Track compaction time in turn profiles (#34835)

## What changed

- Add `compaction_ms` to turn profile facts and turn analytics events.
- Measure manual and automatic compaction as an exclusive profile phase instead of including it in surrounding idle time.
- Complete the profile and total turn duration from the same instant so their elapsed times remain consistent.

## Testing

- Cover compaction phase accounting and profile-duration consistency.
- Update turn event serialization coverage for `compaction_ms`.

GitOrigin-RevId: 50f0e1cf19789a807f9f56c2ef763c620a5d641c
This commit is contained in:
Ben Romano authored and copyberry committed 2026-07-22 22:13:02 +00:00
1 parent 88f1cd9664
commit bd5b55e403
9 files changed
+114 -18

No files matched your search

@@ -441,9 +441,10 @@ fn sample_turn_profile() -> TurnProfile {
TurnProfile {
before_first_sampling_ms: 100,
sampling_ms: 700,
compaction_ms: 40,
between_sampling_overhead_ms: 50,
tool_blocking_ms: 250,
after_last_sampling_ms: 134,
after_last_sampling_ms: 94,
sampling_request_count: 2,
sampling_retry_count: 1,
}
@@ -4065,9 +4066,10 @@ fn turn_event_serializes_expected_shape() {
total_tokens: None,
before_first_sampling_ms: 100,
sampling_ms: 700,
compaction_ms: 40,
between_sampling_overhead_ms: 50,
tool_blocking_ms: 250,
after_last_sampling_ms: 134,
after_last_sampling_ms: 94,
sampling_request_count: 2,
sampling_retry_count: 1,
duration_ms: Some(1234),
@@ -4138,9 +4140,10 @@ fn turn_event_serializes_expected_shape() {
"total_tokens": null,
"before_first_sampling_ms": 100,
"sampling_ms": 700,
"compaction_ms": 40,
"between_sampling_overhead_ms": 50,
"tool_blocking_ms": 250,
"after_last_sampling_ms": 134,
"after_last_sampling_ms": 94,
"sampling_request_count": 2,
"sampling_retry_count": 1,
"duration_ms": 1234,