Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): resumed Claude subagents keep updating their own thread #20061

Mergedjuliusmarmingemerged 2 commits intomain fromrefs/pull/20061/headmerged by juliusmarminge View on GitHub

juliusmarmingecommented

Problem

After a server restart cancels a running Claude subagent, the parent agent can resume it with SendMessage. The resumed subagent then ran fine, but its own thread stayed frozen at "Cancelled": no resume prompt, no new tool calls, no final answer. The parent thread, the composer's "Waiting on N subagents" bar and the Lineage panel all showed it as running, so the two views disagreed.

The run that resumed the subagent never took ownership of the subagent's child thread:

  • A run starting up only inherits the child threads of subagents that are already completed (canRouteRelatedSubagent). A restart-cancelled subagent is cancelled.
  • A resume does not re-announce the child thread (app_thread.created fires only for a brand-new subagent).

So routeProviderEvent dropped every child-thread event. Parent-thread events still got through, because they are matched by run id.

Fix

  • RunExecutionService.routeProviderEvent: a run adopts the child thread of a live, provider-native subagent attributed to it, unless its own root turn has already ended (the same guard as app_thread.created).
  • ClaudeAdapterV2.updateClaudeSubagentNode: emits subagent.updated before the child thread's root node and resume prompt, so those route after adoption. Only the order changes; the same events are emitted.

The existing rule that a dead child's late events stay out of later runs is unchanged, as is its test.

Tests

New replay case in OrchestratorReplayRecovery.integration.test.ts. It reuses the recorded claude_subagent_resume_after_restart session, with the subagent's first run removed so the server restarts while it is still working. Recovery cancels it, then the user's next message resumes it. The test asserts that the child thread's root turn reopens and completes, and that the resume prompt, the reply and the tool calls land there.

  • Fails on main: the child's root turn stays cancelled.
  • Routing fix alone (no adapter reorder): the resume prompt is still missing from the child thread.
  • Both together: passes. The Claude adapter, RunExecutionService, Claude replay, restart background-note and orchestrator replay suites also pass (467 tests). Server typecheck is clean.

Found while investigating a live thread where two resumed subagents were running but their threads showed "Cancelled".

Model: Claude Opus 5.5 in Claude Code (T3 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. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      Approvability

      Verdict: Approved at 3083efc

      Macroscope's review found this PR approvable — This is a focused recovery-path bug fix: resumed provider-native Claude subagents regain ownership of their existing child thread, with event ordering adjusted so subsequent records are retained. The production changes are small and the restart/resume behavior is covered by an integration test.

      No code changes detected at 079da0a. Prior analysis still applies.

      You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    4. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      Review in Change Stack →

      No actionable comments were generated in the recent review. 🎉

      ℹ️ Recent review info
      ⚙️ Run configuration
      • Configuration used: Path: .coderabbit.config.ts
      • Review profile: CHILL
      • Plan: Team
      • Run ID: b1fd9f8f-4aed-45bb-ae0c-4820adb4f78e
      📥 Commits

      Reviewing files that changed from the base of the PR and between 9d26a7986c3fafa4e2cfe50f32ad8cf725081ac4 and 3083efcd81f2304483d12afe22dbe4959ca5490d.

      📒 Files selected for processing: 3
      • apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts
      • apps/server/src/orchestration-v2/RunExecutionService.ts
      • apps/server/src/orchestration-v2/testkit/OrchestratorReplayRecovery.integration.test.ts

      Included review availability: This review used your included allowance. 8 included reviews remain after this review. Your included PR review attempts over the past 7 days set your current allowance at 10 reviews per hour.

      📝 Walkthrough

      The Claude adapter now emits subagent.updated before child-thread root records. Routing adopts eligible child threads. A restart-recovery integration test checks that the child thread resumes and completes.

      Changes: Claude subagent recovery

      Layer / File(s)Summary
      Emit subagent updates before child-thread records
      apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts
      The adapter emits subagent.updated after the parent subagent node update and before child-thread root records. It removes the later duplicate emission.
      Adopt eligible child threads
      apps/server/src/orchestration-v2/RunExecutionService.ts
      Routing state adopts an unowned child thread when the coordinator belongs to the run, the root turn is active, and the subagent is active and provider-native. Workflow-member tracking preserves the adoption.
      Verify Claude restart recovery
      apps/server/src/orchestration-v2/testkit/OrchestratorReplayRecovery.integration.test.ts
      The test checks that the child thread remains running before restart, then resumes and completes after recovery. It verifies the conversation messages and two command executions.

      Priority: ⬇️ Low

      Estimated code review effort: 3 (Moderate) | ~20 minutes

      Change: Bug fix

      Sequence Diagram(s)

      sequenceDiagram
        participant ClaudeAdapterV2
        participant RunExecutionService
        participant RestartedOrchestrator
        ClaudeAdapterV2->>RunExecutionService: Emits subagent.updated
        RunExecutionService->>RunExecutionService: Adopts eligible child thread
        RestartedOrchestrator->>RunExecutionService: Processes next user message
        RunExecutionService->>RestartedOrchestrator: Resumes child thread to completion

      Suggested reviewers: t3dotgg

      Merge Risk: ⚪ Minimal · up to 3083e

      No actionable merge-blocking issue is identified; proceed with normal checks.

      Pre-merge checks: Passed 4
      Check nameStatusExplanation
      Title checkPassedThe title is concise, specific, and accurately describes the primary server fix for resumed Claude subagents.
      Description checkPassedThe description clearly documents the problem, fix, affected components, focused regression test, observed results, test coverage, typecheck status, and agent details. It does not include a separate S…
      Linked Issues checkPassedCheck skipped because no linked issues were found for this pull request.
      Out of Scope Changes checkPassedCheck skipped because no linked issues were found for this pull request.
      ✨ Finishing Touches: 💡 1
      📝 Generate docstrings
      • Commit to this branch
      • Create a new PR
      🧪 Generate unit tests (beta)
      • Commit to this branch
      • Create a new PR
      🛠️ Fix failing CI checks: 💡
      • Commit to this branch
      • Create a new PR
      • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
      Comment `@coderabbitai help` to get the list of available commands.
    5. github-actions[bot](GitHub profile, opens in a new tab)commented

      Thread transfer impact

      ✅ Thread transfer remains within every enforced ceiling.

      ProviderMetricMain baselineThis PRImpactPR ceiling
      CodexTotal thread wire5.0 KiB5.0 KiB+7 B (+0.1%)6.8 KiB✅
      CodexThread snapshot wire3.8 KiB3.8 KiB0 B (0.0%)4.9 KiB✅
      CodexLive turn WebSocket wire1.2 KiB1.2 KiB+7 B (+0.6%)2.0 KiB✅
      CodexLive turn WebSocket decoded20.9 KiB20.9 KiB0 B (0.0%)29.3 KiB✅
      CodexLive turn messages220 (0.0%)8✅
      ClaudeTotal thread wire5.0 KiB5.0 KiB0 B (0.0%)6.8 KiB✅
      ClaudeThread snapshot wire3.8 KiB3.8 KiB0 B (0.0%)4.9 KiB✅
      ClaudeLive turn WebSocket wire1.2 KiB1.2 KiB0 B (0.0%)2.0 KiB✅
      ClaudeLive turn WebSocket decoded21.2 KiB21.2 KiB0 B (0.0%)29.3 KiB✅
      ClaudeLive turn messages220 (0.0%)8✅

      Baseline: 83d6583 · PR result: 079da0a · 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: 108.5 KiB
      • Claude decoded thread snapshot: 108.8 KiB

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

    6. juliusmarminge merged this1550058

    7. juliusmarminge closed this

Sign in to join this conversation.