From af90ddec7e57fc89eb4db36c003dbb97d44d9f0f Mon Sep 17 00:00:00 2001 From: Adam Malczewski Date: Mon, 22 Jun 2026 13:01:13 +0900 Subject: fix(metrics): show turn/step metrics for compacted conversations Compacted conversations start with a system summary (role: "system") instead of a user message (role: "user"). The interleaveTurnMetrics function only detected segments by role === "user", so compacted conversations got zero segments and no metrics were emitted. Fix: when no user messages are found but metrics entries exist, treat the entire transcript as one segment. This places turn-metrics at the end and anchors step-metrics to any tool-batch groups by stepId. 686 tests green. --- src/core/metrics/place.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/core/metrics/place.ts b/src/core/metrics/place.ts index 47d3c5f..0048fa0 100644 --- a/src/core/metrics/place.ts +++ b/src/core/metrics/place.ts @@ -64,7 +64,15 @@ export function interleaveTurnMetrics( } } - const T = segmentStarts.length; + let T = segmentStarts.length; + + // No user messages — e.g. a compacted conversation whose history starts + // with a system summary. Treat the entire transcript as one segment so + // turn/step metrics can still be placed. + if (T === 0 && entries.length > 0) { + segmentStarts.push(0); + T = 1; + } if (T === 0) { return groups.map((g) => ({ kind: "group" as const, group: g })); -- cgit v1.2.3