Include start times in terminal turn events (#32263)

## What changed

- Add an optional `started_at` Unix timestamp to `TurnCompleteEvent` and
  `TurnAbortedEvent`.
- Populate the timestamp from turn timing state when a turn completes or is
  aborted.
- Preserve the timestamp when synthesizing interrupted fork history and when
  importing external sessions.

## Testing

- Verify that interrupting a turn emits a `TurnAbortedEvent` with a start
  timestamp.

GitOrigin-RevId: 75b3911b95c060e5fc1843a5e293d8fe47377186
This commit is contained in:
Owen Lin
2026-07-10 20:25:03 +00:00
committed by copyberry
parent b66c25c6a3
commit bca577d69a
20 changed files with 144 additions and 7 deletions
+9
View File
@@ -740,6 +740,7 @@ impl Session {
turn_context.config.memories.use_memories,
turn_had_memory_citation,
);
let started_at = turn_context.turn_timing_state.started_at_unix_secs().await;
let (completed_at, duration_ms) = turn_context
.turn_timing_state
.completed_at_and_duration_ms()
@@ -756,6 +757,7 @@ impl Session {
EventMsg::TurnAborted(TurnAbortedEvent {
turn_id: Some(turn_context.sub_id.clone()),
reason,
started_at,
completed_at,
duration_ms,
})
@@ -769,6 +771,7 @@ impl Session {
EventMsg::TurnComplete(TurnCompleteEvent {
turn_id: turn_context.sub_id.clone(),
last_agent_message,
started_at,
completed_at,
duration_ms,
time_to_first_token_ms,
@@ -877,6 +880,11 @@ impl Session {
}
}
let started_at = task
.turn_context
.turn_timing_state
.started_at_unix_secs()
.await;
let (completed_at, duration_ms) = task
.turn_context
.turn_timing_state
@@ -891,6 +899,7 @@ impl Session {
let event = EventMsg::TurnAborted(TurnAbortedEvent {
turn_id: Some(task.turn_context.sub_id.clone()),
reason,
started_at,
completed_at,
duration_ms,
});