Skip to content

fix(analyzer): count parallel subagents/tools by wall-clock union, not sum - #3

Closed
wan-huiyan wants to merge 1 commit into
dioptx:mainfrom
wan-huiyan:fix/subagent-wall-clock-union
Closed

fix(analyzer): count parallel subagents/tools by wall-clock union, not sum#3
wan-huiyan wants to merge 1 commit into
dioptx:mainfrom
wan-huiyan:fix/subagent-wall-clock-union

Conversation

@wan-huiyan

Copy link
Copy Markdown

Problem

computeEnhancedStats emits 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 subagent and toolExec phases 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 --noEmit clean.

🤖 Generated with Claude Code

…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.
@wan-huiyan

Copy link
Copy Markdown
Author

Superseded by #7 — re-created on a dedicated branch (upstream/subagent-union) so fork-internal merges/branch-deletes can't disturb it. Same diff.

@wan-huiyan wan-huiyan closed this May 29, 2026
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