diff --git a/codex-rs/cli/tests/daemon_startup.rs b/codex-rs/cli/tests/daemon_startup.rs index 18e5ecf631..db178d0b23 100644 --- a/codex-rs/cli/tests/daemon_startup.rs +++ b/codex-rs/cli/tests/daemon_startup.rs @@ -3,6 +3,8 @@ use anyhow::Context as _; use anyhow::Result; use anyhow::ensure; +use codex_protocol::config_types::WebSearchMode; +use pretty_assertions::assert_eq; use std::collections::VecDeque; use std::fs; use std::process::Command; @@ -197,6 +199,21 @@ async fn daemon_startup(command: &str) -> Result<()> { "# project settings\n", )?; } + let model = if command == "discovered" { + Some( + app_test_support::create_mock_responses_server_sequence_unchecked(vec![ + app_test_support::create_final_assistant_message_sse_response( + "Before restart reply", + )?, + app_test_support::create_final_assistant_message_sse_response( + "After restart reply", + )?, + ]) + .await, + ) + } else { + None + }; fs::write( home.path().join("config.toml"), format!( @@ -211,15 +228,26 @@ async fn daemon_startup(command: &str) -> Result<()> { if command == "bedrock-running" { // Let the first thread use the model from the selected provider's catalog. "tui.status_line=[\"provider\"]" + } else if command == "discovered" { + "model = \"test-model\"" } else { "model = \"gpt-5.6-terra\"" }, - if command == "discovered" { - "tui.status_line=[\"model\",\"thread-id\",\"thread-name\"]\nfeatures.daemon_auto_start=false" + if let Some(model) = &model { + format!( + r#"tui.status_line = ["model", "thread-id", "thread-name"] +features.daemon_auto_start = false +otel.metrics_exporter = "none" +check_for_update_on_startup = false +web_search = "disabled" +model_provider = "local" +model_providers.local = {{ name = "local", base_url = "{}/v1", wire_api = "responses" }}"#, + model.uri(), + ) } else if bedrock_onboarding { - "features.gcp_setup_wizard=false\nfeatures.gateway_setup_wizard=false" + "features.gcp_setup_wizard=false\nfeatures.gateway_setup_wizard=false".to_string() } else { - "" + String::new() }, serde_json::to_string(&workspace_path)?, if trust_restart { @@ -330,6 +358,7 @@ async fn daemon_startup(command: &str) -> Result<()> { None }; let expected = if command == "start" { + args.push("--search".into()); // The draft header is visible before the session's command composer is ready. steps.push_back(("GPT-5.6-Terra", b"/status\r")); "Server:Localbackgroundserver" @@ -358,18 +387,22 @@ async fn daemon_startup(command: &str) -> Result<()> { steps.push_back(("Notasksyet", b"n")); "entercontinue·escback" } else if command == "discovered" { - args.extend(["--disable".into(), "daemon_auto_start".into()]); - // Empty drafts need not survive a daemon restart. Renaming materializes the - // thread; wait for the confirmed footer name, not the echoed command. - steps.push_back(("GPT-5.6-Terra", b"/rename daemon-restart-test\r")); - steps.push_back(("·daemon-restart-test", b"/daemon\r")); + args.extend(["--search".into(), "--disable".into(), "daemon_auto_start".into()]); + // A confirmed name prevents automatic title requests from consuming the + // mock responses reserved for the two user turns. + steps.push_back(("test-model", b"/rename daemon-restart-test\r")); + steps.push_back(("·daemon-restart-test", b"first prompt\r")); + steps.push_back(("Beforerestartreply", b"/daemon\r")); steps.push_back(("Restartbackgroundserver", b"2")); steps.push_back(("Restartbackgroundserver?", b"2\r")); // Offline editing preserves text but suppresses Enter. Observe the command // popup in a complete connected frame before submitting the retained draft. - steps.push_back(("GPT-5.6-Terra", b"/status")); + steps.push_back(("test-model", b"/status")); steps.push_back(("/statusshowcurrentsessionconfigurationandtokenusage", b"\r")); - "Server:Localbackgroundserver" + // Close the status dialog and wait for the conversation footer to return. + steps.push_back(("Server:Localbackgroundserver", b"\x1b")); + steps.push_back(("·daemon-restart-test", b"second prompt\r")); + "Afterrestartreply" } else if elevated_launch || command == "restrictive-job" && elevated { if let Some(action) = command.strip_prefix("elevated-") { args.push(action.into()); @@ -534,7 +567,7 @@ async fn daemon_startup(command: &str) -> Result<()> { if command == "discovered" { if *ready == "Restartbackgroundserver?" { existing_daemon = Some(fs::read(&pid_file)?); - } else if *ready == "GPT-5.6-Terra" { + } else if *ready == "test-model" { // The header renders before thread/start completes. Wait for the // live status line to confirm there is a session to reconnect. if !screen.screen().contents().split_whitespace().any(|part| { @@ -681,6 +714,47 @@ async fn daemon_startup(command: &str) -> Result<()> { let (session, result) = result?; session.terminate(); result??; + if let Some(model) = &model { + let requests = core_test_support::responses::received_responses_requests(model).await; + let [before, after] = requests.as_slice() else { + anyhow::bail!( + "expected one model request before and after restart, got {}", + requests.len() + ); + }; + assert!( + after + .message_input_texts("user") + .iter() + .any(|text| text == "first prompt") + ); + // A host policy can restrict --search to cached or disabled. + let mode = codex_core::config::ConfigBuilder::default() + .codex_home(home.path().to_path_buf()) + .cli_overrides(vec![("web_search".into(), "live".into())]) + .build() + .await? + .web_search_mode + .value(); + let expected = match mode { + WebSearchMode::Disabled => None, + WebSearchMode::Cached => Some(serde_json::Value::Bool(false)), + WebSearchMode::Live | WebSearchMode::Indexed => Some(serde_json::Value::Bool(true)), + }; + for (phase, request) in [("before restart", before), ("after restart", after)] { + let body = request.body_json(); + let search = body["tools"] + .as_array() + .context("request tools")? + .iter() + .find(|tool| tool["type"] == "web_search"); + assert_eq!( + search.map(|tool| &tool["external_web_access"]), + expected.as_ref(), + "{phase}" + ); + } + } ensure!( stopped.status.success(), "{}", diff --git a/codex-rs/cli/tests/worktree.rs b/codex-rs/cli/tests/worktree.rs index 0eba7bfd92..94c5450aee 100644 --- a/codex-rs/cli/tests/worktree.rs +++ b/codex-rs/cli/tests/worktree.rs @@ -1,6 +1,7 @@ //! Exercises interactive destination policy, startup and fork, and ownership before the first turn. use anyhow::Context as _; +use codex_protocol::config_types::WebSearchMode; use pretty_assertions::assert_eq; use serde_json::Value; use std::collections::HashMap; @@ -196,6 +197,7 @@ features.daemon_auto_start = {} features.mcp_oauth_refresh_coordination = true model_provider = "local" model = "test-model" +web_search = "disabled" sandbox_mode = "workspace-write" windows.sandbox = "unelevated" tui.disable_paste_burst = true @@ -310,6 +312,14 @@ trust_level = "trusted" "-c".into(), "suppress_unstable_features_warning=true".into(), ]; + // The CLI and daemon both honor machine-wide search restrictions. + let requested_search = codex_core::config::ConfigBuilder::default() + .codex_home(home.clone()) + .cli_overrides(vec![("web_search".into(), "live".into())]) + .build() + .await? + .web_search_mode + .value(); let mut owner = None; let mut previous: Vec = Vec::new(); let prompt = "describe checkout"; @@ -390,6 +400,10 @@ trust_level = "trusted" .mount(&server) .await; let mut args = worktree_args.clone(); + let live_search = previous.is_empty() || explicit_cd; + if live_search { + args.push("--search".into()); + } if backend == "daemon" && previous.is_empty() { args.extend(["-c".into(), "features.auth_elicitation=true".into()]); } @@ -819,6 +833,29 @@ trust_level = "trusted" ); } assert_eq!(body["model"], "destination-model"); + let search = body["tools"] + .as_array() + .context("request tools")? + .iter() + .find(|tool| tool["type"] == "web_search"); + let mode = if live_search { + requested_search + } else { + WebSearchMode::Disabled + }; + let expected = match mode { + WebSearchMode::Disabled => None, + WebSearchMode::Cached => Some((Value::Bool(false), false)), + WebSearchMode::Live => Some((Value::Bool(true), false)), + WebSearchMode::Indexed => Some((Value::Bool(true), true)), + }; + assert_eq!( + search.map(|tool| ( + tool["external_web_access"].clone(), + tool["indexed_web_access"] == true + )), + expected, + ); assert!(context.contains("managed cloud instructions"), "{context}"); if previous.is_empty() { // A legacy summary still says launcher A, but persisted turns use checkout B. diff --git a/codex-rs/tui/src/app/reconnect.rs b/codex-rs/tui/src/app/reconnect.rs index fe3bc83971..7719de12b5 100644 --- a/codex-rs/tui/src/app/reconnect.rs +++ b/codex-rs/tui/src/app/reconnect.rs @@ -88,7 +88,7 @@ pub(super) async fn reconnect( &local_settings, config.clone(), thread_id, - ResumeModelSettings::PreserveExistingThread, + ResumeModelSettings::Reconnect, ) .await { diff --git a/codex-rs/tui/src/app/session_lifecycle.rs b/codex-rs/tui/src/app/session_lifecycle.rs index 8e0602f1c0..1d8d2116a5 100644 --- a/codex-rs/tui/src/app/session_lifecycle.rs +++ b/codex-rs/tui/src/app/session_lifecycle.rs @@ -419,14 +419,20 @@ impl App { } use crate::app_server_session::ResumeModelSettings; - let side = self.side_threads.get(&thread_id); - let resume_settings = if side.is_some_and(|side| side.storage == SideChatStorage::Attached) + let saved_side = self + .side_threads + .get(&thread_id) + .is_some_and(|side| side.storage == SideChatStorage::Attached); + let resume_settings = if saved_side && self .agent_navigation .get(&thread_id) .is_some_and(|entry| entry.is_closed) { ResumeModelSettings::PreserveSideConversation + } else if saved_side || self.primary_thread_id == Some(thread_id) { + // Offscreen conversations reattach on selection after a daemon restart. + ResumeModelSettings::Reconnect } else { ResumeModelSettings::PreserveExistingThread }; diff --git a/codex-rs/tui/src/app/tests/side_chat_policy_tests.rs b/codex-rs/tui/src/app/tests/side_chat_policy_tests.rs index 44bcd959f5..e0c89e940a 100644 --- a/codex-rs/tui/src/app/tests/side_chat_policy_tests.rs +++ b/codex-rs/tui/src/app/tests/side_chat_policy_tests.rs @@ -332,6 +332,61 @@ async fn fork_saved_chat( Ok(fork.thread.session.thread_id) } +#[tokio::test] +async fn reopening_a_saved_side_chat_restores_search_only_on_cold_resume() -> Result<()> { + use super::session_lifecycle_requests::recorded_params; + use super::session_lifecycle_requests::start_recording_app_server; + use crate::app_server_session::ResumeModelSettings; + + let mut app = make_test_app().await; + app.cli_kv_overrides + .push(("web_search".into(), "live".into())); + let tui = crate::tui::test_support::make_test_tui()?; + let (mut original, model, parent) = Box::pin(saved_chat_parent(&mut app, &tui)).await?; + let child = fork_saved_chat(&app, &mut original, parent).await?; + ask(&mut original, &model, child, "Side question").await?; + original.shutdown().await?; + + let (mut server, requests, proxy) = Box::pin(start_recording_app_server( + &app.config, + /*blocked_thread_list*/ None, + /*failed_thread_name*/ None, + )) + .await?; + // Reopen the saved side chat, then return to the offscreen main conversation. + Box::pin(server.resume_thread( + &app.local_settings, + app.config.clone(), + child, + ResumeModelSettings::PreserveSideConversation, + )) + .await?; + app.primary_thread_id = Some(parent); + app.side_threads.insert( + child, + SideThreadState { + storage: SideChatStorage::Attached, + ..SideThreadState::new(parent) + }, + ); + for thread_id in [parent, child] { + app.ensure_thread_channel(thread_id).mark_replay_only(); + assert!(Box::pin(app.attach_live_thread_for_selection(&mut server, thread_id)).await?); + } + let resumes = recorded_params(&requests, "thread/resume"); + let live = serde_json::json!({"web_search": "live"}); + assert_eq!( + resumes + .iter() + .map(|params| params["config"].clone()) + .collect::>(), + vec![live.clone(), live, serde_json::Value::Null], + ); + server.shutdown().await?; + proxy.await??; + Ok(()) +} + #[tokio::test] async fn pending_scrollback_switch_keeps_pasted_input_in_the_source_draft() -> Result<()> { let (mut app, mut events, mut ops) = make_test_app_with_channels().await; diff --git a/codex-rs/tui/src/app_server_session.rs b/codex-rs/tui/src/app_server_session.rs index c2b57c61e1..b7dd9a7f20 100644 --- a/codex-rs/tui/src/app_server_session.rs +++ b/codex-rs/tui/src/app_server_session.rs @@ -523,6 +523,8 @@ pub(crate) enum ResumeModelSettings { RestoreFromThread, /// Rejoins a loaded thread without changing any of its existing settings. PreserveExistingThread, + /// Reconnect a conversation, restoring launch search on a cold daemon. + Reconnect, /// Restore the saved settings and reapply the side-chat instructions on cold resume. PreserveSideConversation, } @@ -3050,6 +3052,7 @@ fn thread_resume_params_from_config( || matches!( model_settings, ResumeModelSettings::PreserveExistingThread + | ResumeModelSettings::Reconnect | ResumeModelSettings::PreserveSideConversation ) { @@ -3086,6 +3089,7 @@ fn thread_resume_params_from_config( ), ResumeModelSettings::RestoreFromThread | ResumeModelSettings::PreserveExistingThread + | ResumeModelSettings::Reconnect | ResumeModelSettings::PreserveSideConversation => (None, None, None), }; launch.effort = effort; @@ -4974,6 +4978,22 @@ mod tests { let overrides = LaunchOverrides::for_session(&config, ThreadParamsMode::Remote) .into_request() .unwrap_or_default(); + let resume = thread_resume_params_from_config( + LaunchOverrides::for_session(&config, ThreadParamsMode::Embedded), + config, + ThreadId::new(), + ThreadParamsMode::Embedded, + /*remote_cwd_override*/ None, + ResumeModelSettings::RestoreFromThread, + crate::resume_permissions::ResumePermissions::CURRENT_CONFIG, + ); + assert_eq!( + resume + .config + .as_ref() + .and_then(|config| config.get("web_search")), + overrides.get("web_search"), + ); assert_eq!( ( ["model_reasoning_summary", "model_verbosity", "web_search"] diff --git a/codex-rs/tui/src/app_server_session/rollout_history.rs b/codex-rs/tui/src/app_server_session/rollout_history.rs index 482f309114..fdc9edc242 100644 --- a/codex-rs/tui/src/app_server_session/rollout_history.rs +++ b/codex-rs/tui/src/app_server_session/rollout_history.rs @@ -21,9 +21,11 @@ use codex_app_server_protocol::SortDirection; use codex_app_server_protocol::ThreadHistoryMode; use codex_app_server_protocol::ThreadResumeParams; use codex_app_server_protocol::ThreadResumeResponse; +use codex_app_server_protocol::ThreadStatus; use codex_app_server_protocol::ThreadTurnsListParams; use codex_app_server_protocol::ThreadTurnsListResponse; use codex_app_server_protocol::TurnItemsView; +use codex_config::ConfigLayerSource; use codex_protocol::ThreadId; use codex_utils_absolute_path::AbsolutePathBuf; use codex_utils_path_uri::LegacyAppPathString; @@ -241,6 +243,7 @@ impl AppServerSession { ResumeModelSettings::Launch { model, .. } => model.as_deref(), ResumeModelSettings::RestoreFromThread | ResumeModelSettings::PreserveExistingThread + | ResumeModelSettings::Reconnect | ResumeModelSettings::PreserveSideConversation => None, }; // A catalog default or Fast opt-out here would suppress restoration of the saved tier. @@ -285,12 +288,34 @@ impl AppServerSession { let metadata = Box::pin(self.thread_read(thread_id, /*include_turns*/ false)) .await .ok(); + // Launch search is absent from the saved thread. Restore it on cold + // reconnects and side-chat reopens, leaving other attachments untouched. + if matches!( + model_settings, + ResumeModelSettings::Reconnect | ResumeModelSettings::PreserveSideConversation + ) && self.thread_params_mode() == ThreadParamsMode::Embedded + && !self.uses_embedded_app_server() + && metadata + .as_ref() + .is_some_and(|thread| thread.status == ThreadStatus::NotLoaded) + && let Some(layer) = config + .config_layer_stack + .layers_high_to_low() + .find(|layer| layer.config.get("web_search").is_some()) + && layer.name == ConfigLayerSource::SessionFlags + && layer.config["web_search"].as_str() == Some("live") + { + params + .config + .get_or_insert_default() + .insert("web_search".into(), "live".into()); + } // A fresh load applies managed rules. A loaded thread's sandbox summary // cannot confirm its proxy rules or filesystem restrictions. if permission_overrides.confirm_preset - && metadata.as_ref().is_none_or(|thread| { - thread.status != codex_app_server_protocol::ThreadStatus::NotLoaded - }) + && metadata + .as_ref() + .is_none_or(|thread| thread.status != ThreadStatus::NotLoaded) { if config.managed_network_requirements_enabled() { color_eyre::eyre::bail!( diff --git a/codex-rs/tui/src/daemon_startup.rs b/codex-rs/tui/src/daemon_startup.rs index a319362dcd..b04ff1412f 100644 --- a/codex-rs/tui/src/daemon_startup.rs +++ b/codex-rs/tui/src/daemon_startup.rs @@ -15,6 +15,8 @@ use codex_app_server_protocol::RequestId; use std::collections::BTreeMap; pub(super) const FAILURE_HINT: &str = "To work without the background server, rerun the same command with --no-daemon (including resume or fork and its arguments)."; +pub(super) const CONFIG_OVERRIDE_EXCLUSION: &str = + "a command-line configuration override (-c, --enable, or --disable)"; pub(super) const WSL_DRVFS_EXCLUSION: &str = "a Windows-mounted WSL CODEX_HOME (DrvFS/9p)"; pub(super) const GATEWAY_SIGN_IN_EXCLUSION: &str = "custom provider or gateway sign-in"; @@ -112,7 +114,7 @@ pub(super) fn config_exclusion( } }) { - Some("command-line configuration overrides (-c, --enable, --disable, or --search)") + Some(CONFIG_OVERRIDE_EXCLUSION) } else if !loader_overrides_are_default(loader_overrides) { Some("custom configuration loader") } else if strict_config { diff --git a/codex-rs/tui/src/daemon_startup_tests.rs b/codex-rs/tui/src/daemon_startup_tests.rs index 1ef9dab808..cfbaa19e0e 100644 --- a/codex-rs/tui/src/daemon_startup_tests.rs +++ b/codex-rs/tui/src/daemon_startup_tests.rs @@ -379,6 +379,8 @@ fn daemon_eligibility_preserves_launch_options_and_explains_exclusions() { for (args, expected) in [ ("--no-daemon", Some("--no-daemon")), ("--worktree", None), + ("--search", None), + ("--search --no-daemon", Some("--no-daemon")), ("--worktree --no-daemon", Some("--no-daemon")), ("--oss", Some("--oss")), ("--profile test", Some("--profile")), @@ -404,7 +406,7 @@ fn daemon_eligibility_preserves_launch_options_and_explains_exclusions() { expected ); } - let cli = Cli::parse_from(["codex"]); + let cli = Cli::parse_from(["codex", "--search"]); let overrides = [("web_search".into(), toml::Value::String("live".into()))]; let loader = LoaderOverrides { ignore_user_config: true, @@ -416,7 +418,7 @@ fn daemon_eligibility_preserves_launch_options_and_explains_exclusions() { LoaderOverrides::default(), false, None, - "command-line configuration overrides (-c, --enable, --disable, or --search)", + daemon_startup::CONFIG_OVERRIDE_EXCLUSION, ), (&[][..], loader, false, None, "custom configuration loader"), ( @@ -451,6 +453,10 @@ fn daemon_exclusion_warning_snapshot() { "Running without the shared background server: {} requires embedded mode.", daemon_startup::WSL_DRVFS_EXCLUSION ), + format!( + "Running without the shared background server: {} requires embedded mode.", + daemon_startup::CONFIG_OVERRIDE_EXCLUSION + ), format!( "Running without the shared background server: {} requires embedded mode.", daemon_startup::GATEWAY_SIGN_IN_EXCLUSION diff --git a/codex-rs/tui/src/snapshots/codex_tui__tests__daemon_startup_tests__daemon_exclusion_warning.snap b/codex-rs/tui/src/snapshots/codex_tui__tests__daemon_startup_tests__daemon_exclusion_warning.snap index 7c691b56ac..ad1a7c00c2 100644 --- a/codex-rs/tui/src/snapshots/codex_tui__tests__daemon_startup_tests__daemon_exclusion_warning.snap +++ b/codex-rs/tui/src/snapshots/codex_tui__tests__daemon_startup_tests__daemon_exclusion_warning.snap @@ -6,5 +6,7 @@ expression: text embedded mode. ⚠ Running without the shared background server: a Windows-mounted WSL CODEX_HOME (DrvFS/9p) requires embedded mode. +⚠ Running without the shared background server: a command-line configuration + override (-c, --enable, or --disable) requires embedded mode. ⚠ Running without the shared background server: custom provider or gateway sign- in requires embedded mode. diff --git a/codex-rs/tui/src/startup_draft_tests.rs b/codex-rs/tui/src/startup_draft_tests.rs index 11a36f705f..bb19dc3ef9 100644 --- a/codex-rs/tui/src/startup_draft_tests.rs +++ b/codex-rs/tui/src/startup_draft_tests.rs @@ -902,20 +902,16 @@ async fn startup_draft_waits_for_onboarding_before_accepting_input() { codex_home.path().join("system.toml"), ) .expect("resolve missing system configuration"); - let search_override = [("web_search".to_string(), toml::Value::String("live".into()))]; - pump.initial_screen = - if crate::startup_preflight::has_only_search_config_override(&search_override) - && crate::startup_preflight::should_delay_startup_composer_for_first_login( - codex_home.path(), - Ok(system_config_path), - || Ok(false), - |name| (name == "CODEX_HOME").then(|| codex_home.path().as_os_str().to_os_string()), - ) - { - StartupDraftInitialScreen::Onboarding - } else { - StartupDraftInitialScreen::Composer - }; + pump.initial_screen = if crate::startup_preflight::should_delay_startup_composer_for_first_login( + codex_home.path(), + Ok(system_config_path), + || Ok(false), + |name| (name == "CODEX_HOME").then(|| codex_home.path().as_os_str().to_os_string()), + ) { + StartupDraftInitialScreen::Onboarding + } else { + StartupDraftInitialScreen::Composer + }; let mut tui = crate::tui::test_support::make_test_tui().expect("create test terminal"); pump.redraw_if_visible(&mut tui) .expect("keep the composer hidden until onboarding finishes"); diff --git a/codex-rs/tui/src/startup_orchestration.rs b/codex-rs/tui/src/startup_orchestration.rs index 3a03f893df..2999110b82 100644 --- a/codex-rs/tui/src/startup_orchestration.rs +++ b/codex-rs/tui/src/startup_orchestration.rs @@ -80,21 +80,7 @@ pub(super) async fn run_main_inner( cli.shared .take_auto_review_config_overrides(&mut cli.config_overrides); - // Map the legacy --search flag to the canonical web_search mode. - let overrides_before_search = cli.config_overrides.raw_overrides.len(); - if cli.web_search { - cli.config_overrides - .raw_overrides - .push("web_search=\"live\"".to_string()); - } - - // When using `--oss`, let the bootstrapper pick the model (defaulting to - // gpt-oss:20b) and ensure it is present locally. Also, force the built‑in - let raw_overrides = cli.config_overrides.raw_overrides.clone(); - // `oss` model provider. - let overrides_cli = codex_utils_cli::CliConfigOverrides { raw_overrides }; - let mut cli_kv_overrides = match overrides_cli.parse_overrides() { - // Parse `-c` overrides from the CLI. + let mut cli_kv_overrides = match cli.config_overrides.parse_overrides() { Ok(v) => v, #[allow(clippy::print_stderr)] Err(e) => { @@ -160,6 +146,27 @@ pub(super) async fn run_main_inner( codex_app_server_client::EmbeddedNetworkPolicy::load(&launch_loader_overrides).await; let workload_identity_selected = is_workload_identity_selected(); + let mut daemon_exclusion = daemon_startup::exclusion( + &cli, + &cli_kv_overrides, + &launch_loader_overrides, + workload_identity_selected, + std::env::var_os(codex_exec_server::CODEX_EXEC_SERVER_URL_ENV_VAR).as_deref(), + ); + // Preserve first-login preflight for search even when --no-daemon or an + // explicit executor rules out a shared server. + let embedded_search_preflight = cli.web_search + && cli_kv_overrides.is_empty() + && !workload_identity_selected + && loader_overrides_are_default(&launch_loader_overrides) + && !strict_config + && !cli.bypass_hook_trust; + // Like --model, --search applies to the thread without configuring the daemon. + // Append it after explicit -c overrides to preserve its precedence. + if cli.web_search { + cli_kv_overrides.push(("web_search".into(), "live".into())); + } + if !std::io::stdin().is_terminal() || !std::io::stdout().is_terminal() { let validation_target = app_server_target_for_launch( cli.cloud.enabled, @@ -232,34 +239,13 @@ pub(super) async fn run_main_inner( .await; } - let mut daemon_exclusion = daemon_startup::exclusion( - &cli, - &cli_kv_overrides, - &launch_loader_overrides, - workload_identity_selected, - std::env::var_os(codex_exec_server::CODEX_EXEC_SERVER_URL_ENV_VAR).as_deref(), - ); let reuse_implicit_local_daemon = daemon_exclusion.is_none(); - let search_forces_embedded = cli.web_search - && daemon_startup::config_exclusion( - &cli_kv_overrides[..overrides_before_search], - &launch_loader_overrides, - strict_config, - cli.bypass_hook_trust, - ) - .is_none(); - let search_only_config_override = !workload_identity_selected - && cli.web_search - && startup_preflight::has_only_search_config_override(&cli_kv_overrides) - && loader_overrides_are_default(&launch_loader_overrides) - && !strict_config - && !cli.bypass_hook_trust; let initial_screen = if cli.resume_picker || cli.fork_picker || cli.agents_overview { startup_draft::StartupDraftInitialScreen::SessionPicker } else if !cli.cloud.enabled && !cli.oss && explicit_remote_endpoint.is_none() - && (reuse_implicit_local_daemon || search_only_config_override) + && (reuse_implicit_local_daemon || embedded_search_preflight) && launch_loader_overrides.packaged_defaults_path.is_none() && startup_preflight::should_delay_startup_composer_for_first_login( &codex_home, @@ -825,15 +811,7 @@ pub(super) async fn run_main_inner( Some("workload identity") => "workload_identity", Some("executor selection (CODEX_EXEC_SERVER_URL)") => "exec_server_url", Some("custom configuration loader") => "custom_config_loader", - Some( - "command-line configuration overrides (-c, --enable, --disable, or --search)", - ) => { - if search_forces_embedded { - "search" - } else { - "config_override" - } - } + Some(daemon_startup::CONFIG_OVERRIDE_EXCLUSION) => "config_override", Some("GCP sign-in") => "gcp_sign_in", Some(daemon_startup::GATEWAY_SIGN_IN_EXCLUSION) => "gateway_sign_in", Some(daemon_startup::WSL_DRVFS_EXCLUSION) => "wsl_drvfs", diff --git a/codex-rs/tui/src/startup_preflight.rs b/codex-rs/tui/src/startup_preflight.rs index cd284e401b..03b793ae1e 100644 --- a/codex-rs/tui/src/startup_preflight.rs +++ b/codex-rs/tui/src/startup_preflight.rs @@ -10,14 +10,6 @@ use codex_protocol::shell_environment::OPENAI_FEDERATION_RULE_ID_ENV_VAR; use codex_protocol::shell_environment::OPENAI_IDENTITY_TOKEN_FILE_ENV_VAR; use codex_utils_absolute_path::AbsolutePathBuf; -/// Recognize the single configuration override synthesized by the legacy `--search` flag. -pub(super) fn has_only_search_config_override(cli_kv_overrides: &[(String, toml::Value)]) -> bool { - matches!( - cli_kv_overrides, - [(key, toml::Value::String(value))] if key == "web_search" && value == "live" - ) -} - /// Hide the composer when the default file-backed account cannot already be authenticated. pub(super) fn should_delay_startup_composer_for_first_login( codex_home: &Path, diff --git a/codex-rs/tui/src/startup_preflight_tests.rs b/codex-rs/tui/src/startup_preflight_tests.rs index 726277cd1f..bce6108faa 100644 --- a/codex-rs/tui/src/startup_preflight_tests.rs +++ b/codex-rs/tui/src/startup_preflight_tests.rs @@ -1,7 +1,6 @@ use codex_utils_absolute_path::AbsolutePathBuf; use tempfile::TempDir; -use super::has_only_search_config_override; use super::should_delay_startup_composer_for_first_login; #[test] @@ -228,34 +227,6 @@ fn startup_keeps_composer_for_workload_identity_markers() -> std::io::Result<()> Ok(()) } -#[test] -fn startup_only_accepts_the_synthetic_search_override() { - let search = ( - "web_search".to_string(), - toml::Value::String("live".to_string()), - ); - - assert!(!has_only_search_config_override(&[])); - assert!(has_only_search_config_override(std::slice::from_ref( - &search - ))); - assert!(!has_only_search_config_override(&[( - "web_search".to_string(), - toml::Value::String("cached".to_string()), - )])); - assert!(!has_only_search_config_override(&[( - "model_provider".to_string(), - toml::Value::String("live".to_string()), - )])); - assert!(!has_only_search_config_override(&[ - search, - ( - "model".to_string(), - toml::Value::String("custom".to_string()) - ), - ])); -} - #[test] fn startup_keeps_composer_when_system_configuration_is_possible() -> std::io::Result<()> { let temporary_directory = TempDir::new()?;