Repository navigation
Description
What happened
On the review run for fullsend-ai/react-shopping-cart#39 (fullsend 0.54.0, claude runtime, agents fullsend-ai/agents@v0.54.0), the review agent dispatched four sub-agents in parallel (correctness, security, style, risk). The risk sub-agent finished after the main agent's first final answer.
- The Claude Code stream (
iteration-1/output.jsonlin thefullsend-reviewartifact) has twotype: resultevents:- first:
num_turns: 20,duration_ms: 144300,total_cost_usd: 1.6576 - second:
num_turns: 3,duration_ms: 20361,total_cost_usd: 1.6576
- first:
- The harness log prints both blocks one after the other ("→ Result: success / Turns: 20 / Cost: $1.6576" and then "→ Result: success / Turns: 3 / Cost: $1.6576"), with identical token totals.
- The run's
metrics.jsonrecords"num_turns": 3, alongside"tool_calls": 32and the cumulative cost and tokens.
So the cost and token fields are cumulative, but num_turns (and likely any duration taken from the result event) comes only from the last result segment, the short continuation after the background sub-agent returned.
What could go better
metrics.json underreported turns by about 85% (3 against at least 20 real turns) on a run whose cost and tool-call counts were correct. Retro analysis, cost dashboards and eval judges that read num_turns (for example the max_turns judges discussed in fullsend-ai/agents#968) would see a misleadingly cheap, short run whenever the agent is re-invoked after background sub-agents finish. This is now the normal pattern for the review and retro rosters.
Confidence: high that the two result events exist and that metrics.json matches the second one. Medium on the exact cause: I have not read the metrics-extraction code. The pattern (cumulative cost but last-segment num_turns) strongly suggests the parser overwrites rather than accumulates per-segment fields. If duration_ms is also taken from the last event, durations are undercounted too. Impact is limited to telemetry accuracy; agent behavior is unaffected.
Proposed change
In the claude runtime's result/metrics extraction (the code that parses type: result events from the Claude Code stream-json output and writes metrics.json and the "→ Result" log block):
- When a stream contains several
resultevents, sum the per-segment fields (num_turns,duration_ms,duration_api_msif used). Keep taking cumulative fields (total_cost_usd,usage/modelUsageif they are already cumulative) from the last event. Check first which fields Claude Code reports cumulatively and which per segment, and handle each one explicitly. - Print a single aggregated "→ Result" block, optionally with a
segments: Ncount, instead of one block per result event, so logs don't show conflicting turn counts. - Add a unit test with a fixture stream containing two result events (20 turns then 3 turns, same cost) and assert
num_turns == 23and a single summary block.
Validation criteria
- The unit test with a two-result-event fixture passes, with
num_turnsequal to the sum of the segments. - On the next 5 review runs that use background sub-agents (any repo),
metrics.jsonnum_turnsis at least the number of main-agent assistant turns in the transcript, and the harness log shows one "→ Result" block per agent run. total_cost_usdand token totals inmetrics.jsonare unchanged compared with the last result event (no double counting).
Related issues checked
Searched: Turns mismatch result block printed twice; num_turns; metrics.json turns; multiple result events; second result event background sub-agent
Considered: #6806, fullsend-ai/agents#968, #9149, #7413
fullsend#6806: metrics zeroed when the agent exits with an error. That is a different failure mode (all metrics lost, not a wrong turn count). agents#968: eval max_turns judge variance. It is a consumer of num_turns, so it is related context, not a duplicate. fullsend#9149: the headless CLI stops pending background sub-agents after a 600s idle wait. Same background-sub-agent mechanism but a different symptom (run killed, not metrics miscounted). fullsend#7413: run summary artifact for chained workflows. Unrelated to turn accuracy.
Generated by retro agent from fullsend-ai/react-shopping-cart#39
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsTodo
Activity
AshwinUgale commentedon Nov 23, 2026
I'd like to take this. In 355 Claude runs from the agents nightlies (Claude Code 2.1.306), 11 review runs wrote 2–6
resultevents. In all 11,num_turnsis per segment (one run: 18, 2, 1, 1, 1, 4) andmetrics.jsonhas only the last: 2–11 instead of 23–30.total_cost_usdandmodelUsagenever drop between results, and grow in the two runs whose results weren't all written at the end, so they should stay last-wins.Plan: total
num_turnsinparseClaudeStream, so eachResultEventcarries the turns so far andrecordClaudeMetricsstays last-wins. That also works with #7687, which sets a running count on the same field. I'd leave the single "→ Result" block for a follow-up.fix(fullsend-ai#9228): name the Claude Code version the usage comment…
fix(fullsend-ai#9228): sum Claude turns across result events
Merge pull request fullsend-ai#9814 from AshwinUgale/fix/9228-claude-…