Skip to content

fix(tui): show permission prompts from nested subagent chains#36046

Open
NaturalSelect wants to merge 1 commit into
anomalyco:devfrom
NaturalSelect:fix_subagent_perm
Open

fix(tui): show permission prompts from nested subagent chains#36046
NaturalSelect wants to merge 1 commit into
anomalyco:devfrom
NaturalSelect:fix_subagent_perm

Conversation

@NaturalSelect

@NaturalSelect NaturalSelect commented Jul 9, 2026

Copy link
Copy Markdown

Issue for this PR

Closes #13715

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

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 a collectSubtree helper and a subtree() memo; the existing children() 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 single session.children() call, so a reconnect/cold start picks up grandchild sessions too.
  • packages/opencode/src/cli/cmd/run/subagent-data.ts: in reduceSubagentData, 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 typecheck passes in packages/opencode, packages/tui, and packages/app.
  • Added unit tests: 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 for autoRespondsPermission.
  • Ran the targeted suites (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

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

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>
@github-actions github-actions Bot added needs:compliance This means the issue will auto-close after 2 hours. needs:issue labels Jul 9, 2026
@github-actions

github-actions Bot commented Jul 9, 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.

@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

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

Potential Related PRs Found

Note: 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.

  1. fix(acp): surface subagent sessions and route child permissions #33293 - fix(acp): surface subagent sessions and route child permissions

    • Related: Addresses routing permissions from child sessions to UI
  2. fix(session): route nested subagent permission prompts to ancestor UI #30639 - fix(session): route nested subagent permission prompts to ancestor UI

    • Most Similar: Directly tackles the same problem of routing nested permission prompts
  3. fix(tui): propagate permissions from nested subagents and show full subtask tree #24638 - fix(tui): propagate permissions from nested subagents and show full subtask tree

    • Related: Previous attempt to show permissions from nested subagents and display full subtree
  4. feat: nested sub-agent spawning (up to 5 levels) + fixes for #23091 / #13715 #32301 - feat: nested sub-agent spawning (up to 5 levels) + fixes for #23091 / #13715

    • Related: Nested subagent spawning feature and related fixes
  5. fix: render permission and question prompts from nested subagent session #13719 - fix: render permission and question prompts from nested subagent session

    • Related: Similar problem from an earlier version
  6. feat(opencode): add Dynamic workflows (new Claude Code feature) #29789 - feat(opencode): add Dynamic workflows (new Claude Code feature)

    • May be related to subagent functionality

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.

@github-actions github-actions Bot removed needs:issue needs:compliance This means the issue will auto-close after 2 hours. labels Jul 9, 2026
@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Permission asks from nested subagent sessions silently hang

1 participant