fix(analyzer): count parallel subagents/tools by wall-clock union, not sum - #3
Closed
wan-huiyan wants to merge 1 commit into
Closed
fix(analyzer): count parallel subagents/tools by wall-clock union, not sum#3wan-huiyan wants to merge 1 commit into
wan-huiyan wants to merge 1 commit into
Conversation
…t sum
computeEnhancedStats emitted one segment per tool/agent and summed their
durations. When tools or subagents are fanned out in a single assistant turn
(e.g. a 5-agent review panel, or parallel Read/Bash calls), those segments
overlap in wall-clock time, so summing double-counts the concurrency — the
'Subagents' bar reported cumulative agent-seconds, not real elapsed time, and
the active-time percentages could sum to >100% (e.g. 109%).
Aggregate toolExec and subagent by wall-clock interval UNION instead:
- subagent = time with >=1 subagent open
- toolExec = busy-with-a-tool time NOT already counted as subagent
(subagent wins the rare cross-kind overlap, e.g. Agent + Bash in one turn)
claudeThink / planning / humanWait / humanAway are emitted as sequential,
non-overlapping slices and are still summed (unchanged).
On a fan-out-heavy session this dropped reported subagent time from ~53m
(sum of 19 overlapping agents) to ~38m (true elapsed), and the breakdown now
sums to ~100% instead of 109%. The per-call 'Tools' latency table (avg/p50/p95)
is computed separately and is intentionally unchanged.
Tests: 3 cases (parallel agents → union not sum; parallel non-agent tools →
union; sequential agents still add up). 90/90 tests pass.
Author
|
Superseded by #7 — re-created on a dedicated branch ( |
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
computeEnhancedStatsemits one segment per tool/agent and sums them. When tools/agents are fanned out in a single assistant turn (e.g. a panel of review subagents dispatched together), those segments overlap in wall-clock time, so summing double-counts the concurrency — the active-time breakdown can exceed 100% (e.g. reads 109%).Fix
Aggregate the
subagentandtoolExecphases by wall-clock interval union instead of sum (other phases stay summed — they're sequential).subagent= time with ≥1 agent open;toolExec= busy-with-a-tool minus subagent time (subagent wins on cross-kind overlap), so the two never double-count and the percentages stay a true partition.Result
On a fan-out-heavy session this dropped reported subagent time from ~53m (sum of 19 overlapping agents) to ~38m (true elapsed).
Tests
+3 unit tests: parallel agents (union ≠ sum), parallel Bash (union), sequential agents (still add up). All pass;
tsc --noEmitclean.🤖 Generated with Claude Code