mirror of
https://github.com/openai/codex.git
synced 2026-11-29 00:00:54 +00:00
Support persistent reasoning effort (#40799)
## What changed - Add `persistent` to the reasoning-effort protocol and TypeScript SDK types. - Show model-advertised persistent reasoning in the TUI as “Persistent”. - Preserve `persistent` in local configuration while sending the Responses API's `disabled` wire value. ## Testing - Cover parsing and serialization, request translation, remote model requests, the TUI reasoning selector, and TypeScript CLI argument forwarding. GitOrigin-RevId: 22fc2fba1975db345c12d555ec12803d8dc0abca
This commit is contained in:
@@ -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,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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()),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -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(())
|
||||
|
||||
@@ -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(),
|
||||
)
|
||||
);
|
||||
|
||||
@@ -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(),
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -9,7 +9,8 @@ export type ModelReasoningEffort =
|
||||
| "high"
|
||||
| "xhigh"
|
||||
| "max"
|
||||
| "ultra";
|
||||
| "ultra"
|
||||
| "persistent";
|
||||
|
||||
export type WebSearchMode = "disabled" | "cached" | "live";
|
||||
|
||||
|
||||
@@ -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({
|
||||
|
||||
Reference in New Issue
Block a user