mirror of
https://github.com/openai/codex.git
synced 2026-11-13 06:45:07 +00:00
Omit undersized WAV output from Code Mode (#41934)
## Why Audio models cannot reliably encode tool-generated clips shorter than 25 ms. ## What changed - Measure the available audio frames in base64-encoded PCM and IEEE float WAV outputs. - Replace clips under 25 ms with explanatory text while preserving surrounding Code Mode output. - Leave clips at or above the threshold and unrecognized audio formats unchanged. ## Testing - Cover the duration boundary across multiple sample rates and all supported `audio()` input forms. - Verify bounded and truncated WAV chunks, output after `yield_control()`, and end-to-end mixed text and audio output. GitOrigin-RevId: 342b4bdbc65db4238580f9cdc372763c2576eca5
This commit is contained in:
1 parent
a62ff9a5d4
commit
981d6b652b
8 files changed
+326
No files matched your search
@@ -38,6 +38,7 @@ use codex_protocol::models::ContentItem;
|
||||
use codex_protocol::models::ImageDetail;
|
||||
use codex_protocol::models::PermissionProfile;
|
||||
use codex_protocol::models::ResponseItem;
|
||||
use codex_protocol::openai_models::InputModality;
|
||||
use codex_protocol::openai_models::ToolMode;
|
||||
use codex_protocol::protocol::AskForApproval;
|
||||
use codex_protocol::protocol::EventMsg;
|
||||
@@ -3856,6 +3857,89 @@ text("after");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn code_mode_omits_short_audio_and_preserves_other_output() -> Result<()> {
|
||||
skip_if_no_network!(Ok(()));
|
||||
|
||||
let [short_audio_url, valid_audio_url] = [120_u32, 600].map(|frames| {
|
||||
let sample_rate = 24_000_u32;
|
||||
let data_size = frames * 2;
|
||||
let mut wav = b"RIFF".to_vec();
|
||||
wav.extend_from_slice(&(36 + data_size).to_le_bytes());
|
||||
wav.extend_from_slice(b"WAVEfmt ");
|
||||
wav.extend_from_slice(&16_u32.to_le_bytes());
|
||||
wav.extend_from_slice(&1_u16.to_le_bytes());
|
||||
wav.extend_from_slice(&1_u16.to_le_bytes());
|
||||
wav.extend_from_slice(&sample_rate.to_le_bytes());
|
||||
wav.extend_from_slice(&(sample_rate * 2).to_le_bytes());
|
||||
wav.extend_from_slice(&2_u16.to_le_bytes());
|
||||
wav.extend_from_slice(&16_u16.to_le_bytes());
|
||||
wav.extend_from_slice(b"data");
|
||||
wav.extend_from_slice(&data_size.to_le_bytes());
|
||||
wav.resize(44 + data_size as usize, /*value*/ 0);
|
||||
format!("data:audio/wav;base64,{}", BASE64_STANDARD.encode(wav))
|
||||
});
|
||||
let code = format!(
|
||||
r#"
|
||||
text("before");
|
||||
audio({short_audio_url:?});
|
||||
text("between");
|
||||
audio({valid_audio_url:?});
|
||||
text("after");
|
||||
"#,
|
||||
);
|
||||
|
||||
let server = responses::start_mock_server().await;
|
||||
let mut builder = test_codex()
|
||||
.with_model_info_override("gpt-5.4", |model| {
|
||||
model.input_modalities.push(InputModality::Audio);
|
||||
})
|
||||
.with_config(|config| {
|
||||
let _ = config.features.enable(Feature::CodeMode);
|
||||
});
|
||||
let test = builder.build_with_auto_env(&server).await?;
|
||||
responses::mount_sse_once(
|
||||
&server,
|
||||
sse(vec![
|
||||
ev_response_created("resp-1"),
|
||||
ev_custom_tool_call("call-1", "exec", &code),
|
||||
ev_completed("resp-1"),
|
||||
]),
|
||||
)
|
||||
.await;
|
||||
let second_mock = responses::mount_sse_once(
|
||||
&server,
|
||||
sse(vec![
|
||||
ev_assistant_message("msg-1", "done"),
|
||||
ev_completed("resp-2"),
|
||||
]),
|
||||
)
|
||||
.await;
|
||||
|
||||
test.submit_turn("use exec to return short and valid audio with text")
|
||||
.await?;
|
||||
|
||||
let req = second_mock.single_request();
|
||||
let items = custom_tool_output_items(&req, "call-1");
|
||||
let (_, success) = custom_tool_output_body_and_success(&req, "call-1");
|
||||
assert_ne!(success, Some(false));
|
||||
assert_eq!(
|
||||
&items[1..],
|
||||
&[
|
||||
serde_json::json!({ "type": "input_text", "text": "before" }),
|
||||
serde_json::json!({
|
||||
"type": "input_text",
|
||||
"text": "Audio output omitted because the clip is shorter than 25 ms; use a longer clip."
|
||||
}),
|
||||
serde_json::json!({ "type": "input_text", "text": "between" }),
|
||||
serde_json::json!({ "type": "input_audio", "audio_url": valid_audio_url }),
|
||||
serde_json::json!({ "type": "input_text", "text": "after" }),
|
||||
]
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn code_mode_replaces_malformed_image() -> Result<()> {
|
||||
skip_if_no_network!(Ok(()));
|
||||
|
||||
Reference in new issue
Block a user