Skip to content

Conversation

@zerone0x
Copy link
Contributor

@zerone0x zerone0x commented Jan 12, 2026

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

@github-actions
Copy link
Contributor

The following comment was made by an LLM, it may be inaccurate:

Potential duplicate/related PRs found:

  1. PR fix(opencode): add null checks for agent.current() in prompt #7920 - fix(opencode): add null checks for agent.current() in prompt

    • Related: Also addresses null checks for agent.current() handling
  2. PR fix(tui): guard default agent selection #7796 - fix(tui): guard default agent selection

    • Related: Guards agent selection which is similar to the undefined agent handling
  3. PR fix(tui): handle undefined agent.current() to prevent crash on startup #7748 - fix(tui): handle undefined agent.current() to prevent crash on startup

    • Highly related: Very similar fix for preventing crashes when agent.current() is undefined during startup
  4. PR fix(tui): guard local.agent.current() after oauth redirect (fixes #7727) #7747 - fix(tui): guard local.agent.current() after oauth redirect (fixes #7727)

    • Highly related: Specifically addresses oauth/login scenarios with undefined agent guards
  5. PR fix(tui): handle undefined agent.current() to prevent fatal TypeError #7689 - fix(tui): handle undefined agent.current() to prevent fatal TypeError

    • Highly related: Another fix for the same undefined agent crash issue

These PRs suggest there have been multiple attempts to fix similar undefined agent crashes. You may want to verify that PR #7940 doesn't duplicate work already done in #7748, #7747, or #7689, particularly since those specifically mention handling undefined agent during login/oauth scenarios.

When logging in via Google or during bootstrap, sync.data.agent can be
temporarily empty. This caused crashes when accessing local.agent.current().name.

Changes:
- Use safe initial value for agentStore.current
- Add createEffect to reactively update current agent when agents load
- 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 anomalyco#7932, anomalyco#7931, anomalyco#7918

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@zerone0x zerone0x force-pushed the fix/agent-undefined-crash branch from 6531d4d to 8df6e36 Compare January 12, 2026 07:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TypeError: undefined is not an object (evaluating 'local.agent.current().name') during Google login

1 participant