Skip to content

fix(agent): scan full transcript for spawned agent IDs#660

Open
mvanhorn wants to merge 1 commit intoentireio:mainfrom
mvanhorn:fix/extract-spawned-agent-ids-full-scan
Open

fix(agent): scan full transcript for spawned agent IDs#660
mvanhorn wants to merge 1 commit intoentireio:mainfrom
mvanhorn:fix/extract-spawned-agent-ids-full-scan

Conversation

@mvanhorn
Copy link
Contributor

@mvanhorn mvanhorn commented Mar 8, 2026

Summary

Closes #329

Fixes a bug where subagent token usage and modified files were undercounted when a checkpoint boundary (startLine) was set.

The Problem

CalculateTotalTokenUsage and ExtractAllModifiedFiles both:

  1. Slice the transcript from startLine to get the current turn's data
  2. Extract spawned agent IDs from that sliced data
  3. Read subagent transcript files and sum their usage/files

The issue: subagents spawned before startLine (in a previous turn) may still be actively writing to their transcript files during the current turn. By only scanning from startLine, those agent IDs were never discovered, so their token usage and file modifications were silently dropped.

The Fix

Agent ID extraction now scans the full transcript from the beginning (line 0), while file/token extraction still respects the startLine boundary. This ensures all subagents are discovered regardless of when they were spawned.

Added extractAllSpawnedAgentIDs() helper that parses the full transcript bytes independently of the startLine-sliced data.

Changes

Claude Code agent (claudecode/transcript.go):

  • CalculateTotalTokenUsage - Uses extractAllSpawnedAgentIDs(transcriptData) instead of ExtractSpawnedAgentIDs(parsed)
  • ExtractAllModifiedFiles - Same fix
  • Added extractAllSpawnedAgentIDs() helper

Factory AI Droid agent (factoryaidroid/transcript.go):

  • CalculateTotalTokenUsageFromBytes / ExtractAllModifiedFilesFromBytes - Added extractAllSpawnedAgentIDsFromBytes() helper with same full-scan approach
  • CalculateTotalTokenUsageFromTranscript / ExtractAllModifiedFilesFromTranscript - Re-parses full transcript file at line 0 for agent ID discovery

Testing

  • All existing transcript tests continue to pass
  • The fix is conservative - it only broadens agent ID discovery, not file/token extraction boundaries

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 4.6 noreply@anthropic.com

ExtractAllModifiedFiles and CalculateTotalTokenUsage were extracting
spawned agent IDs from a sliced transcript (startLine onward). After a
checkpoint advances startLine, subagents spawned in earlier turns
became invisible - their file modifications and token usage were missed.

Now agent ID extraction scans from line 0 (full transcript) while file
and token extraction remains bounded to startLine. This affects both
ClaudeCode and FactoryAIDroid implementations.

Closes entireio#329

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

ExtractSpawnedAgentIDs misses subagents spawned before startLine offset

1 participant