fix(tui): handle null agent gracefully in TUI#18868
Conversation
|
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: Based on the search results, I found a highly relevant related PR: Potentially Related PRPR #17015 - "Fix/issue 16982 agent current undefined"
Additionally, these PRs have related themes around null safety in the agent system:
These suggest an ongoing effort to improve null safety in the codebase. Check if PR #17015 is already merged and whether PR #18868 extends its fix to cover TUI-specific scenarios. |
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
- agent.current() now returns Agent | undefined instead of asserting - Add sync effect to keep agentStore.current valid when agent list changes - Add early return in submit when no agent available with helpful toast - Use optional chaining in UI components for color/label display - Improve fallback text from "agent" to "No agent"
650a38a to
53a558d
Compare
|
Automated PR Cleanup Thank you for contributing to opencode. Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions. This PR was closed because it matched the following cleanup criteria:
PRs created within the last month are not affected by this cleanup. If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate. Thanks again for taking the time to contribute. |
Issue for this PR
Closes #16982
Type of change
What does this PR do?
This fixes the TUI crash when
local.agent.current()is read while the visible agent list is empty or when the stored current agent is no longer valid.Compared with #17015, this version also fixes the state management side of the bug:
agentStore.currentis nowstring | undefinedagents()[0]?.nameinstead of assuming an agent always existsagent.current()returnsundefinedonly when the visible agent list is emptycreateEffectkeepsagentStore.currentvalid when the available agent list changesmove()now handles an empty agent list safelyIt also updates the TUI call sites to handle the missing-agent case gracefully:
.namealways existsNo agentHow did you verify your code works?
bun typecheckinpackages/opencodeagent.current()to nullable behavioragent.current()call sites to ensure they now handle the missing-agent case safelyScreenshots / recordings
Not included. This is a null-safety fix for a crash path rather than a visual UI change.
Checklist