diff --git a/codex-rs/tui/src/app/event_dispatch.rs b/codex-rs/tui/src/app/event_dispatch.rs index 893e475d4f..1bb7d1cdeb 100644 --- a/codex-rs/tui/src/app/event_dispatch.rs +++ b/codex-rs/tui/src/app/event_dispatch.rs @@ -2523,7 +2523,9 @@ impl App { let result = match result { Ok(call) => { owner.accept_realtime_call(call.answer_sdp); - app_server.thread_realtime_start(thread_id, call.call_id).await + app_server + .thread_realtime_start(thread_id, call.call_id, call.voice_session_id) + .await } Err(error) => Err(error), }; diff --git a/codex-rs/tui/src/app/tests/realtime_handoff_e2e.rs b/codex-rs/tui/src/app/tests/realtime_handoff_e2e.rs index 6999cda88b..f39a2dd91e 100644 --- a/codex-rs/tui/src/app/tests/realtime_handoff_e2e.rs +++ b/codex-rs/tui/src/app/tests/realtime_handoff_e2e.rs @@ -139,7 +139,7 @@ async fn delegated_core_events_keep_private_output_hidden_and_deliver_final_spee .await?; assert_eq!(String::from(call.answer_sdp), "v=answer\r\n"); app_server - .thread_realtime_start(thread_id, call.call_id) + .thread_realtime_start(thread_id, call.call_id, call.voice_session_id) .await?; // The sideband fixture sends its delegation after the first outbound request. app_server diff --git a/codex-rs/tui/src/app/tests/realtime_requests.rs b/codex-rs/tui/src/app/tests/realtime_requests.rs index 535fce5e34..d6bd9efc2f 100644 --- a/codex-rs/tui/src/app/tests/realtime_requests.rs +++ b/codex-rs/tui/src/app/tests/realtime_requests.rs @@ -227,6 +227,11 @@ async fn check_remote_voice_start( assert_eq!(calls.len(), 1); assert_eq!(calls[0].headers["thread-id"], thread_id.to_string()); assert_eq!(calls[0].headers["session-id"], thread_id.to_string()); + let voice_session_id = calls[0].headers["voice-session-id"].to_str()?; + let uuid = uuid::Uuid::parse_str(voice_session_id)?; + assert_eq!(uuid.get_version(), Some(uuid::Version::Random)); + assert_eq!(uuid.to_string(), voice_session_id); + assert_ne!(voice_session_id, thread_id.to_string()); if base_path == "/v1" { let body = std::str::from_utf8(&calls[0].body)?; assert!(body.contains(r#""voice":"marin""#)); @@ -244,6 +249,7 @@ async fn check_remote_voice_start( assert_eq!(starts.len(), 1); let start = &starts[0]; assert_eq!(start["realtimeSessionId"], thread_id.to_string()); + assert_eq!(start["voiceSessionId"], voice_session_id); assert_eq!( serde_json::json!({ "threadId": start["threadId"], diff --git a/codex-rs/tui/src/app_server_session/realtime.rs b/codex-rs/tui/src/app_server_session/realtime.rs index 721dcdc3b4..49e1af6dd1 100644 --- a/codex-rs/tui/src/app_server_session/realtime.rs +++ b/codex-rs/tui/src/app_server_session/realtime.rs @@ -14,12 +14,14 @@ use codex_protocol::protocol::RealtimeConversationVersion; use codex_protocol::protocol::RealtimeOutputModality; use color_eyre::eyre::Result; use color_eyre::eyre::WrapErr; +use uuid::Uuid; impl AppServerSession { pub(crate) async fn thread_realtime_start( &mut self, thread_id: ThreadId, call_id: String, + voice_session_id: Uuid, ) -> Result<()> { let request_id = self.next_request_id(); let _: ThreadRealtimeStartResponse = self @@ -44,7 +46,7 @@ impl AppServerSession { realtime_end_instructions: None, prompt: None, realtime_session_id: Some(thread_id.to_string()), - voice_session_id: None, + voice_session_id: Some(voice_session_id.to_string()), transport: Some(ThreadRealtimeStartTransport::ExistingCall { // The TUI owns the peer connection and has already negotiated this call. call_id, diff --git a/codex-rs/tui/src/realtime_call.rs b/codex-rs/tui/src/realtime_call.rs index 5b2a3f5712..b4986d5157 100644 --- a/codex-rs/tui/src/realtime_call.rs +++ b/codex-rs/tui/src/realtime_call.rs @@ -23,10 +23,12 @@ use codex_protocol::protocol::RealtimeVoice; use color_eyre::eyre::Result; use color_eyre::eyre::ensure; use http::HeaderValue; +use uuid::Uuid; #[derive(Debug)] pub(crate) struct CreatedCall { pub(crate) call_id: String, + pub(crate) voice_session_id: Uuid, pub(crate) answer_sdp: RealtimeSdp, } @@ -57,6 +59,7 @@ pub(crate) async fn create( ClientRedirectPolicy::Reject, )?; let id = thread.id.clone(); + let voice_session_id = Uuid::new_v4(); let mut headers = build_realtime_thread_headers( thread.session_id.clone(), id.clone(), @@ -64,6 +67,10 @@ pub(crate) async fn create( ); headers.insert("openai-alpha", HeaderValue::from_static("quicksilver=v2")); headers.insert("x-session-id", HeaderValue::from_str(&id)?); + headers.insert( + "voice-session-id", + HeaderValue::from_str(&voice_session_id.to_string())?, + ); add_originator_header(&mut headers, &originator().value); let session = RealtimeSessionConfig { instructions: prepare_realtime_backend_prompt( @@ -93,6 +100,7 @@ pub(crate) async fn create( .await?; Ok(CreatedCall { call_id: call.call_id, + voice_session_id, answer_sdp: call.sdp.into(), }) }