fix(server): a Claude subagent's own subagents no longer wake the root agent #14641
t3code/codex-turn-mapping fromrefs/pull/14641/head·merged by juliusmarminge View on GitHubWhen a background subagent starts a subagent of its own, and that nested subagent finishes while the root agent is idle, V2 opened a continuation run for the root. Claude never wakes the root for that, because it delivers a nested subagent's end to the subagent that started it. So the run showed "Thinking" with nothing behind it until one of the root's own subagents happened to finish.
Seen in a real thread: the root started 8 background audit agents and settled. One of them started 3 Explore agents. The first Explore agent's finish opened turn 4, the 3 Explore agents were the only subagents shown in it, and the root produced nothing for about 45 minutes until an audit agent finished.
Why#
While the root is idle, bufferWakeMessage treats a task_notification as wake evidence when its task is a registered subagent that is still running, or has a buffered task_started. A subagent's finish then offers a continuation immediately. Nothing checked who owns the subagent, even though task_started.spawn_depth says so: 1 for a subagent the root started, N+1 for one started inside a depth-N subagent.
Fix#
In ClaudeAdapterV2.ts:
task_startedfor a subagent withspawn_depthabove 1 is recorded innestedSubagentTaskIds. This happens before routing, so the idle path sees it too.- In
bufferWakeMessage, a nested subagent's notification is still buffered, so the next drain completes its card. It no longer counts asisPendingSubagentNotification, so it neither offers a continuation nor records a wake report. - In the active-turn path, a backgrounded nested subagent is no longer added to
backgroundedSubagentTaskIds, so its finish isn't named in the next wake notice either. - The opaque-task gate (a buffered background-command notification plus assistant or user output) now only accepts root frames (
parent_tool_use_id === null) as proof that Claude began the wake turn. Before, a running background subagent's own output counted as proof too.
Fixture#
claude_nested_background_subagent_wake was recorded live with a new recorder scenario on Claude Code 2.1.282. The root starts a background child and settles. The child starts a background grandchild (spawn_depth: 2) that finishes first, then the child finishes and Claude wakes the root.
It checks:
- two completed runs
- the grandchild is parented to the child
- run 2's wake message is the child's summary (
CHILD_DONE) - the only background notification names the child
On unchanged V2 it fails: the child's end opens the wake: expected 'GRANDCHILD_DONE.' to equal 'CHILD_DONE'.
Follow-up (not in this PR)#
A nested subagent's events emitted while the root is idle are saved by two runs: the launch run and the continuation run both still own the child thread. That records the grandchild's child-thread root turn as running and completed twice. It happens on the base too. In this recording, assertProviderNativeSubagentRootTurns hides it by merging consecutive repeated statuses. An earlier recording, where the grandchild ran entirely inside the idle window, failed that check on both the base and this branch. Ingestion ownership is a separate concern, so I left it out.
Verification#
OrchestratorReplayFixtures.integration,OrchestratorReplayFixtures.contract,ClaudeReplayFixtures.integrationandClaudeAdapterV2.test.ts: 250 passed. The new fixture passed 6 runs in a row.- With the adapter reverted to the base, the new fixture fails as above.
- Each new gate is needed. Reverting just the root-frame check also fails the new fixture: once the grandchild's notification was buffered, the child's next frame (its Bash result) opened the wake.
vp run typecheckinapps/server: exit 0.vp linton the touched files: only the existing unusedlayerwarning at the end ofClaudeAdapterV2.ts, which is on the base too.- Not run: other providers' fixtures, and repo-wide checks.
Recording note: the recorder still needs node --experimental-strip-types, not bun.
Model: Claude Opus 5.5 (Claude Code)
🤖 Generated with Claude Code
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
juliusmarminge added labelsmacroscope-review
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes
Approvability#
Verdict: Approved at
950a57bMacroscope's review found this PR approvable — This is a focused Claude orchestration bug fix that distinguishes nested subagent completions from root wake signals while preserving their lifecycle buffering and parent-child projection. A dedicated replay fixture covers the behavior, with no schema, deployment, product-default, or static-analysis configuration changes.
You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).juliusmarminge merged thisb08e051
juliusmarminge closed this
Sign in to join this conversation.
Thread transfer impact#
✅ Thread transfer remains within every enforced ceiling.
Baseline: unavailable · PR result:
950a57b· Source CI: successScenario and decoded snapshot size
10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.
Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.