Classify voice session failures and record terminal outcomes (#52756)

## Why

Voice failure metrics lacked cause and lifecycle phase, and session durations were recorded before the final outcome was known. A failed control send could also overwrite a more specific WebRTC error.

## What changed

- Tag `codex.voice.session.failure` with bounded `cause` and `phase` values, recording at most one failure per session.
- Capture duration when stopping and emit `codex.voice.session.duration` at cleanup with a `success` or `failure` outcome.
- Carry typed WebRTC errors into the TUI, preserve existing errors when control sends fail, and avoid duplicate errors after startup failure.
- Record app-server disconnect failures for background voice sessions as well as the visible session.

## Testing

Add coverage for terminal outcome and failure metric attributes, preservation of specific startup and audio-session errors, and startup failures without duplicate control-channel errors.

GitOrigin-RevId: 5aeda6e766093e3fce7206560aa83b6f7770dddb
This commit is contained in:
Benjamin Carlsson
2026-10-10 02:54:59 +00:00
committed by copyberry
parent 1652992148
commit 322bbf4d84
18 changed files with 431 additions and 66 deletions
+15 -2
View File
@@ -1124,6 +1124,17 @@ impl App {
self.active_thread_id = visible_thread;
}
if let Err(err) = result {
if is_realtime_stop {
let chat_widget = match self.background_voice.as_deref_mut() {
Some(owner) if parked_voice => owner,
_ => &mut self.chat_widget,
};
if chat_widget.thread_id() == realtime_stop_thread_id {
chat_widget.record_realtime_failure(
crate::chatwidget::RealtimeFailureCause::AppServerRequest,
);
}
}
if self.recover_transport_error(&err) {
return Ok(AppRunControl::Continue);
}
@@ -1150,12 +1161,14 @@ impl App {
let message = format!("Voice conversation failed: {err:#}");
if is_realtime_stop {
if chat_widget.thread_id() == realtime_stop_thread_id {
chat_widget.record_realtime_failure();
chat_widget.reset_realtime_conversation();
chat_widget.add_realtime_error(message);
}
} else {
chat_widget.on_realtime_error(message);
chat_widget.on_realtime_error(
message,
crate::chatwidget::RealtimeFailureCause::AppServerRequest,
);
}
tracing::error!(error = ?err, "realtime conversation request failed");
} else if handled {
+1
View File
@@ -191,6 +191,7 @@ impl App {
self.chat_widget.restore_user_message_to_composer(message);
}
if let Some(owner) = self.background_voice.as_mut() {
owner.record_realtime_disconnect_failure();
owner.reset_realtime_conversation();
}
self.retire_background_voice();
+4 -2
View File
@@ -486,7 +486,8 @@ impl App {
| AppCommand::RealtimeConversationStop { thread_id } = &op
&& self.chat_widget.thread_id() == Some(*thread_id)
{
self.chat_widget.record_realtime_failure();
self.chat_widget
.record_realtime_failure(crate::chatwidget::RealtimeFailureCause::LocalRequest);
self.chat_widget.reset_realtime_conversation();
}
self.chat_widget
@@ -512,7 +513,8 @@ impl App {
| AppCommand::RealtimeConversationStop { thread_id } = &op
&& self.chat_widget.thread_id() == Some(*thread_id)
{
self.chat_widget.record_realtime_failure();
self.chat_widget
.record_realtime_failure(crate::chatwidget::RealtimeFailureCause::LocalRequest);
self.chat_widget.reset_realtime_conversation();
}
self.chat_widget.add_error_message(