fix(tui): show permission prompts from nested subagent chains#36046
fix(tui): show permission prompts from nested subagent chains#36046NaturalSelect wants to merge 1 commit into
Conversation
Nested subagents (subagent spawning a subagent) could trigger a permission request that was never rendered in the UI, deadlocking the whole call chain. The TUI and CLI only tracked direct child sessions, so grandchild session events were silently dropped. - tui: collect the full session subtree (not just direct children) when gathering pending permissions/questions - opencode: bootstrap the CLI subagent footer with all descendants via a level-by-level BFS instead of only direct children - opencode: register grandchild tabs when a known child session spawns a nested task, without skipping the child's own event tracking - app: add regression coverage confirming auto-accept rules already propagate correctly across a three-level session chain Signed-off-by: huangzhibin1 <huangzhibin1@xiaomi.com>
c57f380 to
0be4411
Compare
|
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: Potential Related PRs FoundNote: These are related to the same problem space (nested subagent permission prompts), but most appear to be older attempts or adjacent features. Current PR #36046 seems to be a new fix for this recurring issue.
The current PR (#36046) appears to be addressing a recurring issue with nested subagent permission visibility. #30639 and #24638 are the most directly related, as they target the same root cause. You may want to verify if this is a re-fix of a previously closed issue or if those older PRs had different approaches. |
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
Ported from upstream anomalyco#36046.
Issue for this PR
Closes #13715
Type of change
What does this PR do?
Nested subagents (a subagent spawning its own subagent) could trigger a permission request that was never rendered in the UI, deadlocking the whole call chain. The TUI and CLI only tracked direct child sessions, so grandchild session events were silently dropped and the user had no way to approve the pending permission.
Root cause: both the TUI's permission collection and the CLI's subagent footer only looked one level deep in the session tree (direct children), instead of the full subtree. The permission events themselves were delivered correctly (SSE broadcast is not session-scoped) — the gap was purely in how the UI/CLI decided which sessions to display.
Changes:
packages/tui/src/routes/session/index.tsx: collect the full session subtree (not just direct children) when gathering pending permissions/questions. Added acollectSubtreehelper and asubtree()memo; the existingchildren()memo is left untouched since it's still used for tab navigation, which should stay direct-children-only.packages/opencode/src/cli/cmd/run/stream.transport.ts: bootstrap the CLI subagent footer with all descendants via a level-by-level BFS (collectDescendantSessions) instead of a singlesession.children()call, so a reconnect/cold start picks up grandchild sessions too.packages/opencode/src/cli/cmd/run/subagent-data.ts: inreduceSubagentData, register a grandchild tab when a known child session spawns a nested task, without skipping the child's own event tracking (previously the function returned early only for the root session's own task events).packages/app/src/context/permission-auto-respond.test.ts: added regression coverage for a three-level session chain. The auto-accept lookup already walks the full parent chain (sessionLineage), so no code change was needed there — just locking in the behavior with a test.How did you verify your code works?
bun run typecheckpasses inpackages/opencode,packages/tui, andpackages/app.collectSubtree(single/three-level chains, sibling isolation, cycle guard), a bootstrap test asserting grandchild tabs/permissions surface after a level-by-level BFS, a live-event test asserting a grandchild tab is registered when a known child spawns a nested task, and three grandchild-lineage cases forautoRespondsPermission.stream.transport.test.ts,subagent-data.test.ts,permission-auto-respond.test.ts) plus the new test file — all passing, no regressions in existing cases.Screenshots / recordings
N/A — this fixes visibility of an existing permission prompt for deeper session nesting; no new UI surface.
Checklist