Repository navigation
fix(#6806): capture num_turns from incomplete Claude streams - #7687
fullsend-ai-coder[bot] wants to merge 3 commits into
Conversation
Claude Code only reports num_turns on the terminal result NDJSON line. When the process exits abnormally after doing work (exit_code -1), metrics.json recorded num_turns: 0 even though token counts already survive via TokensEvent (#6905). Count message_start events and carry the running turn count on TokensEvent so incomplete streams still populate num_turns. Dollar cost stays zero: the runtime does not report incremental cost, and fullsend does not estimate it from token counts. Note: pre-commit could not fetch remote hook repositories (HTTP 403). Local equivalents were run: gofmt, go vet, trailing-whitespace, end-of-file, lint-docs-links, lychee, lint-broken-symlinks, and scan-secrets. Closes #6806
|
🤖 Finished Review · ✅ Success · Started 7:13 PM UTC · Completed 7:27 PM UTC Commit: Runtime: pi · Model: sonnet → claude-sonnet-5 · Effort: high · Cost: $4.66 |
Site previewPreview: https://f9401bec-site.fullsend-ai.workers.dev Commit: |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
|
Risk Assessment: moderate (2/5) DetailsModerate risk: focused 7-file bug fix with strong test coverage by a bot author, offset by high churn and coupling in modified CLI and runtime files (unchanged from prior review; anchored). Previous runRisk Assessment: moderate (2/5) DetailsModerate risk: focused 7-file bug fix with strong test coverage by a bot author, offset by high churn and coupling in modified CLI and runtime files. Previous run (2)Risk Assessment: moderate (2/5) DetailsModerate risk: focused 7-file bug fix with strong test coverage by a bot author, offset by high churn and coupling in modified CLI and runtime files. |
|
Looks good to me Previous runLooks good to me Previous run (2)ReviewFindingsLow
Next steps:
|
|
🤖 Finished Fix · ✅ Success · Started 7:28 PM UTC · Completed 7:38 PM UTC Commit: Runtime: claude · Model: sonnet → claude-sonnet-5 · Effort: high · Cost: $1.43 |
🔧 Fix agent — iteration 1 (bot-triggered)Added the missing nil guard to applyClaudeMetrics to match applyCodexMetrics's defensive pattern, plus a regression test asserting it does not panic on a nil *RunMetrics. Fixed (1):
Tests: passed CI inspections (13):
Next steps:
|
|
🤖 Finished Review · ✅ Success · Started 7:40 PM UTC · Completed 7:50 PM UTC Commit: Runtime: pi · Model: sonnet → claude-sonnet-5 · Effort: high · Cost: $2.67 |
Superseded by updated review
|
🤖 Finished Review · ✅ Success · Started 6:49 PM UTC · Completed 7:02 PM UTC Commit: Runtime: pi · Model: sonnet → claude-sonnet-5 · Effort: high · Cost: $2.81 |
Superseded by updated review
Summary
Claude Code review (and other) runs that crash or are killed after producing valid output no longer report
num_turns: 0inmetrics.json. The runner now countsmessage_startevents on the stream and carries that running total onTokensEvent, the same incremental channel already used for token counts.Related Issue
This is the remaining gap from #6806 after #6908/#6938 captured token counters on cancelled/killed Claude runs. Those PRs left
NumTurnsandTotalCostUSDsourced only from the terminalResultEvent.Changes
message_startevents inparseClaudeStreamand attach the running turn count toTokensEvent.TokensEvent.NumTurnsintoRunMetricsvia a sharedapplyClaudeMetricshelper (used by bothClaudeRuntime.RunandprogressParser). A laterResultEventstill overwrites with authoritative totals.num_turnshas this fallback indocs/cli/run.md.total_cost_usdon the terminal result line, and fullsend does not estimate cost from token counts (Cost data contract). Incomplete streams still persisttotal_cost_usd: 0.This does not revive the synthetic-
ResultEventapproach from closed PR #6808. Turns ride the existingTokensEventsnapshot, matching the #6908 architecture for tokens.Testing
NumTurns == 3andTotalCostUSD == 0message_startwithoutmessage_deltastill emits a deferredTokensEventwithNumTurnsResultEventstill overwrites the incremental snapshotgo test ./internal/runtime/and targeted./internal/cli/aggregation tests passgo vet ./internal/runtime/ ./internal/cli/applyClaudeMetricsis 100% covered;parseClaudeStreamis 93.2%Checklist
fix(#6806): ...)Closes #6806
Post-script verification
agent/6806-incremental-num-turns)fbf65c8b8c717d74fa6033519658851efaba91f9..HEAD)