Pass a per-call voice session ID through TUI realtime startup (#61908)

## What changed

Generate a UUID v4 for each TUI realtime call, send it in the `voice-session-id` header, and forward the same value as `voiceSessionId` in `thread/realtime/start`.

## Testing

Extend realtime request tests to verify that the ID is a canonical UUID v4 distinct from the thread ID and matches across call creation and realtime startup.

GitOrigin-RevId: 8446b4bf9965b6034422b3f8cf83e20840425c43
This commit is contained in:
Chris Dong
2026-11-16 23:24:42 +00:00
committed by copyberry
parent b08fd8a6f1
commit 837f8b50be
5 changed files with 21 additions and 3 deletions
+3 -1
View File
@@ -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),
};
@@ -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
@@ -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"],
@@ -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,
+8
View File
@@ -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(),
})
}