fix: discover subagent files by directory scan instead of JSONL references#245
Open
neoeny152 wants to merge 1 commit intosirmalloc:mainfrom
Open
fix: discover subagent files by directory scan instead of JSONL references#245neoeny152 wants to merge 1 commit intosirmalloc:mainfrom
neoeny152 wants to merge 1 commit intosirmalloc:mainfrom
Conversation
… of relying on main JSONL references
The subagent discovery mechanism in getSubagentTranscriptPaths() relied on
getReferencedSubagentIds() finding agentId fields in the main session JSONL.
However, the main JSONL contains zero entries with agentId — all agent IDs
exist only in the separate subagent files under {sessionDir}/subagents/.
This caused getReferencedSubagentIds() to return an empty set, making
getSubagentTranscriptPaths() short-circuit and return [], so no subagent
files were ever read.
This affected both speed metrics (tok/s showing only main-chain throughput)
and token counts (missing all subagent tokens). In sessions with heavy agent
usage (e.g. 16+ parallel agents), 90%+ of tokens were invisible.
Changes:
- Remove referencedAgentIds parameter from getSubagentTranscriptPaths() and
scan subagents/ directories for all agent-*.jsonl files directly
- Add subagent token aggregation to getTokenMetrics() so total token counts
include agent usage
- Simplify getSpeedMetricsCollection() to use directory-based discovery
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Owner
|
@neoeny152 I'm not sure this is necessary. After reviewing my session transcript JSONL files, I've found a 1:1 match of unique agentIds in the JSONL files and the subagent transcripts. Can you expand on your assertion that the main JSONL has no agentId fields in it, and provide a recent example with the latest Claude Code version? |
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.
Summary
getSubagentTranscriptPaths()relies ongetReferencedSubagentIds()findingagentIdfields in the main session JSONL. However, the main JSONL contains zero entries withagentId— all agent IDs exist only in the separate subagent files under{sessionDir}/subagents/. This causesgetReferencedSubagentIds()to return an empty set, makinggetSubagentTranscriptPaths()short-circuit and return[], so no subagent files are ever read.subagents/directories for allagent-*.jsonlfiles directly instead of requiring pre-discovered IDs. Also add subagent token aggregation togetTokenMetrics().Changes
getSubagentTranscriptPaths()— RemovereferencedAgentIdsparameter and the early-return gate. Scan candidate directories for allagent-*.jsonlfiles directly. This is safe because thesubagents/directory only contains files for the current session.getTokenMetrics()— After reading the main JSONL, also discover and read all subagent files, summing their token usage (input, output, cached).getSpeedMetricsCollection()— Remove the brokengetReferencedSubagentIds(mainLines)call and use the simplifiedgetSubagentTranscriptPaths(transcriptPath)directly.Verified
Tested against real Claude Code sessions on Windows. Before patch: main JSONL had 0 agent IDs, 0 subagent files discovered. After patch: all subagent files found, ~48% more tokens counted in a 2-agent session. For 16+ agent sessions the difference is ~90%+.
Test plan
isSidechain: falseonly, subagent files have the agent data)🤖 Generated with Claude Code