From 99f72e27ae778d76328fc555842f58c87250c3db Mon Sep 17 00:00:00 2001 From: Ahmed Ibrahim Date: Sun, 5 Apr 2026 10:44:06 -0700 Subject: [PATCH] codex: fix CI failure on PR #16805 Keep the first realtime audio frame from being dropped during WebRTC startup. Also give the realtime test server a tiny flush window before it closes the data channel so the last scripted events land reliably. Co-authored-by: Codex --- .../codex-api/src/endpoint/realtime_websocket/methods.rs | 6 ++++++ .../core/tests/common/responses/realtime_webrtc_server.rs | 2 ++ 2 files changed, 8 insertions(+) diff --git a/codex-rs/codex-api/src/endpoint/realtime_websocket/methods.rs b/codex-rs/codex-api/src/endpoint/realtime_websocket/methods.rs index 00317bbe15..b897ca6a49 100644 --- a/codex-rs/codex-api/src/endpoint/realtime_websocket/methods.rs +++ b/codex-rs/codex-api/src/endpoint/realtime_websocket/methods.rs @@ -65,6 +65,7 @@ const REALTIME_AUDIO_CHANNELS: u16 = 1; const REALTIME_AUDIO_PACKET_SAMPLES: usize = 480; const REALTIME_AUDIO_PACKET_DURATION: Duration = Duration::from_millis(20); const REALTIME_DATA_CHANNEL_OPEN_TIMEOUT: Duration = Duration::from_secs(10); +const REALTIME_AUDIO_TRACK_BINDING_SETTLE_TIME: Duration = Duration::from_millis(250); const OPUS_MAX_PACKET_BYTES: usize = 4_000; const OPUS_MAX_DECODED_SAMPLES_PER_CHANNEL: usize = 2_880; @@ -601,6 +602,11 @@ async fn connect_webrtc_transport( })? .map_err(|_| ApiError::Stream("realtime WebRTC data channel did not open".to_string()))?; + // `TrackLocalStaticSample::write_sample()` silently drops samples until the RTP sender has + // finished binding after negotiation. Give webrtc-rs a short grace period so the first user + // audio frame is not discarded during startup. + tokio::time::sleep(REALTIME_AUDIO_TRACK_BINDING_SETTLE_TIME).await; + info!( calls_url = %calls_url, "realtime WebRTC session connected" diff --git a/codex-rs/core/tests/common/responses/realtime_webrtc_server.rs b/codex-rs/core/tests/common/responses/realtime_webrtc_server.rs index ad9645edc4..1d6237b47d 100644 --- a/codex-rs/core/tests/common/responses/realtime_webrtc_server.rs +++ b/codex-rs/core/tests/common/responses/realtime_webrtc_server.rs @@ -37,6 +37,7 @@ const HTTP_HEADER_TERMINATOR: &[u8] = b"\r\n\r\n"; const REALTIME_AUDIO_CHANNELS: u8 = 1; const REALTIME_AUDIO_SAMPLE_RATE: u32 = 24_000; const REALTIME_DATA_CHANNEL_TIMEOUT: Duration = Duration::from_secs(10); +const REALTIME_DATA_CHANNEL_FLUSH_DELAY: Duration = Duration::from_millis(25); const REALTIME_MAX_DECODED_SAMPLES_PER_CHANNEL: usize = 5760; pub(super) async fn accept_is_http_post(stream: &TcpStream) -> bool { @@ -404,6 +405,7 @@ async fn serve_scripted_requests( } if connection.close_after_requests { + tokio::time::sleep(REALTIME_DATA_CHANNEL_FLUSH_DELAY).await; let _ = data_channel.close().await; } }