Repository navigation
fix(#9228): sum Claude turns across result events - #9814
Conversation
Signed-off-by: Ashwin Govind Ugale <ugaleashwin@gmail.com>
PR Summary by QodoSum Claude turns across result events
AI Description
Merge Risk
|
Code Review by Qodo🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)
Great, no issues found!Qodo reviewed your code and found no material issues that require reviewTip of the day💡 Did you know, you can keep summaries lean with Findings visible per group, which tucks the rest behind a View link |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
/fs-review |
|
🤖 Finished Review · ✅ Success · Started 7:51 PM UTC · Completed 7:57 PM UTC Commit: Runtime: pi · Model: sonnet → claude-sonnet-5-5 · Effort: high · Cost: $0.90 |
|
Risk Assessment: moderate (2/5) DetailsSmall, focused telemetry bug fix with test coverage matching issue scope, though moderate risk is driven by high regression history and change coupling in touched runtime files. |
|
Looks good to me Previous run<!-- fullsend:review-findings-v2:eyJ2ZXJzaW9uIjoyLCJhY3Rpb24iOiJhcHByb3ZlIiwiZmluZGluZ3MiOltdfQ== --> Looks good to me |
jflowers
left a comment
There was a problem hiding this comment.
Council Review: fix(#9228): sum Claude turns across result events
Council verdict: APPROVE WITH ADVISORIES — 6 reviewer runs (4 APPROVE, 2 APPROVE WITH ADVISORIES); findings: 0 CRITICAL, 0 HIGH, 1 MEDIUM, 1 LOW. Neither advisory blocks merge.
Summary
The totalTurns accumulator in parseClaudeStream fixes the num_turns undercount from #9228 with a minimal change that mirrors the existing totalReasoning pattern. Regression tests cover the summed-turns behavior (a six-result fixture from a live review run) and the no-double-counting invariants for cost and tokens, and the PR replays 355 real Claude streams showing the 11 affected runs rise to true totals with every other metric identical. CI is fully green, including codecov/patch. Local gates did not run (external fork PR, UNTRUSTED_HEAD); CI evidence covers them.
Findings
- MEDIUM (test-coverage)
internal/runtime/event.go:111— the rewrittenResultEventandresultEventdoc comments document no-modelUsagemulti-result token semantics that no test verifies: both multi-result fixtures carrymodelUsage. A table-driven no-modelUsagemulti-result fixture would either verify the claim or expose it as wrong before it hardens into API documentation. - LOW (correctness)
internal/runtime/claude_progress.go:273— onlynum_turnsreceives running-total treatment;duration_ms/duration_api_msand theusagefallback (results withoutmodelUsage) keep last-value overwrite. The PR documents these as deliberate deferrals with no observed data in the 11 replayed streams; worth auditing in the follow-up that handles the single "→ Result" log block.
This review was generated by /uf.review-pr (AI-assisted).
…s hold for The comments said a result's usage covers one segment. That holds for Claude Code 2.1.306, the image pin: in the agents nightly streams usage is per segment and for the top-level loop only. Claude Code 2.1.334 derives usage from modelUsage, a running total. The comments now name both versions and say usage is kept last-wins, never summed. A new test runs three results with no modelUsage, from a live 2.1.306 run, and checks that the turns are summed while the token counts are the last result's, so a change that sums usage fails on either version. Signed-off-by: Ashwin Govind Ugale <ugaleashwin@gmail.com>
|
🤖 Finished Review · ✅ Success · Started 3:32 PM UTC · Completed 3:38 PM UTC Commit: Runtime: pi · Model: sonnet → claude-sonnet-5-5 · Effort: high · Cost: $1.08 |
|
Risk Assessment: moderate (2/5) DetailsFocused telemetry bug fix with test coverage matching issue scope, with moderate risk driven by elevated regression history and change coupling in modified runtime files. |
|
Looks good to me Labels: PR changes the Claude runtime metrics parsing in internal/runtime. |
Superseded by updated review
jflowers
left a comment
There was a problem hiding this comment.
Verdict: APPROVE
Light re-review since e286b31 (3 files, 54 lines); this supersedes my earlier review, which predates 0da871f.
from what I can tell, the fix is minimal: totalTurns mirrors the totalReasoning pattern beside it, and the follow-up commit resolves the earlier coverage gap without disturbing the running-total semantics.
Since e286b31
0da871f version-qualifies the usage semantics in the doc comments: 2.1.306 reports usage per segment for the top-level loop; 2.1.334 derives it from modelUsage, a running total. It also adds TestProgressParserMultiResultWithoutModelUsageKeepsLastUsage, a regression test built from a live 2.1.306 stream.
Prior findings
- MEDIUM, test-coverage (
internal/runtime/event.go:111): resolved. The new test,TestProgressParserMultiResultWithoutModelUsageKeepsLastUsage, now pins the contract the earlier round found untested: three results, num_turns 19/1/5 summed to 25; last usage kept (in=9, out=4661); cost 0.70; PerModelUsage nil. An implementation that summed usage would fail on either Claude Code version; the fixture discriminates. - LOW, correctness (
internal/runtime/claude_progress.go:277): open, deferred on-thread. duration_ms and the usage fallback keep last-wins across multi-result streams. The single "→ Result" log block follow-up should settle it; one summary per stream makes each field's scope explicit.
Issue #9228
Two of three validation criteria covered: the multi-result fixture test sums num_turns, and cost and token totals stay last-wins with no double counting. The single "→ Result" log block on live runs stays deferred as follow-up.
Checks
CI is green at 0da871f: test, codecov/patch, semgrep, DCO, commit-lint, pr-title-lint, web, gateway-doc-configs, fork-pr, and the behaviour suites. Local gates did not run; the head comes from a fork whose author has read permission, so this review relies on CI evidence.
This review was generated by /uf.review-pr (AI-assisted).
waynesun09
left a comment
There was a problem hiding this comment.
Approving 0da871f. Two-agent review of this head found nothing; go test ./internal/runtime/ -run 'Claude|Progress|Event|Usage|Turn|Result', go vet and gofmt pass locally, and CI is green.
Summary
Claude Code writes another
resultevent each time a background task resumes a finished session.num_turnscovers only that segment, but fullsend kept the last one, sometrics.jsonandfullsend.num_turnsundercounted.Related Issue
Part of #9228. The single "→ Result" log block is left for a follow-up.
Changes
parseClaudeStreamtotalsnum_turns, so eachResultEventcarries the turns so far.recordClaudeMetricsstays last-wins, which also works with fix(#6806): capture num_turns from incomplete Claude streams #7687.modelUsageare already running totals and are unchanged.Testing
make lintpasses (stage changes first, then run): not run locally;go vetand gofmt are cleanTests added/updated for new or modified logic
Replayed 355 Claude streams from the agents nightlies (Claude Code 2.1.306): 11 change, all review runs, from 2–11 turns to 23–30. Every other metric is identical.
New test with one of those runs' turn counts; the existing two-result test now checks turns. Both fail without the fix.
53
internal/runtimetests fail under WSL here, all of which fail without the fix too.Not covered
modelUsagefall back tousage, which is per segment on Claude Code 2.1.306, the image pin (2.1.334 derives it frommodelUsage). All 11 runs hadmodelUsage.Checklist
!for breaking changes)