Use automatic reasoning summaries by default in the TUI (#62904)

## Why

The TUI left the reasoning summary unset on turn submission, so OpenAI
requests could use `concise` even when the user had chosen no summary
setting. Embedded WebSocket prewarming and the first turn need to use
the same summary setting to reuse the warmup response.

## What changed

- Send the configured `model_reasoning_summary` with TUI turns, defaulting
  to `auto` for OpenAI providers. Use the same fallback when prewarming
  through the in-process app server.
- Read reasoning summary settings and custom provider definitions from
  the app server's effective config while honoring explicit launch
  settings. When resuming a remote session, use its working directory
  for the config lookup unless a remote directory override is set.

## Testing

Cover summary defaults and explicit settings in Responses requests,
and verify that the first embedded WebSocket turn uses `auto` and
reuses the warmup response.

GitOrigin-RevId: 1a2edfa44abdd031691a0d421eba077b0796ebe1
This commit is contained in:
Eric Traut
2026-11-21 05:55:23 +00:00
committed by copyberry
parent 58952e0c39
commit 553c7f8ea6
8 changed files with 261 additions and 35 deletions
+31 -4
View File
@@ -22,14 +22,40 @@ pub(crate) fn has_launch_setting(
.is_some_and(|layer| {
matches!(
layer.name,
ConfigLayerSource::User {
profile: Some(_),
..
}
ConfigLayerSource::SessionFlags
| ConfigLayerSource::User {
profile: Some(_),
..
}
)
})
}
pub(super) fn overlay_reasoning_summary(
config: &mut Config,
defaults: &codex_app_server_protocol::Config,
cli_kv_overrides: &[(String, TomlValue)],
) {
if !has_launch_setting(config, cli_kv_overrides, "model_reasoning_summary") {
config.model_reasoning_summary = defaults.model_reasoning_summary;
}
if let Some(providers) = defaults
.additional
.get("model_providers")
.and_then(serde_json::Value::as_object)
{
let built_in =
codex_model_provider_info::built_in_model_providers(/*openai_base_url*/ None);
for (id, definition) in providers {
if !built_in.contains_key(id)
&& let Ok(provider) = serde_json::from_value(definition.clone())
{
config.model_providers.insert(id.clone(), provider);
}
}
}
}
pub(super) fn overlay_new_session_defaults(
config: &mut Config,
defaults: &codex_app_server_protocol::Config,
@@ -42,6 +68,7 @@ pub(super) fn overlay_new_session_defaults(
if !has_launch_setting(config, cli_kv_overrides, "model_reasoning_effort") {
config.model_reasoning_effort = defaults.model_reasoning_effort.clone();
}
overlay_reasoning_summary(config, defaults, cli_kv_overrides);
if harness_overrides.service_tier.is_none()
&& !has_launch_setting(config, cli_kv_overrides, "service_tier")
{
+18 -4
View File
@@ -56,12 +56,15 @@ pub(super) fn startup_config_cwd<'a>(
config: &'a Config,
app_server: &'a AppServerSession,
app_server_target: &AppServerTarget,
resumed_cwd: Option<&'a Path>,
) -> &'a Path {
match app_server_target {
AppServerTarget::Embedded | AppServerTarget::LocalDaemon { .. } => config.cwd.as_path(),
AppServerTarget::Remote { .. } | AppServerTarget::Cloud => {
app_server.remote_cwd_override().unwrap_or(Path::new("."))
}
AppServerTarget::Remote { .. } => app_server
.remote_cwd_override()
.or(resumed_cwd)
.unwrap_or(Path::new(".")),
AppServerTarget::Cloud => app_server.remote_cwd_override().unwrap_or(Path::new(".")),
}
}
@@ -395,7 +398,11 @@ impl App {
config.model_reasoning_effort = None;
}
}
let cwd = startup_config_cwd(&config, &app_server, &app_server_target)
let resumed_cwd = match &session_selection {
SessionSelection::Resume(target) => target.cwd.as_deref(),
_ => None,
};
let cwd = startup_config_cwd(&config, &app_server, &app_server_target, resumed_cwd)
.display()
.to_string();
let startup_config = match startup_draft
@@ -463,6 +470,13 @@ impl App {
}
},
};
if let Some(defaults) = startup_config.as_ref() {
super::new_session::overlay_reasoning_summary(
&mut config,
&defaults.config,
&cli_kv_overrides,
);
}
launch_choices.apply_projectless_approval_policy(
startup_defaults.approval_policy,
bootstrap.allowed_approval_policies.as_deref(),
@@ -465,7 +465,7 @@ requires_openai_auth = false
}
let defaults = crate::config_update::read_effective_config_with_layers(
&server.request_handle(),
startup_config_cwd(&config, &server, &target)
startup_config_cwd(&config, &server, &target, /*resumed_cwd*/ None)
.display()
.to_string(),
)
@@ -636,7 +636,7 @@ async fn fresh_startup_reads_destination_and_cleared_model_uses_catalog() -> Res
)?;
std::fs::write(
server_home.path().join("config.toml"),
"model_reasoning_effort = \"high\"\nsandbox_mode = \"read-only\"\nmodel_reasoning_summary = \"concise\"\n",
"model_reasoning_effort = \"high\"\nsandbox_mode = \"read-only\"\nmodel_reasoning_summary = \"concise\"\n[model_providers.server-only]\nname = \"OpenAI\"\nwire_api = \"responses\"\n",
)?;
let mut config = ConfigBuilder::default()
.codex_home(client_home.path().to_path_buf())
@@ -680,6 +680,16 @@ async fn fresh_startup_reads_destination_and_cleared_model_uses_catalog() -> Res
} else {
AppServerTarget::Embedded
};
if remote {
assert_eq!(
startup_config_cwd(&config, &server, &target, Some(destination.path())),
if override_cwd {
launch_cwd.path()
} else {
destination.path()
},
);
}
let bootstrap = server.bootstrap(&config).await?;
assert_eq!(
bootstrap.default_model.as_deref(),
@@ -687,7 +697,7 @@ async fn fresh_startup_reads_destination_and_cleared_model_uses_catalog() -> Res
);
let defaults = crate::config_update::read_effective_config_with_layers(
&server.request_handle(),
startup_config_cwd(&config, &server, &target)
startup_config_cwd(&config, &server, &target, /*resumed_cwd*/ None)
.display()
.to_string(),
)
@@ -702,6 +712,11 @@ async fn fresh_startup_reads_destination_and_cleared_model_uses_catalog() -> Res
&EnvironmentManager::default_for_tests(),
);
assert!(!defaults_read.prompt_windows_sandbox);
assert_eq!(
config.model_reasoning_summary,
Some(codex_protocol::config_types::ReasoningSummary::Concise)
);
assert!(config.model_providers["server-only"].is_openai());
assert_eq!(config.model, None);
let selected_model =
startup_model(&config, &bootstrap, /*server_defaults_read*/ true)?;
@@ -321,6 +321,11 @@ impl App {
.await
{
Ok(Some(defaults)) => {
super::new_session::overlay_reasoning_summary(
&mut config,
&defaults.config,
&self.cli_kv_overrides,
);
crate::projectless::apply_defaults(
&mut config,
&self.harness_overrides,
+32 -1
View File
@@ -1199,6 +1199,7 @@ impl AppServerSession {
remote_cwd_override.or(self.remote_cwd_override.as_deref()),
session_start_source,
);
apply_prewarm_reasoning_summary(&mut params, &session_config, &self.request_handle);
if self.thread_params_mode.settings_owner() == ThreadSettingsOwner::Client {
params.model_provider = self
.model_provider_override
@@ -2434,6 +2435,7 @@ pub(crate) async fn start_thread_with_request_handle(
launch_choices.approvals_reviewer,
&launch_choices.approval_policy,
);
apply_prewarm_reasoning_summary(&mut params, &config, &request_handle);
if thread_params_mode.settings_owner() == ThreadSettingsOwner::Client {
thread_tool_transport
.check_namespace(&request_handle, &config.cwd)
@@ -2850,6 +2852,34 @@ pub(crate) fn thread_start_params_from_config(
)
}
pub(crate) fn reasoning_summary_from_config(
config: &Config,
) -> Option<codex_protocol::config_types::ReasoningSummary> {
config.model_reasoning_summary.or_else(|| {
config
.model_providers
.get(&config.model_provider_id)
.is_some_and(codex_model_provider_info::ModelProviderInfo::is_openai)
.then_some(codex_protocol::config_types::ReasoningSummary::Auto)
})
}
fn apply_prewarm_reasoning_summary(
params: &mut ThreadStartParams,
config: &Config,
request_handle: &AppServerRequestHandle,
) {
if matches!(request_handle, AppServerRequestHandle::InProcess(_))
&& config.model_reasoning_summary.is_none()
&& let Some(summary) = reasoning_summary_from_config(config)
{
params.config.get_or_insert_default().insert(
"model_reasoning_summary".to_string(),
serde_json::json!(summary),
);
}
}
fn thread_start_params_with_reviewer(
config: &Config,
thread_params_mode: ThreadParamsMode,
@@ -2871,6 +2901,7 @@ fn thread_start_params_with_reviewer(
)
})
.flatten();
let overrides = config_request_overrides_from_config(config, thread_params_mode);
ThreadStartParams {
model: config.model.clone(),
model_provider: provider_selection::explicit_provider(config),
@@ -2892,7 +2923,7 @@ fn thread_start_params_with_reviewer(
},
sandbox,
permissions,
config: config_request_overrides_from_config(config, thread_params_mode),
config: overrides,
ephemeral: Some(config.ephemeral),
history_mode: (!config.ephemeral).then_some(ThreadHistoryMode::Paginated),
session_start_source,
@@ -3,46 +3,40 @@
use super::*;
use crate::legacy_core::config::ConfigBuilder;
use codex_app_server_client::AppServerEvent;
use codex_app_server_protocol::JSONRPCMessage;
use codex_app_server_protocol::ServerNotification;
use codex_protocol::config_types::ReasoningSummary;
use core_test_support::responses;
use futures::SinkExt;
use futures::StreamExt;
use pretty_assertions::assert_eq;
use serde_json::json;
use tokio_tungstenite::tungstenite::Message;
#[tokio::test]
async fn reasoning_defaults_reach_responses() -> Result<()> {
let concurrent = json!({"reasoning_summary_delivery": "sequential_cutoff"});
for (settings, summary, stream_options, mode) in [
(
"",
json!("concise"),
json!({"reasoning_summary_delivery": "sequential_cutoff"}),
json!("auto"),
concurrent.clone(),
ThreadParamsMode::Embedded,
),
(
"[features]\nconcurrent_reasoning_summaries = false",
json!("concise"),
json!("auto"),
json!(null),
ThreadParamsMode::Embedded,
),
(
"[features]\nconcurrent_reasoning_summaries = true",
json!("concise"),
json!({"reasoning_summary_delivery": "sequential_cutoff"}),
ThreadParamsMode::Embedded,
),
(
"model_reasoning_summary = 'detailed'",
json!("detailed"),
json!({"reasoning_summary_delivery": "sequential_cutoff"}),
concurrent.clone(),
ThreadParamsMode::Embedded,
),
(
"model_reasoning_summary = 'detailed'\n[features]\nconcurrent_reasoning_summaries = true",
json!("detailed"),
json!({"reasoning_summary_delivery": "sequential_cutoff"}),
ThreadParamsMode::Embedded,
),
(
"model_reasoning_summary = 'none'\n[features]\nconcurrent_reasoning_summaries = true",
"model_reasoning_summary = 'none'",
json!(null),
json!(null),
ThreadParamsMode::Embedded,
@@ -50,7 +44,7 @@ async fn reasoning_defaults_reach_responses() -> Result<()> {
(
"model_reasoning_summary = 'detailed'\nmodel_verbosity = 'high'\nweb_search = 'live'",
json!("detailed"),
json!({"reasoning_summary_delivery": "sequential_cutoff"}),
concurrent,
ThreadParamsMode::Remote,
),
] {
@@ -148,7 +142,11 @@ stream_max_retries = 0
&config.workspace_roots,
started.session.model.clone(),
/*effort*/ None,
/*summary*/ None,
Some(
server_config
.model_reasoning_summary
.unwrap_or(ReasoningSummary::Auto),
),
/*service_tier*/ None,
/*collaboration_mode*/ None,
/*output_schema*/ None,
@@ -209,3 +207,133 @@ stream_max_retries = 0
}
Ok(())
}
#[tokio::test]
async fn reasoning_summary_default_preserves_websocket_prewarm() -> Result<()> {
let websocket = responses::start_websocket_server(vec![vec![
vec![
responses::ev_response_created("warmup"),
responses::ev_completed("warmup"),
],
vec![
responses::ev_response_created("first"),
responses::ev_completed("first"),
],
]])
.await;
let home = tempfile::tempdir()?;
let base_url = websocket.uri();
std::fs::write(
home.path().join("config.toml"),
format!(
r#"
model = "gpt-5.5"
model_provider = "reasoning-test"
[model_providers.reasoning-test]
name = "OpenAI"
base_url = "{base_url}/v1"
wire_api = "responses"
supports_websockets = true
"#
),
)?;
let config = ConfigBuilder::default()
.codex_home(home.path().to_path_buf())
.build()
.await?;
let template = thread_start_params_from_config(
&config,
ThreadParamsMode::Embedded,
/*remote_cwd_override*/ None,
/*session_start_source*/ None,
);
assert_eq!(
template
.config
.as_ref()
.and_then(|config| config.get("model_reasoning_summary")),
None,
);
let listener = tokio::net::TcpListener::bind("127.0.0.1:0").await?;
let endpoint = crate::resolve_remote_addr(&format!("ws://{}", listener.local_addr()?))?;
let daemon = tokio::spawn(async move {
let (stream, _) = listener.accept().await?;
let mut socket = tokio_tungstenite::accept_async(stream).await?;
while let Some(Ok(Message::Text(text))) = socket.next().await {
let JSONRPCMessage::Request(request) = serde_json::from_str(&text)? else {
continue;
};
let mut reply = match request.method.as_str() {
"initialize" => json!({"result": {"userAgent": "daemon-test/1.0"}}),
"thread/start" => json!({"error": {"code": -32603, "message": "recorded"}}),
method => panic!("unexpected request: {method}"),
};
reply["id"] = json!(request.id);
socket.send(Message::Text(reply.to_string().into())).await?;
if request.method == "thread/start" {
return Ok::<_, color_eyre::Report>(request.params);
}
}
color_eyre::eyre::bail!("missing thread/start");
});
let mut daemon_session = AppServerSession::new(
crate::backend_id::BackendId::new(),
crate::connect_remote_app_server(endpoint).await?,
ThreadParamsMode::Embedded,
);
assert!(daemon_session.start_thread(&config).await.is_err());
let daemon_params = daemon.await??.expect("thread/start params");
assert_eq!(
daemon_params["config"]["model_reasoning_summary"],
json!(null)
);
daemon_session.shutdown().await?;
let mut app_server = crate::start_embedded_app_server_for_picker(&config).await?;
let started = app_server.start_thread(&config).await?;
let warmup = tokio::time::timeout(
std::time::Duration::from_secs(/*secs*/ 30),
websocket.wait_for_request(/*connection_index*/ 0, /*request_index*/ 0),
)
.await?;
assert_eq!(warmup.body_json()["reasoning"]["summary"], "auto");
app_server
.turn_start(
started.session.thread_id,
"user",
"tui-user-message".to_string(),
vec![UserInput::Text {
text: "hello".to_string(),
text_elements: Vec::new(),
}],
config.cwd.to_path_buf(),
/*approval_policy*/ None,
/*approvals_reviewer*/ None,
TurnPermissionsOverride::Preserve,
&config.workspace_roots,
started.session.model,
/*effort*/ None,
reasoning_summary_from_config(&config),
/*service_tier*/ None,
/*collaboration_mode*/ None,
/*output_schema*/ None,
/*cyber_access_program*/ None,
/*cloud_selection*/ None,
)
.await?;
let first = tokio::time::timeout(
std::time::Duration::from_secs(/*secs*/ 30),
websocket.wait_for_request(/*connection_index*/ 0, /*request_index*/ 1),
)
.await?;
let first = first.body_json();
assert_eq!(
(
first["reasoning"]["summary"].clone(),
first["previous_response_id"].clone()
),
(json!("auto"), json!("warmup")),
);
app_server.shutdown().await?;
websocket.shutdown().await;
Ok(())
}
@@ -517,7 +517,7 @@ impl ChatWidget {
active_permission_profile,
effective_mode.model().to_string(),
effective_mode.reasoning_effort(),
/*summary*/ None,
crate::app_server_session::reasoning_summary_from_config(&self.config),
service_tier,
/*final_output_json_schema*/ None,
collaboration_mode,
@@ -670,7 +670,10 @@ async fn submission_preserves_text_elements_and_local_images() {
chat.handle_key_event(KeyEvent::new(KeyCode::Enter, KeyModifiers::NONE));
let items = match next_submit_op(&mut op_rx) {
Op::UserTurn { items, .. } => items,
Op::UserTurn { items, summary, .. } => {
assert_eq!(summary, None);
items
}
other => panic!("expected Op::UserTurn, got {other:?}"),
};
assert_eq!(items.len(), 2);
@@ -964,7 +967,7 @@ async fn enter_with_only_remote_images_submits_user_turn() {
fork_parent_title: None,
thread_name: None,
model: "test-model".to_string(),
model_provider_id: "test-provider".to_string(),
model_provider_id: "openai".to_string(),
service_tier: None,
approval_policy: AskForApproval::Never,
approvals_reviewer: ApprovalsReviewer::User,
@@ -1001,7 +1004,10 @@ async fn enter_with_only_remote_images_submits_user_turn() {
detail: None,
}]
);
assert_eq!(summary, None);
assert_eq!(
summary,
Some(codex_protocol::config_types::ReasoningSummary::Auto)
);
assert!(chat.remote_image_urls().is_empty());
let mut user_cell = None;