#18498 · @Haohao-end · opened Mar 21, 2026 at 8:11 AM UTC · last updated Mar 21, 2026 at 8:33 AM UTC
fix(tui): prevent subagent sessions from overwriting the selected agent
Score breakdown
Impact
Clarity
Urgency
Ease Of Review
Guidelines
Readiness
Size
Trust
Traction
Summary
This PR addresses a critical bug in the TUI where subagent sessions incorrectly overwrite the primary agent, leading to identity swapping and dysfunctional tool calls. The change prevents this by restricting agent switching logic to root sessions. However, thorough local validation was not performed, raising concerns.
Description
Summary
Fixes #18404
Prevent child/subagent sessions from mutating the globally selected primary agent in the TUI.
This change gates both:
- prompt-state restore
- tool-driven plan/build agent switching
to root sessions only (!session.parentID).
As a result, subagent sessions no longer overwrite the selected primary agent after tool activity, while existing root-session behavior remains unchanged.
Testing
- Verified the change is limited to the TUI agent-selection paths in:
packages/opencode/src/cli/cmd/tui/component/prompt/index.tsxpackages/opencode/src/cli/cmd/tui/routes/session/index.tsx
- CI
bun typecheckcurrently fails inpackages/app, not in the files touched by this PR. - I was not able to run the repo’s normal Bun/tsgo validation locally in the original shell used for development because those tools were unavailable there.
Linked Issues
#18404 Subagent identity swapping after first tool call
View issueComments
PR comments
Haohao-end
Updated the PR description to use the template and linked the issue with Fixes #18404.
Also, the current bun typecheck failure appears to be in packages/app:
src/components/dialog-connect-provider.tsxsrc/components/dialog-custom-provider.tsx
Those files are unrelated to this PR’s TUI-only changes.
Changed Files
packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx
+2−2packages/opencode/src/cli/cmd/tui/routes/session/index.tsx
+1−0