Skip to content

fix(daemon): recover subagent spans when SubagentStop lands after a restart#114

Open
rgao-coreweave wants to merge 1 commit into
mainfrom
fix/recover-subagent-spans-across-restart
Open

fix(daemon): recover subagent spans when SubagentStop lands after a restart#114
rgao-coreweave wants to merge 1 commit into
mainfrom
fix/recover-subagent-spans-across-restart

Conversation

@rgao-coreweave

@rgao-coreweave rgao-coreweave commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Problem

Subagent trackers are in-memory per session. #92 reconstructs the session across a daemon restart but not its subagent trackers, so handleSubagentStop hit "no tracker" and dropped the subagent's invoke_agent + chat spans (and their token usage). Locally this dropped ~70% of post-#92 subagent completions (62/89); a per-conversation cross-reference in coreweave1/claude-code confirmed the missing spans in prod.

Fix

In handleSubagentStop: resolve the session via getOrReconstructSession (like #92), and on no tracker rebuild the subagent from its transcript (recoverSubagentTracker) under the current turn, reconstructing the turn if the restart lost it too. The existing emit path then attaches the subagent's chat spans and token usage. handleSubagentStart is unchanged (SubagentStop is the authoritative recovery point). The recovered type is read from the SubagentStop payload's agent_type (confirmed present on a live payload).

Tests

tests/daemon-subagent-recovery.test.ts drives the real routeEvent with an in-memory exporter and asserts the recovered span tree (turn -> invoke_agent -> chat with tokens), plus that recovery reuses an already-open turn. Full suite 75/75, tsc clean.

🤖 Generated with Claude Code

@w-b-hivemind

w-b-hivemind Bot commented Jul 13, 2026

Copy link
Copy Markdown

HiveMind Sessions

1 session · 1h 7m · $32

Session Agent Duration Tokens Cost Lines
Fix Claude Code Weave Integration Trace Drops
45754e21-c7c1-4ad1-917b-0d669bb69497
claude 1h 7m 298.8K $32 +465 -19
Total 1h 7m 298.8K $32 +465 -19

View all sessions in HiveMind →

Run claude --resume 45754e21-c7c1-4ad1-917b-0d669bb69497 to pickup where you left off.

@rgao-coreweave rgao-coreweave force-pushed the fix/recover-subagent-spans-across-restart branch from 63e0960 to cec5e43 Compare July 13, 2026 18:52
@rgao-coreweave rgao-coreweave marked this pull request as ready for review July 13, 2026 19:37
@rgao-coreweave rgao-coreweave requested a review from a team as a code owner July 13, 2026 19:37
@rgao-coreweave rgao-coreweave requested a review from a team July 13, 2026 23:04
@rgao-coreweave rgao-coreweave force-pushed the fix/recover-subagent-spans-across-restart branch from cec5e43 to fcb06c5 Compare July 14, 2026 00:00
…estart

Subagent trackers live only in per-session in-memory state. #92
reconstructs the session across a daemon restart but not its subagent
trackers, and handleSubagentStop early-returned on a missing session or
tracker. So a subagent whose PreToolUse/SubagentStart ran on a daemon
that then restarted lost its invoke_agent + chat spans (and the token
usage they carry) at SubagentStop. Locally this dropped ~70% of post-#92
subagent completions.

Reconstruct the session (via getOrReconstructSession) and, when no
tracker exists, rebuild the subagent from its transcript under a
reconstructed turn so its chat spans and token usage are emitted instead
of dropped. handleSubagentStart is left unchanged: SubagentStop is the
authoritative recovery point since it has the completed transcript.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@rgao-coreweave rgao-coreweave force-pushed the fix/recover-subagent-spans-across-restart branch from fcb06c5 to 3d5bdce Compare July 14, 2026 00:24
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.

1 participant