fix(daemon): recover subagent spans when SubagentStop lands after a restart#114
Open
rgao-coreweave wants to merge 1 commit into
Open
fix(daemon): recover subagent spans when SubagentStop lands after a restart#114rgao-coreweave wants to merge 1 commit into
rgao-coreweave wants to merge 1 commit into
Conversation
HiveMind Sessions1 session · 1h 7m · $32
View all sessions in HiveMind → Run |
63e0960 to
cec5e43
Compare
cec5e43 to
fcb06c5
Compare
…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>
fcb06c5 to
3d5bdce
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Subagent trackers are in-memory per session. #92 reconstructs the session across a daemon restart but not its subagent trackers, so
handleSubagentStophit "no tracker" and dropped the subagent'sinvoke_agent+chatspans (and their token usage). Locally this dropped ~70% of post-#92 subagent completions (62/89); a per-conversation cross-reference incoreweave1/claude-codeconfirmed the missing spans in prod.Fix
In
handleSubagentStop: resolve the session viagetOrReconstructSession(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'schatspans and token usage.handleSubagentStartis unchanged (SubagentStop is the authoritative recovery point). The recovered type is read from the SubagentStop payload'sagent_type(confirmed present on a live payload).Tests
tests/daemon-subagent-recovery.test.tsdrives the realrouteEventwith an in-memory exporter and asserts the recovered span tree (turn -> invoke_agent -> chatwith tokens), plus that recovery reuses an already-open turn. Full suite 75/75,tscclean.🤖 Generated with Claude Code