fix(server): resumed Claude subagents keep updating their own thread #20061
main fromrefs/pull/20061/head·merged by juliusmarminge View on GitHubProblem#
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 iscancelled. - A resume does not re-announce the child thread (
app_thread.createdfires 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 asapp_thread.created).ClaudeAdapterV2.updateClaudeSubagentNode: emitssubagent.updatedbefore 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
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
juliusmarminge added labelsmacroscope-review
Approvability#
Verdict: Approved at
3083efcMacroscope'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
You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).079da0a. Prior analysis still applies.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.tsapps/server/src/orchestration-v2/RunExecutionService.tsapps/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.updatedbefore 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.tsThe adapter emits subagent.updatedafter 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.tsRouting 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.tsThe 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 completionSuggested reviewers:
t3dotgg
Merge Risk: ⚪ Minimal · up to
3083e-
No actionable merge-blocking issue is identified; proceed with normal checks.
Pre-merge checks:
4-
Check name Status Explanation Title check The title is concise, specific, and accurately describes the primary server fix for resumed Claude subagents. Description check The 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 check Check skipped because no linked issues were found for this pull request. Out of Scope Changes check Check 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
-
Thread transfer impact#
✅ Thread transfer remains within every enforced ceiling.
Provider Metric Main baseline This PR Impact PR ceiling Codex Total thread wire 5.0 KiB 5.0 KiB +7 B (+0.1%) 6.8 KiB ✅ Codex Thread snapshot wire 3.8 KiB 3.8 KiB 0 B (0.0%) 4.9 KiB ✅ Codex Live turn WebSocket wire 1.2 KiB 1.2 KiB +7 B (+0.6%) 2.0 KiB ✅ Codex Live turn WebSocket decoded 20.9 KiB 20.9 KiB 0 B (0.0%) 29.3 KiB ✅ Codex Live turn messages 2 2 0 (0.0%) 8 ✅ Claude Total thread wire 5.0 KiB 5.0 KiB 0 B (0.0%) 6.8 KiB ✅ Claude Thread snapshot wire 3.8 KiB 3.8 KiB 0 B (0.0%) 4.9 KiB ✅ Claude Live turn WebSocket wire 1.2 KiB 1.2 KiB 0 B (0.0%) 2.0 KiB ✅ Claude Live turn WebSocket decoded 21.2 KiB 21.2 KiB 0 B (0.0%) 29.3 KiB ✅ Claude Live turn messages 2 2 0 (0.0%) 8 ✅ Baseline:
83d6583· PR result:079da0a· 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.
- 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.
juliusmarminge merged this1550058
juliusmarminge closed this
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes