mirror of
https://github.com/openai/codex.git
synced 2026-11-21 22:50:37 +00:00
Add an opt-in indexed web search default (#62894)
## What changed Add `features.web_search_indexed_default` to let restricted turns use `indexed` search in place of the implicit `cached` default when the provider and managed requirements allow it. Full-access turns still prefer `live` search when allowed, and an explicit `indexed` selection retains its existing precedence. Forward the flag through the TUI and keep the default implicit when launch overrides disable legacy search flags. ## Testing Cover mode selection across permission profiles, explicit settings, and managed requirements. Verify that the first model request advertises indexed search and that permission changes take effect on the next turn. GitOrigin-RevId: 08a6279c447c517c50b9e6a544ecdf681b81bf50
This commit is contained in:
@@ -34,6 +34,7 @@ use pretty_assertions::assert_eq;
|
||||
use serde_json::Value;
|
||||
use serde_json::json;
|
||||
use tempfile::TempDir;
|
||||
use test_case::test_case;
|
||||
use tokio::time::timeout;
|
||||
use wiremock::Mock;
|
||||
use wiremock::MockServer;
|
||||
@@ -84,8 +85,29 @@ enum WebSearchProvider {
|
||||
CustomResponses,
|
||||
}
|
||||
|
||||
#[test_case(
|
||||
r#"web_search = "cached""#, /*indexed_default*/ false, "",
|
||||
[json!(false), json!(false), json!(true)]; "explicit_cached"
|
||||
)]
|
||||
#[test_case(
|
||||
"", /*indexed_default*/ true, "",
|
||||
[json!("indexed"), json!("indexed"), json!(true)]; "implicit_indexed"
|
||||
)]
|
||||
#[test_case(
|
||||
r#"web_search = "indexed""#, /*indexed_default*/ true, "",
|
||||
[json!("indexed"), json!("indexed"), json!("indexed")]; "explicit_indexed"
|
||||
)]
|
||||
#[test_case(
|
||||
"", /*indexed_default*/ true, r#"allowed_web_search_modes = ["cached", "indexed"]"#,
|
||||
[json!("indexed"), json!("indexed"), json!("indexed")]; "implicit_indexed_without_live"
|
||||
)]
|
||||
#[tokio::test]
|
||||
async fn standalone_web_search_uses_new_permissions_only_on_the_next_turn() -> Result<()> {
|
||||
async fn standalone_web_search_uses_new_permissions_only_on_the_next_turn(
|
||||
root_config: &str,
|
||||
indexed_default: bool,
|
||||
requirements: &str,
|
||||
expected: [Value; 3],
|
||||
) -> Result<()> {
|
||||
let server = responses::start_mock_server().await;
|
||||
let search_path = "/v1/alpha/search";
|
||||
mount_search_response(&server, search_path, /*expected_calls*/ 3).await;
|
||||
@@ -130,13 +152,19 @@ async fn standalone_web_search_uses_new_permissions_only_on_the_next_turn() -> R
|
||||
.await;
|
||||
|
||||
let codex_home = TempDir::new()?;
|
||||
MockResponsesConfig::new(&server.uri())
|
||||
.with_root_config(r#"web_search = "cached""#)
|
||||
let mut config = MockResponsesConfig::new(&server.uri())
|
||||
.with_root_config(root_config)
|
||||
.enable_feature(Feature::StandaloneWebSearch)
|
||||
.enable_feature(Feature::DefaultModeRequestUserInput)
|
||||
.with_provider_config("supports_websockets = false")
|
||||
.with_provider_config("supports_standalone_web_search = true")
|
||||
.write(codex_home.path())?;
|
||||
.with_provider_config("supports_standalone_web_search = true");
|
||||
if indexed_default {
|
||||
config = config.enable_feature(Feature::WebSearchIndexedDefault);
|
||||
}
|
||||
config.write(codex_home.path())?;
|
||||
if !requirements.is_empty() {
|
||||
std::fs::write(codex_home.path().join("requirements.toml"), requirements)?;
|
||||
}
|
||||
let mut app = TestAppServer::builder()
|
||||
.with_codex_home(codex_home.path())
|
||||
.build_initialized_with_timeout(DEFAULT_READ_TIMEOUT)
|
||||
@@ -217,7 +245,7 @@ async fn standalone_web_search_uses_new_permissions_only_on_the_next_turn() -> R
|
||||
observed.push(body["settings"]["external_web_access"].clone());
|
||||
}
|
||||
}
|
||||
assert_eq!(observed, vec![json!(false), json!(false), json!(true)]);
|
||||
assert_eq!(observed, expected);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -225,6 +253,7 @@ async fn assert_standalone_web_search_round_trips_output(
|
||||
provider: WebSearchProvider,
|
||||
literature_search: bool,
|
||||
) -> Result<()> {
|
||||
let indexed_by_default = matches!(provider, WebSearchProvider::ChatGpt);
|
||||
let call_id = "web-run-1";
|
||||
let (model, query, commands) = if literature_search {
|
||||
(
|
||||
@@ -338,12 +367,17 @@ async fn assert_standalone_web_search_round_trips_output(
|
||||
let mut mcp = TestAppServer::builder()
|
||||
.with_codex_home(codex_home.path())
|
||||
.with_env_overrides(&env_overrides)
|
||||
.without_managed_config()
|
||||
.build_initialized_with_timeout(DEFAULT_READ_TIMEOUT)
|
||||
.await?;
|
||||
|
||||
let thread_req = mcp
|
||||
.send_thread_start_request_with_auto_env(ThreadStartParams {
|
||||
service_name: Some("chatgpt_cca".to_string()),
|
||||
config: Some(HashMap::from([(
|
||||
"features.web_search_indexed_default".to_string(),
|
||||
json!(indexed_by_default),
|
||||
)])),
|
||||
..Default::default()
|
||||
})
|
||||
.await?;
|
||||
@@ -446,6 +480,14 @@ async fn assert_standalone_web_search_round_trips_output(
|
||||
search_body["settings"]["allowed_callers"],
|
||||
json!(["direct"])
|
||||
);
|
||||
assert_eq!(
|
||||
search_body["settings"]["external_web_access"],
|
||||
if indexed_by_default {
|
||||
json!("indexed")
|
||||
} else {
|
||||
json!(false)
|
||||
}
|
||||
);
|
||||
assert_eq!(
|
||||
search_body["input"]
|
||||
.as_array()
|
||||
@@ -528,6 +570,7 @@ async fn assert_standalone_web_search_round_trips_output(
|
||||
let mut reloaded_mcp = TestAppServer::builder()
|
||||
.with_codex_home(codex_home.path())
|
||||
.with_env_overrides(&env_overrides)
|
||||
.without_managed_config()
|
||||
.build_initialized_with_timeout(DEFAULT_READ_TIMEOUT)
|
||||
.await?;
|
||||
let read_req = reloaded_mcp
|
||||
|
||||
@@ -1528,6 +1528,9 @@
|
||||
"web_search_cached": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"web_search_indexed_default": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"web_search_request": {
|
||||
"type": "boolean"
|
||||
},
|
||||
@@ -8903,6 +8906,9 @@
|
||||
"web_search_cached": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"web_search_indexed_default": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"web_search_request": {
|
||||
"type": "boolean"
|
||||
},
|
||||
|
||||
@@ -7065,11 +7065,18 @@ async fn feedback_enabled_defaults_to_true() -> std::io::Result<()> {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn web_search_mode_defaults_to_none_if_unset() {
|
||||
fn web_search_mode_defaults_to_cached_if_unset() {
|
||||
let cfg = ConfigToml::default();
|
||||
let features = Features::with_defaults();
|
||||
|
||||
assert_eq!(resolve_web_search_mode(&cfg, &features), None);
|
||||
assert_eq!(
|
||||
resolve_web_search_mode(
|
||||
&cfg,
|
||||
&features,
|
||||
&Constrained::allow_any(WebSearchMode::Cached),
|
||||
),
|
||||
WebSearchMode::Cached,
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -7082,8 +7089,12 @@ fn web_search_mode_prefers_config_over_legacy_flags() {
|
||||
features.enable(Feature::WebSearchCached);
|
||||
|
||||
assert_eq!(
|
||||
resolve_web_search_mode(&cfg, &features),
|
||||
Some(WebSearchMode::Live)
|
||||
resolve_web_search_mode(
|
||||
&cfg,
|
||||
&features,
|
||||
&Constrained::allow_any(WebSearchMode::Cached),
|
||||
),
|
||||
WebSearchMode::Live
|
||||
);
|
||||
}
|
||||
|
||||
@@ -7097,8 +7108,12 @@ fn web_search_mode_disabled_overrides_legacy_request() {
|
||||
features.enable(Feature::WebSearchRequest);
|
||||
|
||||
assert_eq!(
|
||||
resolve_web_search_mode(&cfg, &features),
|
||||
Some(WebSearchMode::Disabled)
|
||||
resolve_web_search_mode(
|
||||
&cfg,
|
||||
&features,
|
||||
&Constrained::allow_any(WebSearchMode::Cached),
|
||||
),
|
||||
WebSearchMode::Disabled
|
||||
);
|
||||
}
|
||||
|
||||
@@ -7107,6 +7122,7 @@ fn web_search_mode_for_turn_preserves_indexed_for_disabled_permissions() {
|
||||
let web_search_mode = Constrained::allow_any(WebSearchMode::Indexed);
|
||||
let mode = resolve_web_search_mode_for_turn(
|
||||
&web_search_mode,
|
||||
/*web_search_mode_was_explicit*/ true,
|
||||
&PermissionProfile::Disabled,
|
||||
ProviderCapabilities::default(),
|
||||
);
|
||||
@@ -7120,6 +7136,7 @@ fn web_search_mode_for_turn_uses_preference_for_read_only() {
|
||||
let permission_profile = PermissionProfile::read_only();
|
||||
let mode = resolve_web_search_mode_for_turn(
|
||||
&web_search_mode,
|
||||
/*web_search_mode_was_explicit*/ true,
|
||||
&permission_profile,
|
||||
ProviderCapabilities::default(),
|
||||
);
|
||||
@@ -7132,6 +7149,7 @@ fn web_search_mode_for_turn_prefers_live_for_disabled_permissions() {
|
||||
let web_search_mode = Constrained::allow_any(WebSearchMode::Cached);
|
||||
let mode = resolve_web_search_mode_for_turn(
|
||||
&web_search_mode,
|
||||
/*web_search_mode_was_explicit*/ true,
|
||||
&PermissionProfile::Disabled,
|
||||
ProviderCapabilities::default(),
|
||||
);
|
||||
@@ -7145,6 +7163,7 @@ fn web_search_mode_for_turn_falls_back_when_provider_disallows_external_web_acce
|
||||
let web_search_mode = Constrained::allow_any(preferred);
|
||||
let mode = resolve_web_search_mode_for_turn(
|
||||
&web_search_mode,
|
||||
/*web_search_mode_was_explicit*/ true,
|
||||
&PermissionProfile::Disabled,
|
||||
ProviderCapabilities {
|
||||
external_web_access: false,
|
||||
@@ -7179,6 +7198,7 @@ fn web_search_mode_for_turn_disables_when_external_access_and_cached_are_disallo
|
||||
})?;
|
||||
let mode = resolve_web_search_mode_for_turn(
|
||||
&web_search_mode,
|
||||
/*web_search_mode_was_explicit*/ true,
|
||||
&PermissionProfile::Disabled,
|
||||
ProviderCapabilities {
|
||||
external_web_access: false,
|
||||
@@ -7196,6 +7216,7 @@ fn web_search_mode_for_turn_respects_disabled_for_disabled_permissions() {
|
||||
let web_search_mode = Constrained::allow_any(WebSearchMode::Disabled);
|
||||
let mode = resolve_web_search_mode_for_turn(
|
||||
&web_search_mode,
|
||||
/*web_search_mode_was_explicit*/ true,
|
||||
&PermissionProfile::Disabled,
|
||||
ProviderCapabilities::default(),
|
||||
);
|
||||
@@ -7220,6 +7241,7 @@ fn web_search_mode_for_turn_falls_back_when_live_is_disallowed() -> anyhow::Resu
|
||||
})?;
|
||||
let mode = resolve_web_search_mode_for_turn(
|
||||
&web_search_mode,
|
||||
/*web_search_mode_was_explicit*/ true,
|
||||
&PermissionProfile::Disabled,
|
||||
ProviderCapabilities::default(),
|
||||
);
|
||||
@@ -7249,6 +7271,7 @@ fn web_search_mode_for_turn_does_not_implicitly_select_indexed() -> anyhow::Resu
|
||||
})?;
|
||||
let mode = resolve_web_search_mode_for_turn(
|
||||
&web_search_mode,
|
||||
/*web_search_mode_was_explicit*/ true,
|
||||
&PermissionProfile::Disabled,
|
||||
ProviderCapabilities::default(),
|
||||
);
|
||||
@@ -12305,6 +12328,7 @@ async fn requirements_web_search_mode_overrides_danger_full_access_default() ->
|
||||
assert_eq!(
|
||||
resolve_web_search_mode_for_turn(
|
||||
&config.web_search_mode,
|
||||
config.web_search_mode_was_explicit,
|
||||
&config.permissions.effective_permission_profile(),
|
||||
ProviderCapabilities::default(),
|
||||
),
|
||||
|
||||
@@ -2904,18 +2904,30 @@ pub fn resolve_oss_provider(
|
||||
}
|
||||
}
|
||||
|
||||
/// Resolve the web search mode from explicit config and feature flags.
|
||||
fn resolve_web_search_mode(config_toml: &ConfigToml, features: &Features) -> Option<WebSearchMode> {
|
||||
/// Resolve the configured preference, or select an allowed implicit default.
|
||||
fn resolve_web_search_mode(
|
||||
config_toml: &ConfigToml,
|
||||
features: &Features,
|
||||
constrained_default: &Constrained<WebSearchMode>,
|
||||
) -> WebSearchMode {
|
||||
if let Some(mode) = config_toml.web_search {
|
||||
return Some(mode);
|
||||
return mode;
|
||||
}
|
||||
if features.enabled(Feature::WebSearchCached) {
|
||||
return Some(WebSearchMode::Cached);
|
||||
return WebSearchMode::Cached;
|
||||
}
|
||||
if features.enabled(Feature::WebSearchRequest) {
|
||||
return Some(WebSearchMode::Live);
|
||||
return WebSearchMode::Live;
|
||||
}
|
||||
let default_mode = constrained_default.value();
|
||||
if default_mode == WebSearchMode::Cached
|
||||
&& features.enabled(Feature::WebSearchIndexedDefault)
|
||||
&& constrained_default.can_set(&WebSearchMode::Indexed).is_ok()
|
||||
{
|
||||
WebSearchMode::Indexed
|
||||
} else {
|
||||
default_mode
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
fn resolve_web_search_config(config_toml: &ConfigToml) -> Option<WebSearchConfig> {
|
||||
@@ -3385,6 +3397,7 @@ pub fn resolve_bootstrap_http_client_factory(
|
||||
|
||||
pub(crate) fn resolve_web_search_mode_for_turn(
|
||||
web_search_mode: &Constrained<WebSearchMode>,
|
||||
web_search_mode_was_explicit: bool,
|
||||
permission_profile: &PermissionProfile,
|
||||
provider_capabilities: ProviderCapabilities,
|
||||
) -> WebSearchMode {
|
||||
@@ -3400,30 +3413,28 @@ pub(crate) fn resolve_web_search_mode_for_turn(
|
||||
provider_supports_mode && web_search_mode.can_set(&mode).is_ok()
|
||||
};
|
||||
|
||||
if matches!(permission_profile, PermissionProfile::Disabled)
|
||||
&& !matches!(preferred, WebSearchMode::Disabled | WebSearchMode::Indexed)
|
||||
{
|
||||
for mode in [
|
||||
WebSearchMode::Live,
|
||||
WebSearchMode::Cached,
|
||||
WebSearchMode::Disabled,
|
||||
] {
|
||||
if is_allowed(mode) {
|
||||
return mode;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if is_allowed(preferred) {
|
||||
return preferred;
|
||||
}
|
||||
for mode in [
|
||||
WebSearchMode::Cached,
|
||||
WebSearchMode::Live,
|
||||
WebSearchMode::Disabled,
|
||||
] {
|
||||
if is_allowed(mode) {
|
||||
return mode;
|
||||
let full_access_promotes_to_live = matches!(permission_profile, PermissionProfile::Disabled)
|
||||
&& match preferred {
|
||||
WebSearchMode::Cached | WebSearchMode::Live => true,
|
||||
WebSearchMode::Indexed => {
|
||||
!web_search_mode_was_explicit
|
||||
&& web_search_mode.can_set(&WebSearchMode::Cached).is_ok()
|
||||
}
|
||||
WebSearchMode::Disabled => false,
|
||||
};
|
||||
if full_access_promotes_to_live && is_allowed(WebSearchMode::Live) {
|
||||
return WebSearchMode::Live;
|
||||
}
|
||||
if is_allowed(preferred) {
|
||||
return preferred;
|
||||
}
|
||||
for mode in [
|
||||
WebSearchMode::Cached,
|
||||
WebSearchMode::Live,
|
||||
WebSearchMode::Disabled,
|
||||
] {
|
||||
if is_allowed(mode) {
|
||||
return mode;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4221,8 +4232,7 @@ impl Config {
|
||||
);
|
||||
approvals_reviewer = constrained_approvals_reviewer.value();
|
||||
}
|
||||
let web_search_mode =
|
||||
resolve_web_search_mode(&cfg, &features).unwrap_or(WebSearchMode::Cached);
|
||||
let web_search_mode = resolve_web_search_mode(&cfg, &features, &constrained_web_search_mode);
|
||||
let web_search_config = resolve_web_search_config(&cfg);
|
||||
let experimental_request_user_input_enabled =
|
||||
resolve_experimental_request_user_input_enabled(&cfg);
|
||||
|
||||
@@ -269,7 +269,7 @@ impl Session {
|
||||
.refresh(&next_config.features);
|
||||
}
|
||||
let previous_config = notify_contributors
|
||||
.then(|| self.build_effective_session_config(&state.session_configuration));
|
||||
.then(|| Self::build_effective_session_config(&state.session_configuration));
|
||||
if config.mcp_enterprise_managed_auth.is_none() {
|
||||
config.config_layer_stack.mcp_ema_cancellation().cancel();
|
||||
}
|
||||
@@ -293,7 +293,7 @@ impl Session {
|
||||
RuntimeConfigRefresh::UserFiles => McpRefreshReason::UserConfigFilesReloaded,
|
||||
});
|
||||
let new_config = notify_contributors
|
||||
.then(|| self.build_effective_session_config(&state.session_configuration));
|
||||
.then(|| Self::build_effective_session_config(&state.session_configuration));
|
||||
(previous_config, new_config)
|
||||
};
|
||||
if config
|
||||
|
||||
@@ -84,7 +84,7 @@ impl Session {
|
||||
)
|
||||
};
|
||||
let config =
|
||||
self.build_per_turn_config(&session_configuration, environments.local_selection());
|
||||
Self::build_per_turn_config(&session_configuration, environments.local_selection());
|
||||
let local_process_cwd = config.cwd.to_path_buf();
|
||||
|
||||
McpDesiredState {
|
||||
@@ -106,7 +106,7 @@ impl Session {
|
||||
mcp_projection: McpRuntimeProjection,
|
||||
resolved_environments: &TurnEnvironmentSnapshot,
|
||||
) -> anyhow::Result<()> {
|
||||
let config = self.build_per_turn_config(
|
||||
let config = Self::build_per_turn_config(
|
||||
session_configuration,
|
||||
resolved_environments.local_selection(),
|
||||
);
|
||||
|
||||
@@ -2253,7 +2253,7 @@ impl Session {
|
||||
)
|
||||
});
|
||||
let previous_config = notify_config_contributors
|
||||
.then(|| self.build_effective_session_config(&state.session_configuration));
|
||||
.then(|| Self::build_effective_session_config(&state.session_configuration));
|
||||
let current = &state.session_configuration;
|
||||
let refresh_network_proxy = current.permission_profile()
|
||||
!= updated.permission_profile()
|
||||
@@ -2306,7 +2306,7 @@ impl Session {
|
||||
None
|
||||
};
|
||||
let new_config = notify_config_contributors
|
||||
.then(|| self.build_effective_session_config(&state.session_configuration));
|
||||
.then(|| Self::build_effective_session_config(&state.session_configuration));
|
||||
let commit = SessionSettingsCommit {
|
||||
configuration: state.session_configuration.clone(),
|
||||
snapshot: state
|
||||
@@ -2499,7 +2499,7 @@ impl Session {
|
||||
state.reasoning_effort_pin.clone(),
|
||||
)
|
||||
};
|
||||
let config = self.build_effective_session_config(&configuration);
|
||||
let config = Self::build_effective_session_config(&configuration);
|
||||
if !config.features.enabled(Feature::ReasoningEffortOverride) {
|
||||
let model = configuration
|
||||
.step_settings
|
||||
|
||||
@@ -6830,7 +6830,7 @@ pub(crate) async fn make_session_and_context() -> (Session, TurnContext) {
|
||||
forked_from_ordinal_exclusive: None,
|
||||
next_internal_sub_id: AtomicU64::new(0),
|
||||
};
|
||||
let per_turn_config = session.build_per_turn_config(
|
||||
let per_turn_config = Session::build_per_turn_config(
|
||||
&session_configuration,
|
||||
resolved_turn_environments.local_selection(),
|
||||
);
|
||||
@@ -9195,7 +9195,7 @@ where
|
||||
forked_from_ordinal_exclusive: None,
|
||||
next_internal_sub_id: AtomicU64::new(0),
|
||||
});
|
||||
let per_turn_config = session.build_per_turn_config(
|
||||
let per_turn_config = Session::build_per_turn_config(
|
||||
&session_configuration,
|
||||
resolved_turn_environments.local_selection(),
|
||||
);
|
||||
|
||||
@@ -993,7 +993,6 @@ fn local_time_context() -> (String, String) {
|
||||
impl Session {
|
||||
/// Don't expand the number of mutated arguments on config. We are in the process of getting rid of it.
|
||||
pub(crate) fn build_per_turn_config(
|
||||
&self,
|
||||
session_configuration: &SessionConfiguration,
|
||||
local_environment: Option<&TurnEnvironmentSelection>,
|
||||
) -> Config {
|
||||
@@ -1032,17 +1031,25 @@ impl Session {
|
||||
per_turn_config.approvals_reviewer = session_configuration.step_settings.approvals_reviewer;
|
||||
session_configuration
|
||||
.apply_permission_profile_to_permissions(&mut per_turn_config.permissions);
|
||||
let permission_profile = session_configuration.permission_profile();
|
||||
Self::apply_effective_web_search_mode(session_configuration, &mut per_turn_config);
|
||||
per_turn_config.features = config.features.clone();
|
||||
per_turn_config
|
||||
}
|
||||
|
||||
pub(super) fn apply_effective_web_search_mode(
|
||||
session_configuration: &SessionConfiguration,
|
||||
config: &mut Config,
|
||||
) {
|
||||
let resolved_web_search_mode = resolve_web_search_mode_for_turn(
|
||||
&per_turn_config.web_search_mode,
|
||||
&permission_profile,
|
||||
&config.web_search_mode,
|
||||
config.web_search_mode_was_explicit,
|
||||
session_configuration
|
||||
.permission_profile_state
|
||||
.permission_profile(),
|
||||
session_configuration.provider.capabilities(),
|
||||
);
|
||||
if let Err(err) = per_turn_config
|
||||
.web_search_mode
|
||||
.set(resolved_web_search_mode)
|
||||
{
|
||||
let fallback_value = per_turn_config.web_search_mode.value();
|
||||
if let Err(err) = config.web_search_mode.set(resolved_web_search_mode) {
|
||||
let fallback_value = config.web_search_mode.value();
|
||||
tracing::warn!(
|
||||
error = %err,
|
||||
?resolved_web_search_mode,
|
||||
@@ -1050,15 +1057,12 @@ impl Session {
|
||||
"resolved web_search_mode is disallowed by requirements; keeping constrained value"
|
||||
);
|
||||
}
|
||||
per_turn_config.features = config.features.clone();
|
||||
per_turn_config
|
||||
}
|
||||
|
||||
pub(crate) fn build_effective_session_config(
|
||||
&self,
|
||||
session_configuration: &SessionConfiguration,
|
||||
) -> Config {
|
||||
let mut config = self.build_per_turn_config(
|
||||
let mut config = Self::build_per_turn_config(
|
||||
session_configuration,
|
||||
session_configuration
|
||||
.environments
|
||||
@@ -1238,10 +1242,8 @@ impl Session {
|
||||
let refresh_client = {
|
||||
let state = self.state.lock().await;
|
||||
let configuration = &state.session_configuration;
|
||||
(!crate::guardian::is_basic_session_source(&configuration.session_source)).then(|| {
|
||||
self.build_effective_session_config(configuration)
|
||||
.http_client_factory()
|
||||
})
|
||||
(!crate::guardian::is_basic_session_source(&configuration.session_source))
|
||||
.then(|| Self::build_effective_session_config(configuration).http_client_factory())
|
||||
};
|
||||
// An auth refresh may change allowed settings; finish it before capturing this turn.
|
||||
if let Some(http_client_factory) = refresh_client {
|
||||
@@ -1333,8 +1335,10 @@ impl Session {
|
||||
git_enrichment_policy: GitEnrichmentPolicy,
|
||||
) -> Arc<TurnContext> {
|
||||
let primary_turn_environment = turn_environments.primary();
|
||||
let mut per_turn_config =
|
||||
self.build_per_turn_config(&session_configuration, turn_environments.local_selection());
|
||||
let mut per_turn_config = Self::build_per_turn_config(
|
||||
&session_configuration,
|
||||
turn_environments.local_selection(),
|
||||
);
|
||||
let overridden_direct_only_tool_namespaces =
|
||||
options.direct_only_tool_namespaces.map(|namespaces| {
|
||||
std::mem::replace(
|
||||
|
||||
@@ -3444,6 +3444,7 @@ async fn hosted_web_search_and_standalone_image_generation_follow_runtime_gates(
|
||||
standalone_web_search.assert_visible_lacks(&["web_search"]);
|
||||
|
||||
let bedrock_cached_web_search = probe(|turn| {
|
||||
set_web_search_mode(turn, WebSearchMode::Cached);
|
||||
use_bedrock_provider(turn);
|
||||
update_turn_settings_for_test(turn, |settings| {
|
||||
Arc::make_mut(&mut settings.model_info).web_search_tool_type = WebSearchToolType::Text;
|
||||
|
||||
@@ -516,7 +516,7 @@ async fn disabled_process_host_with_fallback_disabled_attempts_the_host() -> Res
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn code_mode_can_call_standalone_web_search() -> Result<()> {
|
||||
assert_code_mode_standalone_web_search(
|
||||
WebSearchMode::Live,
|
||||
StandaloneWebSearchConfiguration::Explicit(WebSearchMode::Live),
|
||||
serde_json::json!(true),
|
||||
SearchPolicy::Unmanaged,
|
||||
)
|
||||
@@ -526,19 +526,39 @@ async fn code_mode_can_call_standalone_web_search() -> Result<()> {
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn code_mode_can_call_indexed_standalone_web_search() -> Result<()> {
|
||||
assert_code_mode_standalone_web_search(
|
||||
WebSearchMode::Indexed,
|
||||
StandaloneWebSearchConfiguration::Explicit(WebSearchMode::Indexed),
|
||||
serde_json::json!("indexed"),
|
||||
SearchPolicy::Unmanaged,
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn code_mode_defaults_to_live_standalone_web_search_with_full_access() -> Result<()> {
|
||||
assert_code_mode_standalone_web_search(
|
||||
StandaloneWebSearchConfiguration::FullAccessDefault,
|
||||
serde_json::json!(true),
|
||||
SearchPolicy::Unmanaged,
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
enum StandaloneWebSearchConfiguration {
|
||||
Explicit(WebSearchMode),
|
||||
FullAccessDefault,
|
||||
}
|
||||
|
||||
#[test_case(SearchPolicy::DenySearch; "initial_request")]
|
||||
#[test_case(SearchPolicy::DenyRedirect; "redirect")]
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn code_mode_web_search_preserves_managed_policy(policy: SearchPolicy) -> Result<()> {
|
||||
assert_code_mode_standalone_web_search(WebSearchMode::Live, serde_json::json!(true), policy)
|
||||
.await
|
||||
assert_code_mode_standalone_web_search(
|
||||
StandaloneWebSearchConfiguration::Explicit(WebSearchMode::Live),
|
||||
serde_json::json!(true),
|
||||
policy,
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
enum SearchPolicy {
|
||||
@@ -548,7 +568,7 @@ enum SearchPolicy {
|
||||
}
|
||||
|
||||
async fn assert_code_mode_standalone_web_search(
|
||||
web_search_mode: WebSearchMode,
|
||||
web_search_configuration: StandaloneWebSearchConfiguration,
|
||||
expected_external_web_access: Value,
|
||||
policy: SearchPolicy,
|
||||
) -> Result<()> {
|
||||
@@ -615,6 +635,18 @@ text(result);
|
||||
.with_auth(auth)
|
||||
.with_extensions(Arc::new(extension_builder.build()))
|
||||
.with_model("test-gpt-5.1-codex")
|
||||
.with_pre_build_hook(move |codex_home| {
|
||||
let config = match web_search_configuration {
|
||||
StandaloneWebSearchConfiguration::Explicit(mode) => {
|
||||
format!("web_search = \"{mode}\"\n")
|
||||
}
|
||||
StandaloneWebSearchConfiguration::FullAccessDefault => {
|
||||
"sandbox_mode = \"danger-full-access\"\n[features]\nweb_search_indexed_default = true\n".to_string()
|
||||
}
|
||||
};
|
||||
std::fs::write(codex_home.join("config.toml"), config)
|
||||
.expect("write web search configuration");
|
||||
})
|
||||
.with_config(move |config| {
|
||||
if managed {
|
||||
config.application_network_policy = policy;
|
||||
@@ -628,14 +660,18 @@ text(result);
|
||||
.features
|
||||
.enable(Feature::StandaloneWebSearch)
|
||||
.expect("standalone web search should be enabled");
|
||||
config
|
||||
.web_search_mode
|
||||
.set(web_search_mode)
|
||||
.expect("web search mode should be accepted");
|
||||
});
|
||||
let test = builder.build_with_auto_env(&server).await?;
|
||||
|
||||
test.submit_turn("Search the web from code mode").await?;
|
||||
match web_search_configuration {
|
||||
StandaloneWebSearchConfiguration::Explicit(_) => {
|
||||
test.submit_turn("Search the web from code mode").await?;
|
||||
}
|
||||
StandaloneWebSearchConfiguration::FullAccessDefault => {
|
||||
test.submit_text_turn("Search the web from code mode")
|
||||
.await?;
|
||||
}
|
||||
}
|
||||
|
||||
if managed {
|
||||
let output =
|
||||
|
||||
@@ -3514,6 +3514,53 @@ async fn subagent_waits_for_its_inherited_environment_configuration() -> Result<
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn indexed_search_rollout_request_context() -> Result<()> {
|
||||
skip_if_no_network!(Ok(()));
|
||||
|
||||
let server = start_mock_server().await;
|
||||
let mock = mount_sse_sequence(
|
||||
&server,
|
||||
vec![sse(vec![ev_completed("indexed-search-request")])],
|
||||
)
|
||||
.await;
|
||||
let test = test_codex()
|
||||
.with_model("gpt-5.4")
|
||||
.with_config(|config| {
|
||||
config.workspace_roots = vec![config.cwd.clone()];
|
||||
})
|
||||
.with_pre_build_hook(|codex_home| {
|
||||
std::fs::write(
|
||||
codex_home.join("config.toml"),
|
||||
"[features]\nweb_search_indexed_default = true\n",
|
||||
)
|
||||
.expect("write indexed search rollout config");
|
||||
})
|
||||
.build_with_auto_env(&server)
|
||||
.await?;
|
||||
|
||||
test.submit_text_turn("Find the latest release notes.")
|
||||
.await?;
|
||||
let requests = mock.requests();
|
||||
let body = requests[0].body_json();
|
||||
assert_eq!(
|
||||
body["tools"]
|
||||
.as_array()
|
||||
.and_then(|tools| { tools.iter().find(|tool| tool["type"] == "web_search") }),
|
||||
Some(&json!({
|
||||
"type": "web_search",
|
||||
"external_web_access": true,
|
||||
"indexed_web_access": true,
|
||||
})),
|
||||
);
|
||||
insta::assert_snapshot!(context_snapshot::format_request_history_snapshot(
|
||||
"A restricted thread with the indexed-search rollout enabled advertises indexed web search in its first model request.",
|
||||
&requests,
|
||||
&ContextSnapshotOptions::default().include_request_settings(),
|
||||
));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn prediction_fork_inherits_parent_context() -> Result<()> {
|
||||
skip_if_no_network!(Ok(()));
|
||||
|
||||
+75
@@ -0,0 +1,75 @@
|
||||
---
|
||||
source: core/tests/suite/scenarios.rs
|
||||
expression: "context_snapshot::format_request_history_snapshot(\"A restricted thread with the indexed-search rollout enabled advertises indexed web search in its first model request.\",\n&requests, &ContextSnapshotOptions::default().include_request_settings(),)"
|
||||
---
|
||||
Scenario: A restricted thread with the indexed-search rollout enabled advertises indexed web search in its first model request.
|
||||
|
||||
## Window 1
|
||||
Settings:
|
||||
include: ["reasoning.encrypted_content"]
|
||||
model: "gpt-5.4"
|
||||
parallel_tool_calls: true
|
||||
prompt_cache_key: "<PROMPT_CACHE_KEY 1>"
|
||||
reasoning: {"summary":"auto"}
|
||||
store: false
|
||||
stream: true
|
||||
tool_choice: "auto"
|
||||
tools (6; hash=b4b0ae189288b007):
|
||||
- function/exec_command: Runs a command in a PTY, returning output or a session ID for ongoing interaction.; args=[cmd, justification, login, max_output_tokens, prefix_rule, sandbox_permissions, shell, tty, workdir, yield_time_ms]; hash=24f4b6739dd5d940
|
||||
- function/write_stdin: Writes characters to an existing unified exec session and returns recent output.; args=[chars, max_output_tokens, session_id, yield_time_ms]; hash=7fb62d8a3e2df4e2
|
||||
- function/request_user_input: Request user input for one to three short questions and wait for the response. This tool is only ...; args=[questions]; hash=64a729b25c424fc6
|
||||
- function/view_image: View a local image file from the filesystem when visual inspection is needed. Use this for images...; args=[path]; hash=1908de9c0be7118a
|
||||
- namespace/multi_agent_v1: Tools for spawning and managing sub-agents.; hash=c041c3bd4f63167c
|
||||
- function/close_agent
|
||||
- function/resume_agent
|
||||
- function/send_input
|
||||
- function/spawn_agent
|
||||
- function/wait_agent
|
||||
- web_search; hash=6f6c1b533d45fb52
|
||||
-- request 1 (turn) --
|
||||
00:message/developer:
|
||||
You are a coding agent running in the Codex CLI, a terminal-based coding assistant. Codex CLI is an open...I. You are expected to be precise, safe, and helpful. [hash=5125daec1ed78d99]
|
||||
|
||||
Your capabilities:
|
||||
|
||||
- Receive user prompts and other context provided by the harness, such as files in the workspace.
|
||||
- Communicate with the user by streaming thinking & responses, and by making & updating plans.
|
||||
- Emit function calls to run terminal commands and apply patches. Depending on how this specific run is ... More on this in the "Sandbox and approvals" section. [hash=31cf026fa7b25d6d]
|
||||
|
||||
<OMITTED 180 LINES; ~3987 TOKENS; hash=dd34d4527287c62a>
|
||||
## Shell commands
|
||||
|
||||
When using the shell, you must adhere to the following guidelines:
|
||||
|
||||
- When searching for text or files, prefer using `rg` or `rg --files` respectively because `rg` is much ...he `rg` command is not found, then use alternatives.) [hash=67af3ff3b546e946]
|
||||
- Do not use python scripts to attempt to output larger chunks of a file.
|
||||
|
||||
|
||||
01:message/developer:
|
||||
<permissions instructions>
|
||||
Filesystem sandboxing defines which files can be read or written. `sandbox_mode` is `read-only`: The san... permits reading files. Network access is restricted. [hash=be7da4425f89053c]
|
||||
# Escalation Requests
|
||||
|
||||
Commands are run outside the sandbox if they are approved by the user, or match an existing rule that al...hell control operators, including but not limited to: [hash=d24ebf5fa4e4b9bb]
|
||||
|
||||
- Pipes: |
|
||||
- Logical operators: &&, ||
|
||||
<OMITTED 44 LINES; ~790 TOKENS; hash=3a8900343e968d61>
|
||||
NEVER provide a prefix_rule if your command uses a heredoc or herestring.
|
||||
|
||||
### Examples
|
||||
Good examples of prefixes:
|
||||
- ["npm", "run", "dev"]
|
||||
- ["gh", "pr", "check"]
|
||||
- ["cargo", "test"]
|
||||
</permissions instructions>
|
||||
02:message/user:
|
||||
<environment_context>
|
||||
<cwd><CWD></cwd>
|
||||
<shell><HOST_SHELL></shell>
|
||||
<current_date><CURRENT_DATE></current_date>
|
||||
<timezone><HOST_TIMEZONE></timezone>
|
||||
<filesystem><workspace_roots><root><CWD></root></workspace_roots><permission_profile type="managed"><f...ntry></file_system></permission_profile></filesystem> [hash=e8c1de60307d0a3d]
|
||||
</environment_context>
|
||||
03:message/user:
|
||||
Find the latest release notes.
|
||||
@@ -1,6 +1,7 @@
|
||||
#![allow(clippy::unwrap_used)]
|
||||
|
||||
use codex_config::test_support::CloudConfigBundleFixture;
|
||||
use codex_core::ConfigRefreshOutcome;
|
||||
use codex_features::Feature;
|
||||
use codex_login::CodexAuth;
|
||||
use codex_login::auth::BedrockApiKeyAuth;
|
||||
@@ -11,6 +12,7 @@ use codex_model_provider_info::ModelProviderInfo;
|
||||
use codex_protocol::config_types::WebSearchMode;
|
||||
use codex_protocol::models::PermissionProfile;
|
||||
use codex_protocol::openai_models::WebSearchToolType;
|
||||
use codex_utils_absolute_path::AbsolutePathBuf;
|
||||
use core_test_support::responses;
|
||||
use core_test_support::responses::start_mock_server;
|
||||
use core_test_support::skip_if_no_network;
|
||||
@@ -76,19 +78,24 @@ async fn amazon_bedrock_web_search_uses_text_only_hosted_tools() {
|
||||
Configured,
|
||||
}
|
||||
|
||||
for (case, configured_web_search_mode, model_catalog) in [
|
||||
("cached by default", None, ModelCatalog::BuiltIn),
|
||||
for (case, config_toml, model_catalog) in [
|
||||
("cached by default", "", ModelCatalog::BuiltIn),
|
||||
(
|
||||
"unsupported explicit live search falls back to cached",
|
||||
Some(WebSearchMode::Live),
|
||||
"web_search = \"live\"",
|
||||
ModelCatalog::BuiltIn,
|
||||
),
|
||||
(
|
||||
"unsupported explicit indexed search falls back to cached",
|
||||
Some(WebSearchMode::Indexed),
|
||||
"web_search = \"indexed\"",
|
||||
ModelCatalog::BuiltIn,
|
||||
),
|
||||
("configured model catalog", None, ModelCatalog::Configured),
|
||||
(
|
||||
"unsupported implicit indexed search falls back to cached",
|
||||
"[features]\nweb_search_indexed_default = true",
|
||||
ModelCatalog::BuiltIn,
|
||||
),
|
||||
("configured model catalog", "", ModelCatalog::Configured),
|
||||
] {
|
||||
let server = start_mock_server().await;
|
||||
let resp_mock = responses::mount_sse_once(
|
||||
@@ -104,7 +111,12 @@ async fn amazon_bedrock_web_search_uses_text_only_hosted_tools() {
|
||||
api_key: "dummy".to_string(),
|
||||
region: "us-east-1".to_string(),
|
||||
});
|
||||
let mut builder = test_codex().with_auth(auth);
|
||||
let mut builder = test_codex()
|
||||
.with_auth(auth)
|
||||
.with_pre_build_hook(move |codex_home| {
|
||||
std::fs::write(codex_home.join("config.toml"), config_toml)
|
||||
.expect("write web search configuration");
|
||||
});
|
||||
builder = match model_catalog {
|
||||
ModelCatalog::BuiltIn => builder.with_model(AMAZON_BEDROCK_GPT_5_5_MODEL_ID),
|
||||
ModelCatalog::Configured => builder.with_model_info_override("gpt-5.5", |model_info| {
|
||||
@@ -117,12 +129,6 @@ async fn amazon_bedrock_web_search_uses_text_only_hosted_tools() {
|
||||
config.model_provider =
|
||||
ModelProviderInfo::create_amazon_bedrock_provider(/*aws*/ None);
|
||||
config.model_provider.base_url = base_url;
|
||||
if let Some(mode) = configured_web_search_mode {
|
||||
config
|
||||
.web_search_mode
|
||||
.set(mode)
|
||||
.expect("test web search mode should satisfy constraints");
|
||||
}
|
||||
});
|
||||
let test = builder
|
||||
.build_with_auto_env(&server)
|
||||
@@ -317,119 +323,264 @@ async fn web_search_mode_takes_precedence_over_legacy_flags() {
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn web_search_mode_defaults_to_cached_when_features_disabled() {
|
||||
skip_if_no_network!();
|
||||
async fn default_web_search_rollout_respects_permissions_and_survives_refresh() -> anyhow::Result<()>
|
||||
{
|
||||
skip_if_no_network!(Ok(()));
|
||||
|
||||
let server = start_mock_server().await;
|
||||
let sse = responses::sse(vec![
|
||||
responses::ev_response_created("resp-1"),
|
||||
responses::ev_completed("resp-1"),
|
||||
]);
|
||||
let resp_mock = responses::mount_sse_once(&server, sse).await;
|
||||
for (enabled, restricted_tool) in [
|
||||
(
|
||||
false,
|
||||
json!({"type": "web_search", "external_web_access": false}),
|
||||
),
|
||||
(
|
||||
true,
|
||||
json!({
|
||||
"type": "web_search",
|
||||
"external_web_access": true,
|
||||
"indexed_web_access": true,
|
||||
}),
|
||||
),
|
||||
] {
|
||||
let server = start_mock_server().await;
|
||||
let responses = responses::mount_sse_sequence(
|
||||
&server,
|
||||
vec![
|
||||
responses::sse_completed("restricted"),
|
||||
responses::sse_completed("full-access"),
|
||||
responses::sse_completed("after-refresh"),
|
||||
],
|
||||
)
|
||||
.await;
|
||||
let home = Arc::new(tempfile::TempDir::new()?);
|
||||
let config_path = AbsolutePathBuf::from_absolute_path(home.path().join("config.toml"))?;
|
||||
std::fs::write(
|
||||
&config_path,
|
||||
format!("[features]\nweb_search_indexed_default = {enabled}\n"),
|
||||
)?;
|
||||
let test = test_codex()
|
||||
.with_home(home)
|
||||
.with_model("gpt-5.4")
|
||||
.with_cloud_config_bundle(
|
||||
CloudConfigBundleFixture::loader_with_enterprise_requirement(
|
||||
r#"allowed_web_search_modes = ["cached", "indexed", "live"]"#,
|
||||
),
|
||||
)
|
||||
.build_with_auto_env(&server)
|
||||
.await?;
|
||||
|
||||
let mut builder = test_codex().with_model("gpt-5.4").with_config(|config| {
|
||||
config
|
||||
.web_search_mode
|
||||
.set(WebSearchMode::Cached)
|
||||
.expect("test web_search_mode should satisfy constraints");
|
||||
config
|
||||
test.submit_turn_with_permission_profile("restricted", PermissionProfile::read_only())
|
||||
.await?;
|
||||
test.submit_turn_with_permission_profile("full access", PermissionProfile::Disabled)
|
||||
.await?;
|
||||
|
||||
let current_config = test.codex.config().await;
|
||||
let mut refreshed_config = current_config.as_ref().clone();
|
||||
refreshed_config
|
||||
.features
|
||||
.disable(Feature::WebSearchCached)
|
||||
.expect("test config should allow feature update");
|
||||
config
|
||||
.features
|
||||
.disable(Feature::WebSearchRequest)
|
||||
.expect("test config should allow feature update");
|
||||
});
|
||||
let test = builder
|
||||
.build(&server)
|
||||
.await
|
||||
.expect("create test Codex conversation");
|
||||
.set_enabled(Feature::WebSearchIndexedDefault, !enabled)?;
|
||||
refreshed_config.web_search_mode.set(if enabled {
|
||||
WebSearchMode::Cached
|
||||
} else {
|
||||
WebSearchMode::Indexed
|
||||
})?;
|
||||
refreshed_config.config_layer_stack =
|
||||
refreshed_config.config_layer_stack.with_user_config(
|
||||
&config_path,
|
||||
toml::from_str(&format!(
|
||||
"[features]\nweb_search_indexed_default = {}\n",
|
||||
!enabled
|
||||
))?,
|
||||
)?;
|
||||
assert_eq!(
|
||||
test.codex
|
||||
.refresh_runtime_config(current_config, refreshed_config)
|
||||
.await,
|
||||
ConfigRefreshOutcome::Published,
|
||||
);
|
||||
test.submit_turn_with_permission_profile("after refresh", PermissionProfile::read_only())
|
||||
.await?;
|
||||
|
||||
test.submit_turn_with_permission_profile(
|
||||
"hello default cached web search",
|
||||
PermissionProfile::read_only(),
|
||||
)
|
||||
.await
|
||||
.expect("submit turn");
|
||||
|
||||
let body = resp_mock.single_request().body_json();
|
||||
let tool = find_web_search_tool(&body);
|
||||
assert_eq!(
|
||||
tool.get("external_web_access").and_then(Value::as_bool),
|
||||
Some(false),
|
||||
"default web_search should be cached when unset"
|
||||
);
|
||||
let requests = responses.requests();
|
||||
let tools: Vec<_> = requests
|
||||
.iter()
|
||||
.map(|request| find_web_search_tool(&request.body_json()).clone())
|
||||
.collect();
|
||||
assert_eq!(
|
||||
tools,
|
||||
vec![
|
||||
restricted_tool.clone(),
|
||||
json!({"type": "web_search", "external_web_access": true}),
|
||||
restricted_tool,
|
||||
]
|
||||
);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn web_search_mode_updates_between_turns_with_permission_profile() {
|
||||
skip_if_no_network!();
|
||||
async fn web_search_rollout_preserves_explicit_modes_and_full_access_semantics()
|
||||
-> anyhow::Result<()> {
|
||||
skip_if_no_network!(Ok(()));
|
||||
for (mode, expected) in [
|
||||
("disabled", None),
|
||||
(
|
||||
"cached",
|
||||
Some(json!({"type": "web_search", "external_web_access": false})),
|
||||
),
|
||||
(
|
||||
"live",
|
||||
Some(json!({"type": "web_search", "external_web_access": true})),
|
||||
),
|
||||
(
|
||||
"indexed",
|
||||
Some(json!({
|
||||
"type": "web_search",
|
||||
"external_web_access": true,
|
||||
"indexed_web_access": true,
|
||||
})),
|
||||
),
|
||||
] {
|
||||
let server = start_mock_server().await;
|
||||
let response = responses::mount_sse_sequence(
|
||||
&server,
|
||||
vec![
|
||||
responses::sse_completed("explicit-restricted"),
|
||||
responses::sse_completed("explicit-full-access"),
|
||||
],
|
||||
)
|
||||
.await;
|
||||
let home = Arc::new(tempfile::TempDir::new()?);
|
||||
std::fs::write(
|
||||
home.path().join("config.toml"),
|
||||
format!("web_search = \"{mode}\"\n[features]\nweb_search_indexed_default = true\n",),
|
||||
)?;
|
||||
let test = test_codex()
|
||||
.with_home(home)
|
||||
.with_model("gpt-5.4")
|
||||
.build_with_auto_env(&server)
|
||||
.await?;
|
||||
test.submit_turn_with_permission_profile("restricted", PermissionProfile::read_only())
|
||||
.await?;
|
||||
test.submit_turn_with_permission_profile("full access", PermissionProfile::Disabled)
|
||||
.await?;
|
||||
let tools: Vec<_> = response
|
||||
.requests()
|
||||
.iter()
|
||||
.map(|request| {
|
||||
request.body_json()["tools"]
|
||||
.as_array()
|
||||
.unwrap()
|
||||
.iter()
|
||||
.find(|tool| tool["type"] == "web_search")
|
||||
.cloned()
|
||||
})
|
||||
.collect();
|
||||
let full_access_expected = if mode == "cached" {
|
||||
Some(json!({"type": "web_search", "external_web_access": true}))
|
||||
} else {
|
||||
expected.clone()
|
||||
};
|
||||
assert_eq!(
|
||||
tools,
|
||||
vec![expected, full_access_expected],
|
||||
"web_search={mode}"
|
||||
);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
let server = start_mock_server().await;
|
||||
let resp_mock = responses::mount_sse_sequence(
|
||||
&server,
|
||||
vec![
|
||||
responses::sse(vec![
|
||||
responses::ev_response_created("resp-1"),
|
||||
responses::ev_completed("resp-1"),
|
||||
]),
|
||||
responses::sse(vec![
|
||||
responses::ev_response_created("resp-2"),
|
||||
responses::ev_completed("resp-2"),
|
||||
]),
|
||||
],
|
||||
)
|
||||
.await;
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn default_web_search_rollout_respects_managed_constraints() -> anyhow::Result<()> {
|
||||
skip_if_no_network!(Ok(()));
|
||||
for (enabled, requested_search_mode, requirements, effective_profile, expect_indexed) in [
|
||||
(
|
||||
true,
|
||||
None,
|
||||
"allowed_web_search_modes = [\"cached\", \"indexed\"]",
|
||||
PermissionProfile::Disabled,
|
||||
true,
|
||||
),
|
||||
(
|
||||
true,
|
||||
None,
|
||||
"allowed_web_search_modes = [\"cached\", \"indexed\"]\n[features]\nweb_search_indexed_default = false",
|
||||
PermissionProfile::Disabled,
|
||||
false,
|
||||
),
|
||||
(
|
||||
true,
|
||||
None,
|
||||
"allowed_web_search_modes = [\"cached\"]",
|
||||
PermissionProfile::Disabled,
|
||||
false,
|
||||
),
|
||||
(
|
||||
false,
|
||||
None,
|
||||
"allowed_web_search_modes = [\"indexed\", \"live\"]",
|
||||
PermissionProfile::Disabled,
|
||||
true,
|
||||
),
|
||||
(
|
||||
true,
|
||||
Some("live"),
|
||||
"allowed_web_search_modes = [\"cached\", \"indexed\"]",
|
||||
PermissionProfile::Disabled,
|
||||
false,
|
||||
),
|
||||
(
|
||||
true,
|
||||
None,
|
||||
"allowed_sandbox_modes = [\"read-only\"]",
|
||||
PermissionProfile::read_only(),
|
||||
true,
|
||||
),
|
||||
] {
|
||||
let server = start_mock_server().await;
|
||||
let response =
|
||||
responses::mount_sse_once(&server, responses::sse_completed("managed")).await;
|
||||
let home = Arc::new(tempfile::TempDir::new()?);
|
||||
let mut user_config = String::from("sandbox_mode = \"danger-full-access\"\n");
|
||||
if let Some(mode) = requested_search_mode {
|
||||
user_config.push_str(&format!("web_search = \"{mode}\"\n"));
|
||||
}
|
||||
user_config.push_str(&format!(
|
||||
"[features]\nweb_search_indexed_default = {enabled}\n"
|
||||
));
|
||||
std::fs::write(home.path().join("config.toml"), user_config)?;
|
||||
let test = test_codex()
|
||||
.with_home(home)
|
||||
.with_model("gpt-5.4")
|
||||
.with_cloud_config_bundle(
|
||||
CloudConfigBundleFixture::loader_with_enterprise_requirement(requirements),
|
||||
)
|
||||
.build_with_auto_env(&server)
|
||||
.await?;
|
||||
assert_eq!(
|
||||
test.codex
|
||||
.config()
|
||||
.await
|
||||
.permissions
|
||||
.effective_permission_profile(),
|
||||
effective_profile,
|
||||
);
|
||||
test.submit_text_turn("managed").await?;
|
||||
|
||||
let mut builder = test_codex().with_model("gpt-5.4").with_config(|config| {
|
||||
config
|
||||
.web_search_mode
|
||||
.set(WebSearchMode::Cached)
|
||||
.expect("test web_search_mode should satisfy constraints");
|
||||
config
|
||||
.features
|
||||
.disable(Feature::WebSearchCached)
|
||||
.expect("test config should allow feature update");
|
||||
config
|
||||
.features
|
||||
.disable(Feature::WebSearchRequest)
|
||||
.expect("test config should allow feature update");
|
||||
});
|
||||
let test = builder
|
||||
.build(&server)
|
||||
.await
|
||||
.expect("create test Codex conversation");
|
||||
|
||||
test.submit_turn_with_permission_profile("hello cached", PermissionProfile::read_only())
|
||||
.await
|
||||
.expect("submit first turn");
|
||||
test.submit_turn_with_permission_profile("hello live", PermissionProfile::Disabled)
|
||||
.await
|
||||
.expect("submit second turn");
|
||||
|
||||
let requests = resp_mock.requests();
|
||||
assert_eq!(requests.len(), 2, "expected two response requests");
|
||||
|
||||
let first_body = requests[0].body_json();
|
||||
let first_tool = find_web_search_tool(&first_body);
|
||||
assert_eq!(
|
||||
first_tool
|
||||
.get("external_web_access")
|
||||
.and_then(Value::as_bool),
|
||||
Some(false),
|
||||
"read-only policy should default web_search to cached"
|
||||
);
|
||||
|
||||
let second_body = requests[1].body_json();
|
||||
let second_tool = find_web_search_tool(&second_body);
|
||||
assert_eq!(
|
||||
second_tool
|
||||
.get("external_web_access")
|
||||
.and_then(Value::as_bool),
|
||||
Some(true),
|
||||
"danger-full-access policy should default web_search to live"
|
||||
);
|
||||
let tool = if expect_indexed {
|
||||
json!({
|
||||
"type": "web_search",
|
||||
"external_web_access": true,
|
||||
"indexed_web_access": true,
|
||||
})
|
||||
} else {
|
||||
json!({"type": "web_search", "external_web_access": false})
|
||||
};
|
||||
assert_eq!(
|
||||
find_web_search_tool(&response.single_request().body_json()),
|
||||
&tool
|
||||
);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
@@ -491,40 +642,61 @@ location = { country = "US", city = "New York", timezone = "America/New_York" }
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn indexed_web_search_mode_sets_indexed_access() {
|
||||
skip_if_no_network!();
|
||||
async fn indexed_web_search_mode_sets_indexed_access() -> anyhow::Result<()> {
|
||||
skip_if_no_network!(Ok(()));
|
||||
|
||||
let server = start_mock_server().await;
|
||||
let sse = responses::sse(vec![
|
||||
responses::ev_response_created("resp-1"),
|
||||
responses::ev_completed("resp-1"),
|
||||
]);
|
||||
let resp_mock = responses::mount_sse_once(&server, sse).await;
|
||||
|
||||
let home = Arc::new(tempfile::TempDir::new().expect("create codex home"));
|
||||
std::fs::write(home.path().join("config.toml"), r#"web_search = "indexed""#)
|
||||
.expect("write config.toml");
|
||||
|
||||
let mut builder = test_codex().with_model("gpt-5.2").with_home(home);
|
||||
let test = builder
|
||||
.build(&server)
|
||||
.await
|
||||
.expect("create test Codex conversation");
|
||||
|
||||
test.submit_turn_with_permission_profile(
|
||||
"hello indexed web search",
|
||||
PermissionProfile::Disabled,
|
||||
let resp_mock = responses::mount_sse_sequence(
|
||||
&server,
|
||||
vec![
|
||||
responses::sse_completed("before-refresh"),
|
||||
responses::sse_completed("after-refresh"),
|
||||
],
|
||||
)
|
||||
.await
|
||||
.expect("submit turn");
|
||||
.await;
|
||||
let home = Arc::new(tempfile::TempDir::new()?);
|
||||
let config_path = AbsolutePathBuf::from_absolute_path(home.path().join("config.toml"))?;
|
||||
std::fs::write(&config_path, "web_search = \"indexed\"\n")?;
|
||||
let test = test_codex()
|
||||
.with_home(home)
|
||||
.with_model("gpt-5.2")
|
||||
.build_with_auto_env(&server)
|
||||
.await?;
|
||||
|
||||
let body = resp_mock.single_request().body_json();
|
||||
let tool = find_web_search_tool(&body);
|
||||
test.submit_turn_with_permission_profile("before refresh", PermissionProfile::Disabled)
|
||||
.await?;
|
||||
|
||||
// Runtime refreshes replace the user layer, but web search stays session-static.
|
||||
let current_config = test.codex.config().await;
|
||||
let mut refreshed_config = current_config.as_ref().clone();
|
||||
refreshed_config.web_search_mode_was_explicit = false;
|
||||
refreshed_config
|
||||
.web_search_mode
|
||||
.set(WebSearchMode::Cached)?;
|
||||
refreshed_config.config_layer_stack = refreshed_config
|
||||
.config_layer_stack
|
||||
.with_user_config(&config_path, toml::Value::Table(Default::default()))?;
|
||||
assert_eq!(
|
||||
(
|
||||
tool.get("external_web_access").and_then(Value::as_bool),
|
||||
tool.get("indexed_web_access").and_then(Value::as_bool),
|
||||
),
|
||||
(Some(true), Some(true))
|
||||
test.codex
|
||||
.refresh_runtime_config(current_config, refreshed_config)
|
||||
.await,
|
||||
ConfigRefreshOutcome::Published,
|
||||
);
|
||||
|
||||
test.submit_turn_with_permission_profile("after refresh", PermissionProfile::Disabled)
|
||||
.await?;
|
||||
|
||||
let requests = resp_mock.requests();
|
||||
assert_eq!(requests.len(), 2);
|
||||
for request in requests {
|
||||
assert_eq!(
|
||||
find_web_search_tool(&request.body_json()),
|
||||
&json!({
|
||||
"type": "web_search",
|
||||
"external_web_access": true,
|
||||
"indexed_web_access": true,
|
||||
}),
|
||||
);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -203,6 +203,8 @@ pub enum Feature {
|
||||
/// Allow the model to request web searches that fetch cached content.
|
||||
/// Takes precedence over `WebSearchRequest`.
|
||||
WebSearchCached,
|
||||
/// Prefer indexed search when the implicit cached default can be upgraded.
|
||||
WebSearchIndexedDefault,
|
||||
/// Expose the extension-backed standalone web search tool.
|
||||
StandaloneWebSearch,
|
||||
/// Request the legacy Landlock mode of the Linux sandbox.
|
||||
@@ -1463,6 +1465,12 @@ pub const FEATURES: &[FeatureSpec] = &[
|
||||
stage: Stage::Deprecated,
|
||||
default_enabled: false,
|
||||
},
|
||||
FeatureSpec {
|
||||
id: Feature::WebSearchIndexedDefault,
|
||||
key: "web_search_indexed_default",
|
||||
stage: Stage::Stable,
|
||||
default_enabled: false,
|
||||
},
|
||||
FeatureSpec {
|
||||
id: Feature::StandaloneWebSearch,
|
||||
key: "standalone_web_search",
|
||||
|
||||
@@ -38,6 +38,12 @@ pub(super) fn apply_launch_override(
|
||||
)
|
||||
})
|
||||
};
|
||||
if is_launch("features.web_search_indexed_default") {
|
||||
overrides
|
||||
.entry("features".to_string())
|
||||
.or_insert_with(|| serde_json::json!({}))["web_search_indexed_default"] =
|
||||
serde_json::json!(effective["features"]["web_search_indexed_default"]);
|
||||
}
|
||||
// A canonical setting always takes precedence, even when its origin is implicit.
|
||||
if let Some(value) = effective.get("web_search") {
|
||||
if is_launch("web_search") {
|
||||
@@ -72,13 +78,31 @@ pub(super) fn apply_launch_override(
|
||||
if thread_params_mode == ThreadParamsMode::Embedded && (cached || live) {
|
||||
return;
|
||||
}
|
||||
// Explicitly disabling all legacy search features falls back to cached search.
|
||||
let Some(key) = ["web_search_cached", request_key].into_iter().find(|key| {
|
||||
features.get(*key).and_then(toml::Value::as_bool) == Some(false)
|
||||
&& is_launch(&format!("features.{key}"))
|
||||
}) else {
|
||||
return;
|
||||
};
|
||||
let indexed_default_enabled = if thread_params_mode == ThreadParamsMode::Embedded {
|
||||
config.features.enabled(Feature::WebSearchIndexedDefault)
|
||||
} else {
|
||||
is_launch("features.web_search_indexed_default")
|
||||
&& features
|
||||
.get("web_search_indexed_default")
|
||||
.and_then(toml::Value::as_bool)
|
||||
== Some(true)
|
||||
};
|
||||
if indexed_default_enabled {
|
||||
// Keep the default implicit so full-access turns can still promote it to live.
|
||||
let features = overrides
|
||||
.entry("features".to_string())
|
||||
.or_insert_with(|| serde_json::json!({}));
|
||||
features["web_search_cached"] = false.into();
|
||||
features["web_search_request"] = false.into();
|
||||
return;
|
||||
}
|
||||
// Preserve the legacy cached fallback while the rollout is disabled.
|
||||
(key, "cached")
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
use super::super::ThreadParamsMode;
|
||||
use super::super::config_request_overrides_from_config;
|
||||
use crate::legacy_core::config::ConfigBuilder;
|
||||
use codex_protocol::config_types::WebSearchMode;
|
||||
use codex_utils_absolute_path::AbsolutePathBuf;
|
||||
use color_eyre::Result;
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
@@ -148,3 +150,177 @@ async fn embedded_legacy_search_honors_shared_feature_requirements() -> Result<(
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn legacy_search_disables_keep_indexed_default_implicit() -> Result<()> {
|
||||
let client_home = tempfile::tempdir()?;
|
||||
let server_home = tempfile::tempdir()?;
|
||||
let profile = AbsolutePathBuf::from_absolute_path(client_home.path().join("work.config.toml"))?;
|
||||
for (selected_profile, enabled) in [(false, false), (false, true), (true, false), (true, true)]
|
||||
{
|
||||
for flags in [
|
||||
"",
|
||||
"web_search = false",
|
||||
"web_search_cached = false",
|
||||
"web_search_request = false",
|
||||
] {
|
||||
let settings = format!("[features]\nweb_search_indexed_default = {enabled}\n{flags}");
|
||||
std::fs::write(&profile, &settings)?;
|
||||
let config = ConfigBuilder::default()
|
||||
.codex_home(client_home.path().to_path_buf())
|
||||
.cli_overrides(if selected_profile {
|
||||
Vec::new()
|
||||
} else {
|
||||
toml::from_str::<toml::Table>(&settings)?
|
||||
.into_iter()
|
||||
.collect()
|
||||
})
|
||||
.loader_overrides(codex_config::LoaderOverrides {
|
||||
user_config_path: selected_profile.then(|| profile.clone()),
|
||||
user_config_profile: selected_profile.then(|| "work".parse()).transpose()?,
|
||||
..codex_config::LoaderOverrides::without_managed_config_for_tests()
|
||||
})
|
||||
.build()
|
||||
.await?;
|
||||
for mode in [ThreadParamsMode::Embedded, ThreadParamsMode::Remote] {
|
||||
let overrides =
|
||||
config_request_overrides_from_config(&config, mode).expect("config overrides");
|
||||
let forwarded = ConfigBuilder::default()
|
||||
.codex_home(server_home.path().to_path_buf())
|
||||
.cli_overrides(
|
||||
overrides
|
||||
.into_iter()
|
||||
.map(|(key, value)| Ok((key, toml::Value::try_from(value)?)))
|
||||
.collect::<Result<_>>()?,
|
||||
)
|
||||
.loader_overrides(
|
||||
codex_config::LoaderOverrides::without_managed_config_for_tests(),
|
||||
)
|
||||
.build()
|
||||
.await?;
|
||||
assert_eq!(forwarded.web_search_mode, config.web_search_mode);
|
||||
assert_eq!(
|
||||
forwarded.web_search_mode_was_explicit,
|
||||
!enabled && !flags.is_empty()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn local_indexed_default_preserves_remote_legacy_search_disable() -> Result<()> {
|
||||
let client_home = tempfile::tempdir()?;
|
||||
let server_home = tempfile::tempdir()?;
|
||||
std::fs::write(
|
||||
client_home.path().join("config.toml"),
|
||||
"[features]\nweb_search_indexed_default = true",
|
||||
)?;
|
||||
std::fs::write(
|
||||
server_home.path().join("config.toml"),
|
||||
"web_search = 'live'",
|
||||
)?;
|
||||
let config = ConfigBuilder::default()
|
||||
.codex_home(client_home.path().to_path_buf())
|
||||
.cli_overrides(vec![(
|
||||
"features.web_search_request".to_string(),
|
||||
toml::Value::Boolean(false),
|
||||
)])
|
||||
.loader_overrides(codex_config::LoaderOverrides::without_managed_config_for_tests())
|
||||
.build()
|
||||
.await?;
|
||||
let overrides = config_request_overrides_from_config(&config, ThreadParamsMode::Remote)
|
||||
.expect("config overrides");
|
||||
assert_eq!(
|
||||
overrides,
|
||||
std::collections::HashMap::from([("web_search".to_string(), serde_json::json!("cached"))]),
|
||||
);
|
||||
let forwarded = ConfigBuilder::default()
|
||||
.codex_home(server_home.path().to_path_buf())
|
||||
.cli_overrides(
|
||||
overrides
|
||||
.into_iter()
|
||||
.map(|(key, value)| Ok((key, toml::Value::try_from(value)?)))
|
||||
.collect::<Result<_>>()?,
|
||||
)
|
||||
.loader_overrides(codex_config::LoaderOverrides::without_managed_config_for_tests())
|
||||
.build()
|
||||
.await?;
|
||||
assert_eq!(forwarded.web_search_mode.value(), WebSearchMode::Cached);
|
||||
assert!(forwarded.web_search_mode_was_explicit);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn legacy_search_disables_preserve_server_policy_with_indexed_default() -> Result<()> {
|
||||
let client_home = tempfile::tempdir()?;
|
||||
let server_home = tempfile::tempdir()?;
|
||||
let requirements_path = server_home.path().join("requirements.toml");
|
||||
for enabled in [false, true] {
|
||||
let config = ConfigBuilder::default()
|
||||
.codex_home(client_home.path().to_path_buf())
|
||||
.cli_overrides(
|
||||
toml::from_str::<toml::Table>(&format!(
|
||||
"[features]\nweb_search_indexed_default = {enabled}\nweb_search_request = false"
|
||||
))?
|
||||
.into_iter()
|
||||
.collect(),
|
||||
)
|
||||
.loader_overrides(codex_config::LoaderOverrides::without_managed_config_for_tests())
|
||||
.build()
|
||||
.await?;
|
||||
let overrides = config_request_overrides_from_config(&config, ThreadParamsMode::Remote)
|
||||
.expect("config overrides");
|
||||
for (settings, requirements, expected, explicit) in [
|
||||
("web_search = 'live'", "", WebSearchMode::Live, true),
|
||||
("web_search = 'indexed'", "", WebSearchMode::Indexed, true),
|
||||
("web_search = 'disabled'", "", WebSearchMode::Disabled, true),
|
||||
(
|
||||
"",
|
||||
"[features]\nweb_search_request = true",
|
||||
WebSearchMode::Live,
|
||||
false,
|
||||
),
|
||||
(
|
||||
"",
|
||||
"[features]\nweb_search_cached = true",
|
||||
WebSearchMode::Cached,
|
||||
false,
|
||||
),
|
||||
(
|
||||
"",
|
||||
"allowed_web_search_modes = ['cached']",
|
||||
WebSearchMode::Cached,
|
||||
false,
|
||||
),
|
||||
] {
|
||||
std::fs::write(server_home.path().join("config.toml"), settings)?;
|
||||
std::fs::write(&requirements_path, requirements)?;
|
||||
let forwarded = ConfigBuilder::default()
|
||||
.codex_home(server_home.path().to_path_buf())
|
||||
.cli_overrides(
|
||||
overrides
|
||||
.iter()
|
||||
.map(|(key, value)| Ok((key.clone(), toml::Value::try_from(value)?)))
|
||||
.collect::<Result<_>>()?,
|
||||
)
|
||||
.loader_overrides(codex_config::LoaderOverrides {
|
||||
system_requirements_path: Some(requirements_path.clone()),
|
||||
..codex_config::LoaderOverrides::without_managed_config_for_tests()
|
||||
})
|
||||
.build()
|
||||
.await?;
|
||||
assert_eq!(
|
||||
forwarded.web_search_mode.value(),
|
||||
if enabled {
|
||||
expected
|
||||
} else {
|
||||
WebSearchMode::Cached
|
||||
},
|
||||
);
|
||||
assert_eq!(forwarded.web_search_mode_was_explicit, !enabled || explicit);
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user