Include terminal errors in turn completion events (#32280)

## What changed

- Add an optional `error` payload to `TurnCompleteEvent` and omit it when a turn completes without an error.
- Preserve the full terminal `ErrorEvent` through the turn lifecycle so the completion event includes the same error details emitted separately by `EventMsg::Error`.

## Testing

- Extend the stream-error integration test to verify that `TurnCompleteEvent` contains the emitted error and that the next turn can still proceed.

GitOrigin-RevId: 8d32942a44132763076130102d8b89ab356d59d0
This commit is contained in:
Owen Lin authored and copyberry committed 2026-07-10 22:04:03 +00:00
1 parent 09ccae2c07
commit c4318c386d
19 files changed
+92 -6

No files matched your search

+2
View File
@@ -766,11 +766,13 @@ impl Session {
.turn_timing_state
.time_to_first_token_ms()
.await;
let error = turn_context.terminal_error.lock().await.clone();
self.emit_turn_stop_lifecycle(turn_context.extension_data.as_ref())
.await;
EventMsg::TurnComplete(TurnCompleteEvent {
turn_id: turn_context.sub_id.clone(),
last_agent_message,
error,
started_at,
completed_at,
duration_ms,