fix(tui): handle undefined agent.current() to prevent crash on startup#7748
fix(tui): handle undefined agent.current() to prevent crash on startup#7748junhoyeo wants to merge 1 commit intoanomalyco:devfrom
Conversation
When sync.data.agent is empty (e.g., during oauth flow or initial load), local.agent.current() would crash accessing undefined.name. Changes: - Make agent store initialization safe with optional chaining - Rewrite current() to handle empty agents list (return undefined) - Update set()/move() methods to handle undefined/empty list - Guard all call sites in model functions and createEffect - Add null checks in prompt component and dialog-agent This matches the safer implementation already present in packages/app.
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
|
The following comment was made by an LLM, it may be inaccurate: Potential Duplicate PRs FoundBased on the search results, there are two highly related PRs that appear to address the same issue:
Recommendation: Check if PR #7747 or #7689 are already merged or open. If either is already in progress or merged, PR #7748 may be redundant and should be consolidated or closed. |
00637c0 to
71e0ba2
Compare
f1ae801 to
08fa7f7
Compare
Summary
Fixes crash when
local.agent.current()is called before agents are loaded (e.g., after OAuth flow or during initial startup).Error:
Root Cause
In
packages/opencode/src/cli/cmd/tui/context/local.tsx, the agent store initialization assumes agents are always available:This happens because:
sync.data.agentstarts as an empty arrayLocalProviderinitializes beforebootstrap()fetches agentsagents()[0].namecrashes when array is emptyChanges
packages/opencode/src/cli/cmd/tui/context/local.tsx:currentoptional and use?.on initializationcurrent()to safely returnundefinedwhen no agents available (matches web app implementation)set()andmove()methods to handle empty agent listcurrentModelmemo and model functions against undefined agentcreateEffectfor agent model syncpackages/opencode/src/cli/cmd/tui/component/prompt/index.tsx:submit()when no agent selectedhighlight()andspinnerDef()memos with fallback colorspackages/opencode/src/cli/cmd/tui/component/dialog-agent.tsx:Testing
packages/app/src/context/local.tsx