From 13c77fafb72dee279b2e4175af970cec358b8b60 Mon Sep 17 00:00:00 2001 From: fullsend-code <278716306+fullsend-ai-coder[bot]@users.noreply.github.com> Date: Thu, 24 Sep 2026 19:08:07 +0000 Subject: [PATCH 1/2] fix(#6806): capture num_turns from incomplete Claude streams 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 --- docs/cli/run.md | 2 +- internal/cli/run.go | 4 +- internal/cli/run_test.go | 16 ++- internal/runtime/claude.go | 26 +---- internal/runtime/claude_progress.go | 67 +++++++---- internal/runtime/claude_progress_test.go | 141 ++++++++++++++++++++++- internal/runtime/event.go | 5 + 7 files changed, 202 insertions(+), 59 deletions(-) diff --git a/docs/cli/run.md b/docs/cli/run.md index 1ace3829c0..cf4bd7ffe1 100644 --- a/docs/cli/run.md +++ b/docs/cli/run.md @@ -98,7 +98,7 @@ depend on the process cwd. | `override_source` | Where `requested_model` came from (`--model flag`, `FULLSEND_MODEL`, `FULLSEND_PI_MODEL`, `FULLSEND_CODEX_MODEL`, ` agents.`, `harness`, `default`), suffixed `, remapped by models.aliases` when a per-repo alias override applied to it | | `runtime_source` | Where `requested_runtime` came from (`--runtime flag`, `FULLSEND_RUNTIME`, the config file path — suffixed ` agents.` when the agent's entry decided — or `default (config not found)`) | | `total_cost_usd` | Total inference cost in USD, as reported by the runtime (raw floating-point aggregate across all iterations; no fullsend-side pricing-table fallback). See [Cost data contract](../guides/infrastructure/distributed-tracing.md#cost-data-contract) | -| `num_turns` | Number of conversation turns | +| `num_turns` | Number of conversation turns. Claude Code takes this from the terminal result event when the process completes normally; if the stream ends without that event (killed or crashed process), the runner counts `message_start` events instead. Dollar cost has no equivalent fallback — see [Cost data contract](../guides/infrastructure/distributed-tracing.md#cost-data-contract) | | `iterations` | Number of agent iterations run; an iteration killed at the budget is not retried (see [Budget and deadline](#budget-and-deadline)) | | `per_model_usage` | Per-model-spec breakdown, present only when a runtime reports one (today: `pi` with the `Agent` tool enabled). See below | diff --git a/internal/cli/run.go b/internal/cli/run.go index de5ac7c404..982ebd4c0c 100644 --- a/internal/cli/run.go +++ b/internal/cli/run.go @@ -3930,8 +3930,8 @@ func transcriptErrorMessage(te agentruntime.TranscriptError) string { // NOTE: TotalCostUSD will be zero in the persisted metrics because dollar // cost is only available from the terminal ResultEvent, which a cancelled // run never emits. Token counts (input, output, cache_read, cache_creation) -// are captured via the deferred TokensEvent and will be non-zero. See #6936 -// for background. +// and NumTurns are captured via the deferred TokensEvent and will be +// non-zero when the stream produced work. See #6936 and #6806. // // cancelled is false when ctx is still live, in which case the caller's // normal control flow continues unchanged; the other return values are diff --git a/internal/cli/run_test.go b/internal/cli/run_test.go index a89c196abe..fb710caa0a 100644 --- a/internal/cli/run_test.go +++ b/internal/cli/run_test.go @@ -5152,12 +5152,14 @@ func TestAggregateRunMetrics_PartialCancelledRun(t *testing.T) { var agg aggregateMetrics // Simulate a cancelled run: metrics populated via TokensEvent (no - // ResultEvent, so NumTurns/TotalCostUSD stay zero). + // ResultEvent, so TotalCostUSD stays zero). NumTurns is counted from + // message_start and carried on TokensEvent (#6806). m := agentruntime.RunMetrics{ InputTokens: 599, OutputTokens: 119, CacheCreationInputTokens: 148_943, CacheReadInputTokens: 583_298, + NumTurns: 3, Model: "claude-opus-4-6", } m.ToolCalls.Store(10) @@ -5182,11 +5184,11 @@ func TestAggregateRunMetrics_PartialCancelledRun(t *testing.T) { if agg.Model != "claude-opus-4-6" { t.Errorf("model = %q, want claude-opus-4-6", agg.Model) } - if agg.NumTurns != 0 { - t.Errorf("num_turns = %d, want 0 (cancelled run has no ResultEvent)", agg.NumTurns) + if agg.NumTurns != 3 { + t.Errorf("num_turns = %d, want 3 (TokensEvent carries turns when ResultEvent is missing)", agg.NumTurns) } if agg.TotalCostUSD != 0 { - t.Errorf("total_cost_usd = %f, want 0 (cancelled run has no ResultEvent)", agg.TotalCostUSD) + t.Errorf("total_cost_usd = %f, want 0 (dollar cost is only on ResultEvent)", agg.TotalCostUSD) } } @@ -5213,11 +5215,13 @@ func TestAggregateRunMetrics_MultiIterationCancel(t *testing.T) { aggregateRunMetrics(&agg, &m1, 1) // Iteration 2: cancelled — TokensEvent only (no ResultEvent). + // NumTurns is still counted from message_start (#6806); cost is not. m2 := agentruntime.RunMetrics{ InputTokens: 599, OutputTokens: 119, CacheCreationInputTokens: 148_943, CacheReadInputTokens: 583_298, + NumTurns: 2, Model: "claude-opus-4-6", } m2.ToolCalls.Store(3) @@ -5241,8 +5245,8 @@ func TestAggregateRunMetrics_MultiIterationCancel(t *testing.T) { if agg.TotalCostUSD != 0.42 { t.Errorf("total_cost_usd = %f, want 0.42", agg.TotalCostUSD) } - if agg.NumTurns != 5 { - t.Errorf("num_turns = %d, want 5 (cancelled iteration contributes zero turns)", agg.NumTurns) + if agg.NumTurns != 7 { + t.Errorf("num_turns = %d, want 7 (cancelled iteration still contributes TokensEvent turns)", agg.NumTurns) } if agg.ToolCalls != 11 { t.Errorf("tool_calls = %d, want 11", agg.ToolCalls) diff --git a/internal/runtime/claude.go b/internal/runtime/claude.go index 8ebeeda824..b3ad2821f8 100644 --- a/internal/runtime/claude.go +++ b/internal/runtime/claude.go @@ -152,31 +152,7 @@ func (ClaudeRuntime) Run(ctx context.Context, params RunParams, printer *ui.Prin // Always wrap handler to capture metrics regardless of custom/default path. innerHandler := handler handler = func(evt AgentEvent) { - switch e := evt.(type) { - case InitEvent: - if metrics.Model == "" { - metrics.Model = e.Model - } - case TokensEvent: - // Capture cumulative token usage from the stream so cancelled - // runs (no ResultEvent) retain non-zero telemetry (#6905). - metrics.InputTokens = e.InputTokens - metrics.OutputTokens = e.OutputTokens - metrics.CacheReadInputTokens = e.CacheRead - metrics.CacheCreationInputTokens = e.CacheWrite - case ResultEvent: - // Authoritative totals from the terminal result event overwrite - // the incremental snapshot. - metrics.NumTurns = e.NumTurns - metrics.TotalCostUSD = e.TotalCostUSD - metrics.InputTokens = e.InputTokens - metrics.OutputTokens = e.OutputTokens - metrics.ReasoningTokens = e.ReasoningTokens - metrics.CacheCreationInputTokens = e.CacheCreationInputTokens - metrics.CacheReadInputTokens = e.CacheReadInputTokens - case ToolUseEvent: - metrics.ToolCalls.Add(1) - } + applyClaudeMetrics(metrics, evt) innerHandler(evt) } diff --git a/internal/runtime/claude_progress.go b/internal/runtime/claude_progress.go index 00f851a55e..f37cd196dc 100644 --- a/internal/runtime/claude_progress.go +++ b/internal/runtime/claude_progress.go @@ -161,12 +161,15 @@ func parseClaudeStream(r io.Reader, onEvent func(AgentEvent)) error { cumulativeCacheWrite int seenResult bool totalReasoning int // accumulated thinking tokens across all messages (for ResultEvent) + numTurns int // message_start count; carried on TokensEvent (#6806) + lastEmittedTurns int ) // Emit a final cumulative TokensEvent when the stream ends without // a ResultEvent (cancelled/killed run) and the cumulative total - // exceeds the last emitted snapshot. The deferred call covers - // every exit path: EOF, read error, and normal return. + // exceeds the last emitted snapshot, or turns arrived after the + // last snapshot. The deferred call covers every exit path: EOF, + // read error, and normal return. defer func() { if seenResult { return @@ -176,12 +179,13 @@ func parseClaudeStream(r io.Reader, onEvent func(AgentEvent)) error { finalCacheRead := cumulativeCacheRead + totalCacheRead finalCacheWrite := cumulativeCacheWrite + totalCacheWrite total := finalInput + finalOutput + finalCacheRead + finalCacheWrite - if total > lastEmittedTotal { + if total > lastEmittedTotal || numTurns > lastEmittedTurns { onEvent(TokensEvent{ InputTokens: finalInput, OutputTokens: finalOutput, CacheRead: finalCacheRead, CacheWrite: finalCacheWrite, + NumTurns: numTurns, }) } }() @@ -313,6 +317,7 @@ func parseClaudeStream(r io.Reader, onEvent func(AgentEvent)) error { }) case "message_start": + numTurns++ var msg struct { Message struct { Usage struct { @@ -354,12 +359,14 @@ func parseClaudeStream(r io.Reader, onEvent func(AgentEvent)) error { msgReasoning + cumulativeCacheRead + totalCacheRead + cumulativeCacheWrite + totalCacheWrite if total-lastEmittedTotal >= tokenThreshold { lastEmittedTotal = total + lastEmittedTurns = numTurns onEvent(TokensEvent{ InputTokens: cumulativeInput + totalInput, OutputTokens: cumulativeOutput + totalOutput, ReasoningTokens: msgReasoning, CacheRead: cumulativeCacheRead + totalCacheRead, CacheWrite: cumulativeCacheWrite + totalCacheWrite, + NumTurns: numTurns, }) } } @@ -527,33 +534,45 @@ func toolResultText(raw json.RawMessage) (text string, partial bool) { return strings.Join(texts, "\n"), partial } +// applyClaudeMetrics folds a stream event into RunMetrics. TokensEvent is +// the incremental snapshot used when the process dies before the terminal +// result line (#6905, #6806); ResultEvent overwrites with authoritative +// totals. Dollar cost is ResultEvent-only: Claude Code does not report +// incremental cost, and fullsend does not estimate it from token counts. +func applyClaudeMetrics(metrics *RunMetrics, evt AgentEvent) { + switch e := evt.(type) { + case InitEvent: + if metrics.Model == "" { + metrics.Model = e.Model + } + case TokensEvent: + metrics.InputTokens = e.InputTokens + metrics.OutputTokens = e.OutputTokens + metrics.CacheReadInputTokens = e.CacheRead + metrics.CacheCreationInputTokens = e.CacheWrite + if e.NumTurns > 0 { + metrics.NumTurns = e.NumTurns + } + case ResultEvent: + metrics.NumTurns = e.NumTurns + metrics.TotalCostUSD = e.TotalCostUSD + metrics.InputTokens = e.InputTokens + metrics.OutputTokens = e.OutputTokens + metrics.ReasoningTokens = e.ReasoningTokens + metrics.CacheCreationInputTokens = e.CacheCreationInputTokens + metrics.CacheReadInputTokens = e.CacheReadInputTokens + case ToolUseEvent: + metrics.ToolCalls.Add(1) + } +} + // progressParser reads NDJSON from Claude Code's stream-json output and emits // progress updates via the printer. It is a thin wrapper around parseClaudeStream // that creates an EventRenderer and populates RunMetrics. func progressParser(r io.Reader, printer *ui.Printer, metrics *RunMetrics) error { renderer := NewEventRenderer(printer) return parseClaudeStream(r, func(evt AgentEvent) { - switch e := evt.(type) { - case InitEvent: - if metrics.Model == "" { - metrics.Model = e.Model - } - case TokensEvent: - metrics.InputTokens = e.InputTokens - metrics.OutputTokens = e.OutputTokens - metrics.CacheReadInputTokens = e.CacheRead - metrics.CacheCreationInputTokens = e.CacheWrite - case ResultEvent: - metrics.NumTurns = e.NumTurns - metrics.TotalCostUSD = e.TotalCostUSD - metrics.InputTokens = e.InputTokens - metrics.OutputTokens = e.OutputTokens - metrics.ReasoningTokens = e.ReasoningTokens - metrics.CacheCreationInputTokens = e.CacheCreationInputTokens - metrics.CacheReadInputTokens = e.CacheReadInputTokens - case ToolUseEvent: - metrics.ToolCalls.Add(1) - } + applyClaudeMetrics(metrics, evt) renderer.Handle(evt) }) } diff --git a/internal/runtime/claude_progress_test.go b/internal/runtime/claude_progress_test.go index 5f0d05d90a..f0c7e7b1d0 100644 --- a/internal/runtime/claude_progress_test.go +++ b/internal/runtime/claude_progress_test.go @@ -611,7 +611,53 @@ func TestProgressParserCapturesModelFromSystemEvent(t *testing.T) { } } +func TestApplyClaudeMetricsTokensEventSetsTurns(t *testing.T) { + metrics := &RunMetrics{} + applyClaudeMetrics(metrics, TokensEvent{ + InputTokens: 4000, + OutputTokens: 800, + CacheRead: 500, + CacheWrite: 200, + NumTurns: 3, + }) + if metrics.NumTurns != 3 { + t.Errorf("NumTurns = %d, want 3", metrics.NumTurns) + } + if metrics.InputTokens != 4000 || metrics.OutputTokens != 800 { + t.Errorf("token snapshot = in %d out %d, want 4000/800", metrics.InputTokens, metrics.OutputTokens) + } + if metrics.TotalCostUSD != 0 { + t.Errorf("TotalCostUSD = %f, want 0 (TokensEvent carries no cost)", metrics.TotalCostUSD) + } + + applyClaudeMetrics(metrics, TokensEvent{InputTokens: 5000, NumTurns: 0}) + if metrics.NumTurns != 3 { + t.Errorf("NumTurns = %d, want 3 (zero-turn TokensEvent must not clobber)", metrics.NumTurns) + } + if metrics.InputTokens != 5000 { + t.Errorf("InputTokens = %d, want 5000", metrics.InputTokens) + } + + applyClaudeMetrics(metrics, ResultEvent{ + NumTurns: 8, + TotalCostUSD: 0.42, + InputTokens: 12000, + OutputTokens: 3400, + }) + if metrics.NumTurns != 8 { + t.Errorf("NumTurns = %d, want 8 from ResultEvent", metrics.NumTurns) + } + if metrics.TotalCostUSD != 0.42 { + t.Errorf("TotalCostUSD = %f, want 0.42 from ResultEvent", metrics.TotalCostUSD) + } + if metrics.InputTokens != 12000 { + t.Errorf("InputTokens = %d, want 12000 from ResultEvent", metrics.InputTokens) + } +} + func TestProgressParserNoResultEvent(t *testing.T) { + // An assistant line with no message_start is not an API turn; incremental + // NumTurns is counted from message_start only (#6806). lines := []string{ `{"type":"assistant","content":[{"type":"tool_use","name":"Read","input":{"file_path":"/a.go"}}]}`, } @@ -626,7 +672,7 @@ func TestProgressParserNoResultEvent(t *testing.T) { } if metrics.NumTurns != 0 { - t.Errorf("expected 0 turns when no result event, got %d", metrics.NumTurns) + t.Errorf("expected 0 turns when no message_start or result event, got %d", metrics.NumTurns) } if metrics.TotalCostUSD != 0 { t.Errorf("expected 0 cost when no result event, got %f", metrics.TotalCostUSD) @@ -1263,6 +1309,9 @@ func TestParseClaudeStreamTokensEvent(t *testing.T) { if tokens[0].CacheRead != 500 || tokens[0].CacheWrite != 200 { t.Errorf("unexpected cache counts: %+v", tokens[0]) } + if tokens[0].NumTurns != 1 { + t.Errorf("expected 1 turn on TokensEvent, got %d", tokens[0].NumTurns) + } } func TestParseClaudeStreamTokensEventWithReasoningTokens(t *testing.T) { @@ -1456,6 +1505,12 @@ func TestProgressParserCancelledRunCapturesTokens(t *testing.T) { if metrics.CacheCreationInputTokens != 200 { t.Errorf("expected 200 cache creation tokens, got %d", metrics.CacheCreationInputTokens) } + if metrics.NumTurns != 1 { + t.Errorf("expected 1 turn from message_start on cancelled run, got %d", metrics.NumTurns) + } + if metrics.TotalCostUSD != 0 { + t.Errorf("expected 0 cost on cancelled run, got %f", metrics.TotalCostUSD) + } } // TestProgressParserResultOverwritesIncrementalTokens verifies that when a @@ -1531,6 +1586,9 @@ func TestParseClaudeStreamCumulativeTokensAcrossMessages(t *testing.T) { if lastTokens.CacheWrite != 300 { t.Errorf("expected cumulative cache write 300, got %d", lastTokens.CacheWrite) } + if lastTokens.NumTurns != 2 { + t.Errorf("expected 2 turns from two message_start events, got %d", lastTokens.NumTurns) + } } // TestParseClaudeStreamNoFinalTokensEventAfterResult verifies that when @@ -1615,6 +1673,12 @@ func TestParseClaudeStreamBrokenPipeCapturesTokens(t *testing.T) { if metrics.Model != "claude-opus-4-6" { t.Errorf("Model = %q, want claude-opus-4-6", metrics.Model) } + if metrics.NumTurns != 1 { + t.Errorf("NumTurns = %d, want 1 (message_start counted on incomplete stream)", metrics.NumTurns) + } + if metrics.TotalCostUSD != 0 { + t.Errorf("TotalCostUSD = %f, want 0 (cost is only on ResultEvent)", metrics.TotalCostUSD) + } } // TestParseClaudeStreamFinalTokensEventOnCancel verifies that a deferred @@ -1647,6 +1711,9 @@ func TestParseClaudeStreamFinalTokensEventOnCancel(t *testing.T) { if tokens[0].OutputTokens != 500 { t.Errorf("expected 500 output tokens, got %d", tokens[0].OutputTokens) } + if tokens[0].NumTurns != 1 { + t.Errorf("expected 1 turn on deferred TokensEvent, got %d", tokens[0].NumTurns) + } } // TestParseClaudeStreamMalformedResultFallsBackToTokensEvent verifies that @@ -1757,3 +1824,75 @@ func TestParseClaudeStream_ServerToolUseCarriesNoID(t *testing.T) { t.Errorf("client tool_use must keep its id, got %+v", uses[1]) } } + +// TestProgressParserIncompleteStreamCapturesTurns is the #6806 regression: +// a stream that did real work (multiple API turns) but never emitted a +// result line must still report non-zero num_turns. Dollar cost stays +// zero because Claude Code only reports it on the terminal result event +// and fullsend does not estimate cost from token counts. +func TestProgressParserIncompleteStreamCapturesTurns(t *testing.T) { + lines := []string{ + `{"type":"system","subtype":"init","model":"claude-opus-4-6"}`, + `{"type":"stream_event","event":{"type":"message_start","message":{"usage":{"input_tokens":3000,"cache_read_input_tokens":500,"cache_creation_input_tokens":200}}}}`, + `{"type":"stream_event","event":{"type":"message_delta","usage":{"output_tokens":800}}}`, + `{"type":"stream_event","event":{"type":"message_start","message":{"usage":{"input_tokens":4000,"cache_read_input_tokens":600,"cache_creation_input_tokens":100}}}}`, + `{"type":"stream_event","event":{"type":"message_delta","usage":{"output_tokens":900}}}`, + `{"type":"stream_event","event":{"type":"message_start","message":{"usage":{"input_tokens":5000,"cache_read_input_tokens":700,"cache_creation_input_tokens":50}}}}`, + `{"type":"stream_event","event":{"type":"message_delta","usage":{"output_tokens":1100}}}`, + // Process died before the result line. + } + + input := strings.NewReader(strings.Join(lines, "\n")) + var buf bytes.Buffer + printer := ui.New(&buf) + metrics := &RunMetrics{} + + if err := progressParser(input, printer, metrics); err != nil { + t.Fatalf("progressParser returned error: %v", err) + } + + if metrics.NumTurns != 3 { + t.Errorf("NumTurns = %d, want 3 (one per message_start)", metrics.NumTurns) + } + if metrics.TotalCostUSD != 0 { + t.Errorf("TotalCostUSD = %f, want 0 (no ResultEvent, no cost fallback)", metrics.TotalCostUSD) + } + if metrics.InputTokens != 12000 { + t.Errorf("InputTokens = %d, want 12000", metrics.InputTokens) + } + if metrics.OutputTokens != 2800 { + t.Errorf("OutputTokens = %d, want 2800", metrics.OutputTokens) + } + if metrics.Model != "claude-opus-4-6" { + t.Errorf("Model = %q, want claude-opus-4-6", metrics.Model) + } +} + +// TestParseClaudeStreamMessageStartWithoutDeltaStillCountsTurn covers the +// kill-during-generation case: message_start arrived, message_delta did +// not, so the mid-stream TokensEvent throttle never fired. The EOF +// snapshot must still carry NumTurns. +func TestParseClaudeStreamMessageStartWithoutDeltaStillCountsTurn(t *testing.T) { + lines := []string{ + `{"type":"stream_event","event":{"type":"message_start","message":{"usage":{"input_tokens":1500}}}}`, + } + events := collectEvents(t, strings.Join(lines, "\n")) + + var last TokensEvent + var found bool + for _, e := range events { + if te, ok := e.(TokensEvent); ok { + last = te + found = true + } + } + if !found { + t.Fatal("expected a deferred TokensEvent at EOF") + } + if last.NumTurns != 1 { + t.Errorf("NumTurns = %d, want 1", last.NumTurns) + } + if last.InputTokens != 1500 { + t.Errorf("InputTokens = %d, want 1500", last.InputTokens) + } +} diff --git a/internal/runtime/event.go b/internal/runtime/event.go index 0b2faf0235..2e93ccaa49 100644 --- a/internal/runtime/event.go +++ b/internal/runtime/event.go @@ -78,12 +78,17 @@ type ToolResultEvent struct { func (ToolResultEvent) agentEvent() {} // TokensEvent carries incremental token usage counters. +// NumTurns is the running turn count from the stream (Claude Code +// counts message_start events). It is 0 when the emitter does not +// track turns incrementally; ResultEvent remains authoritative when +// the stream completes normally. type TokensEvent struct { InputTokens int OutputTokens int ReasoningTokens int CacheRead int CacheWrite int + NumTurns int } func (TokensEvent) agentEvent() {} From 3e04bd59951a525a5acbd3174c338a9505d36e5e Mon Sep 17 00:00:00 2001 From: fullsend-fix <278716306+fullsend-ai-coder[bot]@users.noreply.github.com> Date: Thu, 24 Sep 2026 19:35:56 +0000 Subject: [PATCH 2/2] refactor(#6806): guard applyClaudeMetrics against a nil *RunMetrics Add the same nil check applyCodexMetrics already has. No current call site passes nil, so this is a defensive consistency fix, not a live crash fix, per review feedback on PR #7687. Addresses #7687 --- internal/runtime/claude_progress.go | 3 +++ internal/runtime/claude_progress_test.go | 3 +++ 2 files changed, 6 insertions(+) diff --git a/internal/runtime/claude_progress.go b/internal/runtime/claude_progress.go index f37cd196dc..955602b65f 100644 --- a/internal/runtime/claude_progress.go +++ b/internal/runtime/claude_progress.go @@ -540,6 +540,9 @@ func toolResultText(raw json.RawMessage) (text string, partial bool) { // totals. Dollar cost is ResultEvent-only: Claude Code does not report // incremental cost, and fullsend does not estimate it from token counts. func applyClaudeMetrics(metrics *RunMetrics, evt AgentEvent) { + if metrics == nil { + return + } switch e := evt.(type) { case InitEvent: if metrics.Model == "" { diff --git a/internal/runtime/claude_progress_test.go b/internal/runtime/claude_progress_test.go index f0c7e7b1d0..dcd93892f2 100644 --- a/internal/runtime/claude_progress_test.go +++ b/internal/runtime/claude_progress_test.go @@ -653,6 +653,9 @@ func TestApplyClaudeMetricsTokensEventSetsTurns(t *testing.T) { if metrics.InputTokens != 12000 { t.Errorf("InputTokens = %d, want 12000 from ResultEvent", metrics.InputTokens) } + + // A nil *RunMetrics must not panic, matching applyCodexMetrics. + applyClaudeMetrics(nil, ResultEvent{}) } func TestProgressParserNoResultEvent(t *testing.T) {