GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(tui): handle empty agent list without crashing by Romanok2805 · Pull Request #16063 · anomalyco/opencode

Conversation

@Romanok2805

@Romanok2805 Romanok2805 commented Mar 4, 2026

Copy link
Copy Markdown

Summary

  • Fixes a TypeError: undefined is not an object (evaluating 'agents()[0].name') crash in the TUI when the filtered agent list is empty at initialization time
  • This occurs when plugins reconfigure agent modes (e.g. demoting all built-in agents to subagent) so that no primary/visible agents remain when LocalProvider initializes

Changes

All changes are in packages/opencode/src/cli/cmd/tui/context/local.tsx:

  1. Safe initial value: agents()[0].name → agents()[0]?.name ?? "" to avoid crash on empty list
  2. Reactive sync: Added createEffect to update current when the agent list changes and the current selection becomes invalid
  3. Safe current() accessor: Removed non-null assertion (!), falls back to agents()[0] (which may be undefined)
  4. Guard move(): Early return when agent list is empty
  5. Guard currentModel memo: Return undefined when agent.current() is undefined
  6. Guard cycle() / cycleFavorite(): Extract agent.current() into a variable, early return if undefined
  7. Guard agent-change effect: Early return when agent value is undefined

Reproduction

  1. Install a plugin that reconfigures agent modes (e.g. oh-my-opencode with Claude Code user agents in ~/.claude/agents/ that shadow built-in agent names)
  2. Start the TUI — crashes immediately at local.tsx:43

Test plan

  • Start TUI with no plugins — agents render normally, no regression
  • Start TUI with a plugin that demotes all agents to subagent — TUI starts without crash, shows remaining visible agents
  • Switch agents via keybind — cycling works without errors
  • Change model while agent list is dynamic — no crash on undefined agent

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@Romanok2805 @claude
fix(tui): handle empty agent list without crashing
20eebd2
The TUI crashes with `TypeError: undefined is not an object (evaluating
'agents()[0].name')` when the filtered agent list is empty. This happens
when plugins reconfigure agent modes so no primary/visible agents remain
at the time the LocalProvider initializes.

- Use optional chaining on `agents()[0]?.name` for safe initial value
- Add reactive effect to sync current agent when the list changes
- Remove non-null assertion on `current()`, fall back to first agent
- Guard `move()` against empty agent lists
- Guard `currentModel` memo against undefined agent
- Guard `cycle()` and `cycleFavorite()` against undefined agent
- Guard agent-change effect against undefined value

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@github-actions github-actions Bot added the needs:compliance This means the issue will auto-close after 2 hours. label Mar 4, 2026
@github-actions

github-actions Bot commented Mar 4, 2026

Copy link
Copy Markdown
Contributor

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • PR description is missing required template sections. Please use the PR template.

Please edit this PR description to address the above within 2 hours, or it will be automatically closed.

If you believe this was flagged incorrectly, please let a maintainer know.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot added the needs:issue label Mar 4, 2026
@github-actions

github-actions Bot commented Mar 4, 2026

Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions

github-actions Bot commented Mar 4, 2026

Copy link
Copy Markdown
Contributor

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

Based on the search results, I found several related PRs that address similar issues with handling undefined/empty agent states in the TUI. These are potentially duplicates or related fixes:

Potential Related/Duplicate PRs:

  1. fix(tui): handle undefined agent.current() to prevent crash on startup #7748 - fix(tui): handle undefined agent.current() to prevent crash on startup
  2. fix(tui): handle undefined agent.current() to prevent fatal TypeError #7689 - fix(tui): handle undefined agent.current() to prevent fatal TypeError
  3. fix(tui): guard default agent selection #7796 - fix(tui): guard default agent selection
  4. fix(tui): add null check for local.agent.current() #8745 - fix(tui): add null check for local.agent.current()
  5. fix(tui): add null safety for local.agent.current().name (#8858) #8882 - fix(tui): add null safety for local.agent.current().name
  6. fix: add fallback for current agent in TUI to prevent crashes #9877 - fix: add fallback for current agent in TUI to prevent crashes
  7. fix(tui): handle undefined agent during login/bootstrap transition #7940 - fix(tui): handle undefined agent during login/bootstrap transition

Why they're related:
These PRs all address similar TypeError crashes in the TUI related to accessing properties on undefined agent objects or empty agent lists. They involve guard checks, null/undefined handling, and fallbacks in the agent initialization and selection logic - very similar to the changes in PR #16063.

Recommendation: Check if this issue has already been fixed in one of these earlier PRs (particularly #7748, #7689, or #8882 which seem most directly relevant to this specific problem).

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Romanok2805 Romanok2805 closed this Mar 4, 2026
@Romanok2805
Romanok2805 deleted the fix/tui-agent-null-crash branch March 4, 2026 23:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

needs:compliance This means the issue will auto-close after 2 hours. needs:issue

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@Romanok2805
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.