[PR #6528] fix(tui): don't show 'Agent not found' toast for subagents #11957

Closed
opened 2026-02-16 18:16:53 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/6528

State: closed
Merged: Yes


Summary

When a command runs with a subagent (e.g., /init with project-initializer), the TUI incorrectly shows an "Agent not found" toast error.

Related issues

https://github.com/sst/opencode/issues/6518

Root Cause

The code added in #6325 (variants toggle) syncs the agent from the last user message to the TUI:

if (msg.agent) local.agent.set(msg.agent)

However, local.agent.list() only includes primary agents (mode !== 'subagent'), so when a command runs with a subagent, the set() call fails and shows the toast.

The backend correctly creates and runs the subagent session - only the TUI display has this bug.

Fix

Check if the agent exists in the primary agents list before attempting to set it:

if (msg.agent && local.agent.list().some((x) => x.name === msg.agent)) local.agent.set(msg.agent)

Testing

  1. Create a custom command that uses a subagent (e.g., /init with agent: "my-subagent")
  2. Run the command
  3. Before: "Agent not found: my-subagent" toast appears
  4. After: No toast, command runs correctly
**Original Pull Request:** https://github.com/anomalyco/opencode/pull/6528 **State:** closed **Merged:** Yes --- ## Summary When a command runs with a subagent (e.g., `/init` with `project-initializer`), the TUI incorrectly shows an "Agent not found" toast error. ## Related issues https://github.com/sst/opencode/issues/6518 ## Root Cause The code added in #6325 (variants toggle) syncs the agent from the last user message to the TUI: ```typescript if (msg.agent) local.agent.set(msg.agent) ``` However, `local.agent.list()` only includes primary agents (`mode !== 'subagent'`), so when a command runs with a subagent, the `set()` call fails and shows the toast. The backend correctly creates and runs the subagent session - only the TUI display has this bug. ## Fix Check if the agent exists in the primary agents list before attempting to set it: ```typescript if (msg.agent && local.agent.list().some((x) => x.name === msg.agent)) local.agent.set(msg.agent) ``` ## Testing 1. Create a custom command that uses a subagent (e.g., `/init` with `agent: "my-subagent"`) 2. Run the command 3. Before: "Agent not found: my-subagent" toast appears 4. After: No toast, command runs correctly
yindo added the pull-request label 2026-02-16 18:16:53 -05:00
yindo closed this issue 2026-02-16 18:16:53 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#11957