Track voice session lifecycle metrics in the TUI (#43934)

## What changed

- Record voice session starts, connections, failures, endings, and active duration under `codex.voice.session.*`.
- Deduplicate failure accounting and distinguish errors during startup retry cleanup from errors during a requested stop.
- Record failures on rejected voice operations and disconnects, and clear the owned session when a stop request is rejected.

## Testing

Add regression tests for failure accounting during retry cleanup and session cleanup after rejected stop requests, including replay-only threads.

GitOrigin-RevId: d67cab5ff1e8fc85ce7a3d61a1763d38a5d537f0
This commit is contained in:
Benjamin Carlsson authored and copyberry committed 2026-09-08 22:21:01 +00:00
1 parent 5e3f0ee94b
commit fba22e9a2a
7 files changed
+140 -7

No files matched your search

+1
View File
@@ -849,6 +849,7 @@ impl App {
let message = format!("Voice conversation failed: {err:#}");
if is_realtime_stop {
if self.chat_widget.thread_id() == realtime_stop_thread_id {
self.chat_widget.record_realtime_failure();
self.chat_widget.reset_realtime_conversation();
self.chat_widget.add_error_message(message);
}
@@ -62,3 +62,39 @@ async fn rejected_voice_start_does_not_leave_local_capture_active() -> Result<()
}
Ok(())
}
#[tokio::test]
async fn rejected_voice_stop_clears_the_owned_session() -> Result<()> {
for replay_only in [false, true] {
let (mut app, _events, _ops) = make_test_app_with_channels().await;
let (mut app_server, requests, proxy) =
start_recording_remote_app_server(&app.config).await?;
let thread_id = ThreadId::new();
app.chat_widget
.handle_thread_session_quiet(test_thread_session(
thread_id,
app.config.cwd.to_path_buf(),
));
crate::chatwidget::activate_voice_for_thread(&mut app.chat_widget, thread_id);
if replay_only {
app.app_server_target = AppServerTarget::Remote {
endpoint: crate::resolve_remote_addr("ws://127.0.0.1:9")?,
};
app.active_thread_id = Some(thread_id);
app.ensure_thread_channel(thread_id).mark_replay_only();
}
let mut tui = crate::tui::test_support::make_test_tui()?;
Box::pin(app.handle_event(
&mut tui,
&mut app_server,
AppEvent::CodexOp(Op::RealtimeConversationStop { thread_id }),
))
.await?;
assert!(!app.chat_widget.may_receive_realtime_transcripts());
assert!(recorded_params(&requests, "thread/realtime/stop").is_empty());
app_server.shutdown().await?;
proxy.await??;
}
Ok(())
}
+6 -2
View File
@@ -482,9 +482,11 @@ impl App {
self.chat_widget
.restore_undelivered_realtime_speech(*delivery_id);
}
if let AppCommand::RealtimeConversationStart { thread_id, .. } = &op
if let AppCommand::RealtimeConversationStart { thread_id, .. }
| AppCommand::RealtimeConversationStop { thread_id } = &op
&& self.chat_widget.thread_id() == Some(*thread_id)
{
self.chat_widget.record_realtime_failure();
self.chat_widget.reset_realtime_conversation();
}
self.chat_widget
@@ -506,9 +508,11 @@ impl App {
self.chat_widget
.restore_undelivered_realtime_speech(*delivery_id);
}
if let AppCommand::RealtimeConversationStart { thread_id, .. } = &op
if let AppCommand::RealtimeConversationStart { thread_id, .. }
| AppCommand::RealtimeConversationStop { thread_id } = &op
&& self.chat_widget.thread_id() == Some(*thread_id)
{
self.chat_widget.record_realtime_failure();
self.chat_widget.reset_realtime_conversation();
}
self.chat_widget.add_error_message(