Fix/issue 16982 agent current undefined#17015
Conversation
Fixes anomalyco#16982 Remove unsafe non-null assertion and add proper null checks when accessing agent.current() properties. This prevents the fatal error when no agents are available.
Add tests to verify agent.current() null safety: - Test undefined agent handling - Test all null safety patterns (optional chaining, early returns) - Test filtering logic that could cause empty agent list - Test property access in all contexts (model, submit, display) Prevents regression of issue anomalyco#16982
|
Hey! Your PR title Please update it to start with one of:
Where See CONTRIBUTING.md for details. |
|
The following comment was made by an LLM, it may be inaccurate: Potential Duplicate/Related PRs Found: This issue has been addressed multiple times historically. While these are older PRs, they tackle the same root cause - the unsafe
These PRs suggest this is a recurring issue in the codebase. You may want to check if any of these previous fixes were reverted or if this is a regression, and consider why the same crash pattern keeps appearing. |
|
Closing this pull request because it has had no updates for more than 60 days. If you plan to continue working on it, feel free to reopen or open a new PR. |
Issue for this PR
Closes #16982
Type of change
What does this PR do?
Problem:
The TUI was crashing with
TypeError: undefined is not an object (evaluating 'local.agent.current().name')when the agent list was empty or filtered out (e.g., only subagents/hidden agents available).The root cause was in src/cli/cmd/tui/context/local.tsx where agent.current() used a non-null assertion (!) but could actually return undefined:
Fix:
Files changed:
src/cli/cmd/tui/context/local.tsx: Removed!, added 4 null checkssrc/cli/cmd/tui/component/prompt/index.tsx: Added agent validation before submit, safe property access in memossrc/cli/cmd/tui/component/dialog-agent.tsx: Added optional chainingHow did you verify your code works?
Created comprehensive unit tests (
test/cli/tui/context/local.test.ts):✓undefinedagent doesn't cause crashesTypeScript compilation:
bun typecheckpasses with no errorsManual verification:
.current()!calls remain in the codebaseScreenshots / recordings
N/A - This is a bug fix, no visual UI changes.
Checklist