Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): a Claude subagent's own subagents no longer wake the root agent #14641

Mergedjuliusmarmingemerged 1 commit intot3code/codex-turn-mapping fromrefs/pull/14641/headmerged by juliusmarminge View on GitHub

juliusmarmingecommented

When 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_started for a subagent with spawn_depth above 1 is recorded in nestedSubagentTaskIds. 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 as isPendingSubagentNotification, 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.integration and ClaudeAdapterV2.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 typecheck in apps/server: exit 0.
  • vp lint on the touched files: only the existing unused layer warning at the end of ClaudeAdapterV2.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


Devin Review
    1. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted

    2. juliusmarminge added labelsmacroscope-review

    3. Thread transfer impact

      ✅ Thread transfer remains within every enforced ceiling.

      ℹ️ No successful main baseline artifact is available yet. This run establishes the initial measurement.

      ProviderMetricMain baselineThis PRImpactPR ceiling
      CodexTotal thread wire—4.9 KiB—6.8 KiB✅
      CodexThread snapshot wire—3.7 KiB—4.9 KiB✅
      CodexLive turn WebSocket wire—1.2 KiB—2.0 KiB✅
      CodexLive turn WebSocket decoded—20.4 KiB—29.3 KiB✅
      CodexLive turn messages—2—8✅
      ClaudeTotal thread wire—4.9 KiB—6.8 KiB✅
      ClaudeThread snapshot wire—3.7 KiB—4.9 KiB✅
      ClaudeLive turn WebSocket wire—1.2 KiB—2.0 KiB✅
      ClaudeLive turn WebSocket decoded—20.7 KiB—29.3 KiB✅
      ClaudeLive turn messages—1—8✅

      Baseline: unavailable · PR result: 950a57b · Source CI: success

      Scenario 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.

      • Codex decoded thread snapshot: 106.1 KiB
      • Claude decoded thread snapshot: 106.4 KiB

      Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.

    4. Approvability

      Verdict: Approved at 950a57b

      Macroscope'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).
    5. juliusmarminge merged thisb08e051

    6. juliusmarminge closed this

Sign in to join this conversation.