diff --git a/codex-rs/core/src/client.rs b/codex-rs/core/src/client.rs index 6fd3f1ff57..a715d7bb14 100644 --- a/codex-rs/core/src/client.rs +++ b/codex-rs/core/src/client.rs @@ -180,6 +180,8 @@ pub(crate) struct CompactConversationRequestSettings { fn reasoning_effort_for_request(effort: ReasoningEffortConfig) -> ReasoningEffortConfig { match effort { ReasoningEffortConfig::Ultra => ReasoningEffortConfig::Max, + // Keep "persistent" in local settings; the Responses API calls it "disabled". + ReasoningEffortConfig::Persistent => ReasoningEffortConfig::Custom("disabled".to_string()), effort => effort, } } diff --git a/codex-rs/core/src/client_tests.rs b/codex-rs/core/src/client_tests.rs index 5b74e040b2..b580a4dfff 100644 --- a/codex-rs/core/src/client_tests.rs +++ b/codex-rs/core/src/client_tests.rs @@ -299,13 +299,18 @@ fn test_session_telemetry() -> SessionTelemetry { } #[test] -fn ultra_reasoning_uses_max_for_requests() { +fn reasoning_effort_for_requests_maps_ultra_and_persistent() { assert_eq!( ( super::reasoning_effort_for_request(ReasoningEffort::Ultra), super::reasoning_effort_for_request(ReasoningEffort::High), + super::reasoning_effort_for_request(ReasoningEffort::Persistent), ), - (ReasoningEffort::Max, ReasoningEffort::High,) + ( + ReasoningEffort::Max, + ReasoningEffort::High, + ReasoningEffort::Custom("disabled".to_string()), + ) ); } diff --git a/codex-rs/core/tests/suite/remote_models.rs b/codex-rs/core/tests/suite/remote_models.rs index b1c77fe359..94ac7cb192 100644 --- a/codex-rs/core/tests/suite/remote_models.rs +++ b/codex-rs/core/tests/suite/remote_models.rs @@ -48,6 +48,7 @@ use core_test_support::wait_for_event_match; use pretty_assertions::assert_eq; use serde_json::json; use tempfile::TempDir; +use test_case::test_case; use tokio::time::Duration; use tokio::time::Instant; use tokio::time::sleep; @@ -365,8 +366,13 @@ async fn remote_models_use_context_window_when_config_override_is_absent() -> Re Ok(()) } +#[test_case(ReasoningEffort::Custom("future".to_string()), "future"; "custom")] +#[test_case(ReasoningEffort::Persistent, "disabled"; "persistent")] #[tokio::test(flavor = "multi_thread", worker_threads = 2)] -async fn remote_models_long_model_slug_is_sent_with_custom_reasoning() -> Result<()> { +async fn remote_models_long_model_slug_is_sent_with_supported_reasoning( + effort: ReasoningEffort, + expected_wire_effort: &str, +) -> Result<()> { skip_if_no_network!(Ok(())); skip_if_sandbox!(Ok(())); @@ -379,16 +385,15 @@ async fn remote_models_long_model_slug_is_sent_with_custom_reasoning() -> Result /*priority*/ 1_000, TruncationPolicyConfig::bytes(/*limit*/ 10_000), ); - let custom_reasoning_effort = ReasoningEffort::Custom("future".to_string()); - remote_model.default_reasoning_level = Some(custom_reasoning_effort.clone()); + remote_model.default_reasoning_level = Some(effort.clone()); remote_model.supported_reasoning_levels = vec![ ReasoningEffortPreset { effort: ReasoningEffort::Medium, description: ReasoningEffort::Medium.to_string(), }, ReasoningEffortPreset { - effort: custom_reasoning_effort.clone(), - description: custom_reasoning_effort.to_string(), + effort: effort.clone(), + description: effort.to_string(), }, ]; remote_model.default_reasoning_summary = ReasoningSummary::Detailed; @@ -411,7 +416,7 @@ async fn remote_models_long_model_slug_is_sent_with_custom_reasoning() -> Result .with_config(|config| { config.model = Some(requested_model.to_string()); }) - .build(&server) + .build_with_auto_env(&server) .await?; codex @@ -434,7 +439,7 @@ async fn remote_models_long_model_slug_is_sent_with_custom_reasoning() -> Result .and_then(|reasoning| reasoning.get("summary")) .and_then(|value| value.as_str()); assert_eq!(body["model"].as_str(), Some(requested_model)); - assert_eq!(reasoning_effort, Some("future")); + assert_eq!(reasoning_effort, Some(expected_wire_effort)); assert_eq!(reasoning_summary, Some("detailed")); Ok(()) diff --git a/codex-rs/protocol/src/openai_models.rs b/codex-rs/protocol/src/openai_models.rs index 3dc5aa6261..55ac2153d1 100644 --- a/codex-rs/protocol/src/openai_models.rs +++ b/codex-rs/protocol/src/openai_models.rs @@ -57,6 +57,7 @@ pub enum ReasoningEffort { XHigh, Max, Ultra, + Persistent, /// A model-defined effort value that this client does not know yet. Custom(String), } @@ -73,6 +74,7 @@ impl ReasoningEffort { Self::XHigh => "xhigh", Self::Max => "max", Self::Ultra => "ultra", + Self::Persistent => "persistent", Self::Custom(effort) => effort, } } @@ -139,6 +141,7 @@ impl FromStr for ReasoningEffort { "xhigh" => Ok(Self::XHigh), "max" => Ok(Self::Max), "ultra" => Ok(Self::Ultra), + "persistent" => Ok(Self::Persistent), "" => Err("reasoning_effort must not be empty".to_string()), effort => Ok(Self::Custom(effort.to_string())), } @@ -1132,28 +1135,34 @@ mod tests { let serialized = to_string(&custom).expect("custom reasoning effort should serialize"); let serialized_max = to_string(&ReasoningEffort::Max).expect("Max should serialize"); let serialized_ultra = to_string(&ReasoningEffort::Ultra).expect("Ultra should serialize"); + let serialized_persistent = + to_string(&ReasoningEffort::Persistent).expect("Persistent should serialize"); assert_eq!( ( "high".parse(), "max".parse(), "ultra".parse(), + "persistent".parse(), "future".parse(), deserialized, serialized, serialized_max, serialized_ultra, + serialized_persistent, custom.to_string(), ), ( Ok(ReasoningEffort::High), Ok(ReasoningEffort::Max), Ok(ReasoningEffort::Ultra), + Ok(ReasoningEffort::Persistent), Ok(custom.clone()), custom, r#""future""#.to_string(), r#""max""#.to_string(), r#""ultra""#.to_string(), + r#""persistent""#.to_string(), "future".to_string(), ) ); diff --git a/codex-rs/tui/src/chatwidget/model_popups.rs b/codex-rs/tui/src/chatwidget/model_popups.rs index c8ace98397..0fb20b5e7c 100644 --- a/codex-rs/tui/src/chatwidget/model_popups.rs +++ b/codex-rs/tui/src/chatwidget/model_popups.rs @@ -646,6 +646,7 @@ impl ChatWidget { ReasoningEffortConfig::XHigh => "Extra high".to_string(), ReasoningEffortConfig::Max => "Max".to_string(), ReasoningEffortConfig::Ultra => "Ultra".to_string(), + ReasoningEffortConfig::Persistent => "Persistent".to_string(), ReasoningEffortConfig::Custom(value) => value.clone(), } } diff --git a/codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__tests__model_reasoning_selection_popup.snap b/codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__tests__model_reasoning_selection_popup.snap index 1b91548f11..cd6e70b342 100644 --- a/codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__tests__model_reasoning_selection_popup.snap +++ b/codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__tests__model_reasoning_selection_popup.snap @@ -8,6 +8,7 @@ expression: popup 2. Medium (default) Balances speed and reasoning depth for everyday tasks › 3. High (current) Greater reasoning depth for complex problems 4. Extra high Extra high reasoning depth for complex problems - 5. More reasoning… Max and Ultra consume usage limits faster + 5. Persistent Continue working until put to sleep + 6. More reasoning… Max and Ultra consume usage limits faster Press enter to confirm or esc to go back diff --git a/codex-rs/tui/src/chatwidget/tests/popups_and_settings.rs b/codex-rs/tui/src/chatwidget/tests/popups_and_settings.rs index c8fe64d966..17a52f8c07 100644 --- a/codex-rs/tui/src/chatwidget/tests/popups_and_settings.rs +++ b/codex-rs/tui/src/chatwidget/tests/popups_and_settings.rs @@ -3352,6 +3352,12 @@ async fn model_reasoning_selection_popup_snapshot() { effort: ReasoningEffortConfig::Ultra, description: "Ultra reasoning".to_string(), }); + preset + .supported_reasoning_efforts + .push(ReasoningEffortPreset { + effort: ReasoningEffortConfig::Persistent, + description: "Continue working until put to sleep".to_string(), + }); chat.open_reasoning_popup(preset); let popup = render_bottom_popup(&chat, /*width*/ 80); diff --git a/sdk/typescript/src/threadOptions.ts b/sdk/typescript/src/threadOptions.ts index 6d59851200..13cf0c5248 100644 --- a/sdk/typescript/src/threadOptions.ts +++ b/sdk/typescript/src/threadOptions.ts @@ -9,7 +9,8 @@ export type ModelReasoningEffort = | "high" | "xhigh" | "max" - | "ultra"; + | "ultra" + | "persistent"; export type WebSearchMode = "disabled" | "cached" | "live"; diff --git a/sdk/typescript/tests/run.test.ts b/sdk/typescript/tests/run.test.ts index 5802133f49..9729c597b7 100644 --- a/sdk/typescript/tests/run.test.ts +++ b/sdk/typescript/tests/run.test.ts @@ -229,36 +229,39 @@ describe("Codex", () => { } }); - it("passes modelReasoningEffort to exec", async () => { - const { url, close } = await startResponsesTestProxy({ - statusCode: 200, - responseBodies: [ - sse( - responseStarted("response_1"), - assistantMessage("Reasoning effort applied", "item_1"), - responseCompleted("response_1"), - ), - ], - }); - - const { args: spawnArgs, restore } = codexExecSpy(); - const { client, cleanup } = createMockClient(url); - - try { - const thread = client.startThread({ - modelReasoningEffort: "high", + it.each(["high", "persistent"] as const)( + "passes %s modelReasoningEffort to exec", + async (effort) => { + const { url, close } = await startResponsesTestProxy({ + statusCode: 200, + responseBodies: [ + sse( + responseStarted("response_1"), + assistantMessage("Reasoning effort applied", "item_1"), + responseCompleted("response_1"), + ), + ], }); - await thread.run("apply reasoning effort"); - const commandArgs = spawnArgs[0]; - expect(commandArgs).toBeDefined(); - expectPair(commandArgs, ["--config", 'model_reasoning_effort="high"']); - } finally { - cleanup(); - restore(); - await close(); - } - }); + const { args: spawnArgs, restore } = codexExecSpy(); + const { client, cleanup } = createMockClient(url); + + try { + const thread = client.startThread({ + modelReasoningEffort: effort, + }); + await thread.run("apply reasoning effort"); + + const commandArgs = spawnArgs[0]; + expect(commandArgs).toBeDefined(); + expectPair(commandArgs, ["--config", `model_reasoning_effort="${effort}"`]); + } finally { + cleanup(); + restore(); + await close(); + } + }, + ); it("passes networkAccessEnabled to exec", async () => { const { url, close } = await startResponsesTestProxy({