[PR #7940] fix(tui): handle undefined agent during login/bootstrap transition #12569

Open
opened 2026-02-16 18:17:28 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/7940

State: open
Merged: No


Summary

  • Fix crash when local.agent.current() returns undefined during Google login or bootstrap
  • Add reactive agent state management using createEffect to handle async data loading
  • Add proper null checks throughout the agent/model handling code

Root Cause

When logging in via Google or during bootstrap(), sync.data.agent is temporarily empty. The code assumed agents would always be available, causing crashes when accessing local.agent.current().name.

Changes

  • Use safe initial value agents()[0]?.name ?? "" instead of direct access
  • Add createEffect to reactively update current agent when agents list loads
  • Remove unsafe ! non-null assertion in current() method
  • Add null checks in move(), cycle(), cycleFavorite(), set() methods
  • Use optional chaining at all call sites

Fixes #7932, #7931, #7918

**Original Pull Request:** https://github.com/anomalyco/opencode/pull/7940 **State:** open **Merged:** No --- ## Summary - Fix crash when `local.agent.current()` returns undefined during Google login or bootstrap - Add reactive agent state management using `createEffect` to handle async data loading - Add proper null checks throughout the agent/model handling code ## Root Cause When logging in via Google or during `bootstrap()`, `sync.data.agent` is temporarily empty. The code assumed agents would always be available, causing crashes when accessing `local.agent.current().name`. ## Changes - Use safe initial value `agents()[0]?.name ?? ""` instead of direct access - Add `createEffect` to reactively update current agent when agents list loads - Remove unsafe `!` non-null assertion in `current()` method - Add null checks in `move()`, `cycle()`, `cycleFavorite()`, `set()` methods - Use optional chaining at all call sites Fixes #7932, #7931, #7918
yindo added the pull-request label 2026-02-16 18:17:28 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#12569