Snapshot resolved settings for each model step (#40651)

## Why

Thread settings can change while a turn is running, and delegated review or
compaction steps can select a different model. Each request needs a consistent
set of settings resolved against the model that will execute it.

## What changed

- Capture immutable resolved settings for each model step, including model
  metadata, reasoning options, service tier, approvals, and personality.
- Keep in-flight steps on their captured settings while applying thread updates
  to subsequent work.
- Resolve inherited reasoning summaries and filter service tiers against the
  selected model and feature configuration for review and compaction steps.

## Testing

Added coverage for settings updates during paused turns, model changes,
previous-model compaction, review-model defaults, and service-tier filtering.

GitOrigin-RevId: fca4b3b305379f1bf26a5cac75ee0dd1747ac1f6
This commit is contained in:
joeflorencio-openai
2026-08-25 17:41:22 +00:00
committed by copyberry
parent ba6cf9c692
commit 68301fa45f
68 changed files with 1393 additions and 516 deletions
+1 -1
View File
@@ -497,7 +497,7 @@ impl Session {
_ => {}
}
}
resolution.into_tool_result(&ctx.review_context.turn().model_info)
resolution.into_tool_result(ctx.review_context.turn().model_info())
}
async fn request_reviewer_approval(
+1 -1
View File
@@ -277,7 +277,7 @@ pub(super) async fn handle_runtime_response(
}
fn sanitize_runtime_image_detail(turn: &TurnContext, items: &mut [FunctionCallOutputContentItem]) {
sanitize_image_detail_items(can_request_original_image_detail(&turn.model_info), items);
sanitize_image_detail_items(can_request_original_image_detail(turn.model_info()), items);
}
fn format_script_status(response: &RuntimeResponse) -> String {
+3 -3
View File
@@ -132,7 +132,7 @@ async fn emit_exec_command_begin(ctx: ToolEventCtx<'_>, exec_input: &ExecCommand
.analytics_events_client
.track_artifact_operation(
build_track_events_context(
ctx.turn.model_info.slug.clone(),
ctx.turn.model_info().slug.clone(),
ctx.session.thread_id.to_string(),
ctx.turn.sub_id.clone(),
ctx.turn.originator.clone(),
@@ -373,7 +373,7 @@ impl ToolEmitter {
output: &ExecToolCallOutput,
ctx: ToolEventCtx<'_>,
) -> String {
super::format_exec_output_for_model(output, ctx.turn.model_info.truncation_policy.into())
super::format_exec_output_for_model(output, ctx.turn.model_info().truncation_policy.into())
}
pub async fn finish(
@@ -521,7 +521,7 @@ async fn emit_exec_stage(
duration: output.duration,
formatted_output: format_exec_output_str(
&output,
ctx.turn.model_info.truncation_policy.into(),
ctx.turn.model_info().truncation_policy.into(),
),
status: if output.exit_code == 0 {
ExecCommandStatus::Completed
@@ -162,7 +162,7 @@ async fn to_extension_call(invocation: &ToolInvocation) -> ExtensionToolCall {
.turn
.turn_metadata_state
.current_meta_value_for_mcp_request(McpTurnMetadataContext {
model: invocation.turn.model_info.slug.as_str(),
model: invocation.turn.model_info().slug.as_str(),
reasoning_effort: invocation.turn.effective_reasoning_effort(),
})
.and_then(|metadata| to_ascii_json_string(&metadata).ok());
@@ -194,9 +194,9 @@ async fn to_extension_call(invocation: &ToolInvocation) -> ExtensionToolCall {
turn_id: invocation.turn.sub_id.clone(),
call_id: invocation.call_id.clone(),
tool_name: invocation.tool_name.clone(),
model: invocation.turn.model_info.slug.clone(),
model: invocation.turn.model_info().slug.clone(),
codex_turn_metadata,
truncation_policy: invocation.turn.model_info.truncation_policy.into(),
truncation_policy: invocation.turn.model_info().truncation_policy.into(),
source: extension_tool_call_source(invocation.source.clone()),
conversation_history,
turn_item_emitter: Arc::new(CoreTurnItemEmitter {
@@ -388,8 +388,8 @@ mod tests {
let weak_session = Arc::downgrade(&session);
let weak_turn = Arc::downgrade(&turn);
let turn_id = turn.sub_id.clone();
let model = turn.model_info.slug.clone();
let truncation_policy = turn.model_info.truncation_policy.into();
let model = turn.model_info().slug.clone();
let truncation_policy = turn.model_info().truncation_policy.into();
let expected_sandbox_cwds = turn
.environments
.turn_environments()
+2 -2
View File
@@ -208,8 +208,8 @@ impl McpHandler {
result: result.result,
tool_input: result.tool_input,
wall_time: started.elapsed(),
original_image_detail_supported: can_request_original_image_detail(&turn.model_info),
truncation_policy: turn.model_info.truncation_policy.into(),
original_image_detail_supported: can_request_original_image_detail(turn.model_info()),
truncation_policy: turn.model_info().truncation_policy.into(),
}))
}
}
@@ -290,7 +290,7 @@ where
emit_tool_call_begin(session, turn, call_id, invocation.clone()).await;
let start = Instant::now();
let result = operation.await.and_then(|payload| {
serialize_function_output(payload, turn.model_info.truncation_policy.into())
serialize_function_output(payload, turn.model_info().truncation_policy.into())
});
match result {
@@ -194,13 +194,13 @@ pub(crate) fn build_agent_resume_config(turn: &TurnContext) -> Result<Config, Fu
fn build_agent_shared_config(turn: &TurnContext) -> Result<Config, FunctionCallError> {
let base_config = turn.config.clone();
let mut config = (*base_config).clone();
config.model = Some(turn.model_info.slug.clone());
config.model = Some(turn.model_info().slug.clone());
config.model_provider = turn.provider.info().clone();
config.model_reasoning_effort = turn
.reasoning_effort
.clone()
.or_else(|| turn.model_info.default_reasoning_level.clone());
config.model_reasoning_summary = Some(turn.reasoning_summary);
.reasoning_effort()
.or(turn.model_info().default_reasoning_level.as_ref())
.cloned();
config.model_reasoning_summary = Some(turn.reasoning_summary());
config.developer_instructions = turn.developer_instructions.clone();
if turn.multi_agent_version == MultiAgentVersion::V2
&& let Some(developer_instructions) = turn
@@ -308,8 +308,8 @@ pub(crate) async fn apply_requested_spawn_agent_model_overrides(
if let Some(reasoning_effort) = requested_reasoning_effort {
validate_spawn_agent_reasoning_effort(
&turn.model_info.slug,
&turn.model_info.supported_reasoning_levels,
&turn.model_info().slug,
&turn.model_info().supported_reasoning_levels,
&reasoning_effort,
)?;
config.model_reasoning_effort = Some(reasoning_effort);
@@ -386,11 +386,9 @@ async fn multi_agent_v2_spawn_fork_turns_all_applies_agent_type_override() {
.features
.enable(Feature::MultiAgentV2)
.expect("test config should allow feature update");
let turn = TurnContext {
config: Arc::new(config),
multi_agent_version: codex_protocol::protocol::MultiAgentVersion::V2,
..turn
};
let mut turn = turn;
turn.config = Arc::new(config);
turn.multi_agent_version = codex_protocol::protocol::MultiAgentVersion::V2;
SpawnAgentHandlerV2::default()
.handle(invocation(
@@ -915,11 +913,9 @@ async fn multi_agent_v2_spawn_partial_fork_turns_allows_agent_type_override() {
.features
.enable(Feature::MultiAgentV2)
.expect("test config should allow feature update");
let turn = TurnContext {
config: Arc::new(config),
multi_agent_version: codex_protocol::protocol::MultiAgentVersion::V2,
..turn
};
let mut turn = turn;
turn.config = Arc::new(config);
turn.multi_agent_version = codex_protocol::protocol::MultiAgentVersion::V2;
let parent_provider_id = turn.config.model_provider_id.clone();
let output = SpawnAgentHandlerV2::default()
@@ -4534,7 +4530,7 @@ async fn build_agent_spawn_config_uses_turn_context_values() {
let base_instructions = BaseInstructions {
text: "base".to_string(),
provenance: Some(BaseInstructionsProvenance::Model {
model: turn.model_info.slug.clone(),
model: turn.model_info().slug.clone(),
}),
};
turn.developer_instructions = Some("dev".to_string());
@@ -4581,10 +4577,10 @@ async fn build_agent_spawn_config_uses_turn_context_values() {
let mut expected = (*turn.config).clone();
expected.base_instructions_provenance = base_instructions.provenance.clone();
expected.base_instructions = Some(base_instructions.text);
expected.model = Some(turn.model_info.slug.clone());
expected.model = Some(turn.model_info().slug.clone());
expected.model_provider = turn.provider.info().clone();
expected.model_reasoning_effort = turn.reasoning_effort.clone();
expected.model_reasoning_summary = Some(turn.reasoning_summary);
expected.model_reasoning_effort = turn.reasoning_effort().cloned();
expected.model_reasoning_summary = Some(turn.reasoning_summary());
expected.developer_instructions = turn.developer_instructions.clone();
#[allow(deprecated)]
{
@@ -4604,7 +4600,7 @@ async fn build_agent_resume_config_clears_base_instructions() {
let mut base_config = (*turn.config).clone();
base_config.base_instructions = Some("caller-base".to_string());
base_config.base_instructions_provenance = Some(BaseInstructionsProvenance::Model {
model: turn.model_info.slug.clone(),
model: turn.model_info().slug.clone(),
});
turn.config = Arc::new(base_config);
Arc::make_mut(&mut turn.config)
@@ -4634,10 +4630,10 @@ async fn build_agent_resume_config_clears_base_instructions() {
let mut expected = (*turn.config).clone();
expected.base_instructions = None;
expected.base_instructions_provenance = None;
expected.model = Some(turn.model_info.slug.clone());
expected.model = Some(turn.model_info().slug.clone());
expected.model_provider = turn.provider.info().clone();
expected.model_reasoning_effort = turn.reasoning_effort.clone();
expected.model_reasoning_summary = Some(turn.reasoning_summary);
expected.model_reasoning_effort = turn.reasoning_effort().cloned();
expected.model_reasoning_summary = Some(turn.reasoning_summary());
expected.developer_instructions = turn.developer_instructions.clone();
#[allow(deprecated)]
{
@@ -186,7 +186,7 @@ async fn handle_spawn_agent(
let multi_agent_v2_usage_hints =
if is_full_history_fork && turn.multi_agent_version == MultiAgentVersion::V2 {
let child_model_info = match config.model.as_deref() {
Some(model) if model != turn.model_info.slug => Some(
Some(model) if model != turn.model_info().slug => Some(
session
.services
.models_manager
@@ -197,7 +197,7 @@ async fn handle_spawn_agent(
};
let child_catalog = child_model_info
.as_ref()
.unwrap_or(&turn.model_info)
.unwrap_or(turn.model_info())
.model_messages
.as_ref()
.and_then(|messages| messages.multi_agent.as_ref())
+1 -1
View File
@@ -81,7 +81,7 @@ impl PlanHandler {
}
};
if turn.mode == ModeKind::Plan {
if turn.mode() == ModeKind::Plan {
return Err(FunctionCallError::RespondToModel(
"update_plan is a TODO/checklist tool and is not allowed in Plan mode".to_string(),
));
@@ -217,7 +217,7 @@ impl RequestPluginInstallHandler {
.analytics_events_client
.track_plugin_install_requested(
build_track_events_context(
turn.model_info.slug.clone(),
turn.model_info().slug.clone(),
session.thread_id.to_string(),
turn.sub_id.clone(),
turn.originator.clone(),
@@ -2,6 +2,8 @@ use super::*;
use crate::session::step_context::StepContext;
use crate::session::tests::make_session_and_context;
use crate::session::tests::make_session_and_context_with_rx;
use crate::session::tests::update_selected_settings_for_test;
use crate::session::tests::update_turn_settings_for_test;
use crate::state::ActiveTurn;
use crate::tools::context::ToolInvocation;
use crate::tools::context::ToolPayload;
@@ -224,9 +226,14 @@ async fn guardian_user_input_evidence_is_bounded() {
#[tokio::test]
async fn request_user_input_sets_blocking_from_turn_mode() {
let (session, mut turn, events) = make_session_and_context_with_rx().await;
Arc::get_mut(&mut turn)
.expect("turn context should be uniquely owned")
.mode = ModeKind::Plan;
update_turn_settings_for_test(
Arc::get_mut(&mut turn).expect("turn context should be uniquely owned"),
|settings| {
update_selected_settings_for_test(settings, |selected| {
selected.collaboration_mode.mode = ModeKind::Plan;
});
},
);
*session.active_turn.lock().await = Some(ActiveTurn::default());
let request = tokio::spawn({
@@ -345,7 +345,7 @@ impl ExecCommandHandler {
chunk_id: String::new(),
wall_time: std::time::Duration::ZERO,
raw_output: output.into_text().into_bytes(),
truncation_policy: turn.model_info.truncation_policy.into(),
truncation_policy: turn.model_info().truncation_policy.into(),
max_output_tokens,
process_id: None,
exit_code: None,
@@ -397,7 +397,7 @@ impl ExecCommandHandler {
chunk_id: generate_chunk_id(),
wall_time: output.duration,
raw_output: output_text.into_bytes(),
truncation_policy: turn.model_info.truncation_policy.into(),
truncation_policy: turn.model_info().truncation_policy.into(),
max_output_tokens,
// Sandbox denial is terminal, so there is no live
// process for write_stdin to resume.
@@ -78,7 +78,7 @@ impl WriteStdinHandler {
input: &args.chars,
yield_time_ms: args.yield_time_ms,
max_output_tokens: args.max_output_tokens,
truncation_policy: turn.model_info.truncation_policy.into(),
truncation_policy: turn.model_info().truncation_policy.into(),
interaction_event: Some(WriteStdinInteractionEvent {
session: &session,
turn: &turn,
@@ -93,7 +93,7 @@ impl ViewImageHandler {
) -> Result<Box<dyn crate::tools::context::ToolOutput>, FunctionCallError> {
if !invocation
.turn
.model_info
.model_info()
.input_modalities
.contains(&InputModality::Image)
{
@@ -182,7 +182,7 @@ impl ViewImageHandler {
FunctionCallError::RespondToModel(VIEW_IMAGE_INVALID_MESSAGE.to_string())
})?;
let can_request_original_detail = can_request_original_image_detail(&turn.model_info);
let can_request_original_detail = can_request_original_image_detail(turn.model_info());
let use_original_detail = self.options.unified_image_budget
|| can_request_original_detail && matches!(detail, Some(ViewImageDetail::Original));
let image_detail = if use_original_detail {
+1 -1
View File
@@ -65,7 +65,7 @@ pub(crate) fn tool_user_shell_type(
}
pub(crate) fn requested_tool_mode(turn_context: &TurnContext) -> ToolMode {
turn_context.model_info.tool_mode.unwrap_or_else(|| {
turn_context.model_info().tool_mode.unwrap_or_else(|| {
if turn_context.config.features.enabled(Feature::CodeModeOnly) {
ToolMode::CodeModeOnly
} else if turn_context.config.features.enabled(Feature::CodeMode) {
@@ -365,7 +365,7 @@ impl CoreShellActionProvider {
}
ReviewDecision::TimedOut => EscalationDecision::deny(Some(
crate::guardian::guardian_timeout_message(
&self.review_context.turn().model_info,
self.review_context.turn().model_info(),
),
)),
ReviewDecision::ApprovedMcpPolicyAmendment => {
+21 -18
View File
@@ -373,7 +373,7 @@ pub(crate) fn finalize_tool_router(
.config
.tool_registry
.turn_metadata_includes_tool_info
&& turn_context.model_info.use_responses_lite;
&& turn_context.model_info().use_responses_lite;
if turn_context.config.tool_registry.error_on_tool_collisions {
if let Some(tool_name) = registry.first_collision() {
@@ -547,7 +547,7 @@ fn hosted_model_tool_specs(
registered_extension_tool_names: &[ToolName],
) -> Vec<ToolSpec> {
// Responses Lite accepts schemas for client-executed tools, not hosted Responses tools.
if turn_context.model_info.use_responses_lite
if turn_context.model_info().use_responses_lite
|| crate::guardian::is_basic_session_source(&turn_context.session_source)
{
return Vec::new();
@@ -567,7 +567,7 @@ fn hosted_model_tool_specs(
if let Some(hosted_web_search_tool) = create_web_search_tool(WebSearchToolOptions {
web_search_mode,
web_search_config,
web_search_tool_type: turn_context.model_info.web_search_tool_type,
web_search_tool_type: turn_context.model_info().web_search_tool_type,
}) {
specs.push(hosted_web_search_tool);
}
@@ -575,7 +575,7 @@ fn hosted_model_tool_specs(
}
pub(crate) fn search_tool_enabled(turn_context: &TurnContext) -> bool {
turn_context.model_info.supports_search_tool && namespace_tools_enabled(turn_context)
turn_context.model_info().supports_search_tool && namespace_tools_enabled(turn_context)
}
pub(crate) fn tool_suggest_enabled(turn_context: &TurnContext) -> bool {
@@ -602,7 +602,7 @@ fn collab_tools_enabled(turn_context: &TurnContext) -> bool {
),
MultiAgentVersion::V2 => {
turn_context.session_source.get_agent_path().is_none()
|| turn_context.model_info.multi_agent_version == Some(MultiAgentVersion::V2)
|| turn_context.model_info().multi_agent_version == Some(MultiAgentVersion::V2)
}
}
}
@@ -633,7 +633,7 @@ fn image_generation_available(turn_context: &TurnContext) -> bool {
}
if !turn_context
.model_info
.model_info()
.input_modalities
.contains(&InputModality::Image)
{
@@ -794,8 +794,10 @@ fn register_code_mode_executors(
&namespace_descriptions,
turn_context.config.code_mode.default_exec_yield_time_ms,
tool_mode == ToolMode::CodeModeOnly,
if unified_image_budget_enabled(&turn_context.config.features, &turn_context.model_info)
{
if unified_image_budget_enabled(
&turn_context.config.features,
turn_context.model_info(),
) {
codex_code_mode::ImageDetailVisibility::Hidden
} else {
codex_code_mode::ImageDetailVisibility::Visible
@@ -908,7 +910,7 @@ fn add_core_tool_sources(context: &CoreToolPlanContext<'_>, registry: &mut ToolR
if turn_context.config.features.enabled(Feature::ShellTool)
&& turn_context.config.features.enabled(Feature::UnifiedExec)
&& !matches!(
turn_context.model_info.shell_type,
turn_context.model_info().shell_type,
ConfigShellToolType::Disabled
)
{
@@ -926,11 +928,11 @@ fn add_core_tool_sources(context: &CoreToolPlanContext<'_>, registry: &mut ToolR
if turn_context.config.features.enabled(Feature::ViewImage) {
registry.add(ViewImageHandler::new(ViewImageToolOptions {
can_request_original_image_detail: can_request_original_image_detail(
&turn_context.model_info,
turn_context.model_info(),
),
unified_image_budget: unified_image_budget_enabled(
&turn_context.config.features,
&turn_context.model_info,
turn_context.model_info(),
),
include_environment_id,
}));
@@ -948,7 +950,7 @@ fn add_core_tool_sources(context: &CoreToolPlanContext<'_>, registry: &mut ToolR
fn standalone_web_search_enabled(turn_context: &TurnContext) -> bool {
namespace_tools_enabled(turn_context)
&& turn_context.provider.capabilities().web_search
&& (turn_context.model_info.use_responses_lite
&& (turn_context.model_info().use_responses_lite
|| turn_context
.config
.features
@@ -975,7 +977,7 @@ fn add_shell_tools(context: &CoreToolPlanContext<'_>, registry: &mut ToolRegistr
|| !features.enabled(Feature::ShellTool)
|| !features.enabled(Feature::UnifiedExec)
|| matches!(
turn_context.model_info.shell_type,
turn_context.model_info().shell_type,
ConfigShellToolType::Disabled
)
{
@@ -1051,7 +1053,7 @@ fn add_core_utility_tools(context: &CoreToolPlanContext<'_>, registry: &mut Tool
if !turn_context.session_source.is_non_root_agent()
&& turn_context
.model_info
.model_info()
.experimental_supported_tools
.iter()
.any(|tool| tool == "send_user_message_async")
@@ -1096,14 +1098,15 @@ fn add_core_utility_tools(context: &CoreToolPlanContext<'_>, registry: &mut Tool
));
}
if environment_mode.has_environment() && turn_context.model_info.apply_patch_tool_type.is_some()
if environment_mode.has_environment()
&& turn_context.model_info().apply_patch_tool_type.is_some()
{
let include_environment_id = matches!(environment_mode, ToolEnvironmentMode::Multiple);
registry.add(ApplyPatchHandler::new(include_environment_id));
}
if turn_context
.model_info
.model_info()
.experimental_supported_tools
.iter()
.any(|tool| tool == "test_sync_tool")
@@ -1115,11 +1118,11 @@ fn add_core_utility_tools(context: &CoreToolPlanContext<'_>, registry: &mut Tool
let include_environment_id = matches!(environment_mode, ToolEnvironmentMode::Multiple);
registry.add(ViewImageHandler::new(ViewImageToolOptions {
can_request_original_image_detail: can_request_original_image_detail(
&turn_context.model_info,
turn_context.model_info(),
),
unified_image_budget: unified_image_budget_enabled(
&turn_context.config.features,
&turn_context.model_info,
turn_context.model_info(),
),
include_environment_id,
}));
+128 -43
View File
@@ -1,3 +1,4 @@
use crate::session::tests::update_turn_settings_for_test;
use std::collections::BTreeMap;
use std::sync::Arc;
@@ -532,7 +533,9 @@ async fn internal_guardian_sessions_respect_managed_shell_restrictions() {
)
.expect("managed shell restriction should be valid");
}
Arc::make_mut(&mut turn.model_info).shell_type = shell_type;
update_turn_settings_for_test(&mut turn, |settings| {
Arc::make_mut(&mut settings.model_info).shell_type = shell_type;
});
let turn = Arc::new(turn);
let step_context = StepContext::for_test(Arc::clone(&turn));
@@ -850,7 +853,9 @@ async fn shell_family_registers_only_unified_exec_tools() {
let plan = probe(|turn| {
set_features(turn, &[Feature::ShellTool]);
set_feature(turn, Feature::ShellZshFork, /*enabled*/ false);
Arc::make_mut(&mut turn.model_info).shell_type = ConfigShellToolType::UnifiedExec;
update_turn_settings_for_test(turn, |settings| {
Arc::make_mut(&mut settings.model_info).shell_type = ConfigShellToolType::UnifiedExec;
});
})
.await;
@@ -866,7 +871,10 @@ async fn login_shell_parameter_follows_selected_environment() {
let plan = probe(|turn| {
set_feature(turn, Feature::ShellTool, /*enabled*/ true);
set_feature(turn, Feature::ShellZshFork, /*enabled*/ false);
Arc::make_mut(&mut turn.model_info).shell_type = ConfigShellToolType::UnifiedExec;
update_turn_settings_for_test(turn, |settings| {
Arc::make_mut(&mut settings.model_info).shell_type =
ConfigShellToolType::UnifiedExec;
});
update_config(turn, |config| {
config.permissions.allow_login_shell = !allow_login_shell;
});
@@ -922,7 +930,9 @@ async fn login_shell_parameter_is_available_when_any_environment_allows_it() {
async fn disabling_shell_tools_disables_command_tools_for_all_environments() {
let remote_environment = probe(|turn| {
set_feature(turn, Feature::ShellTool, /*enabled*/ false);
Arc::make_mut(&mut turn.model_info).shell_type = ConfigShellToolType::UnifiedExec;
update_turn_settings_for_test(turn, |settings| {
Arc::make_mut(&mut settings.model_info).shell_type = ConfigShellToolType::UnifiedExec;
});
let TurnEnvironmentState::Ready(environment) = turn
.environments
@@ -946,7 +956,9 @@ async fn disabling_shell_tools_disables_command_tools_for_all_environments() {
let multiple_local_environments = probe(|turn| {
set_feature(turn, Feature::ShellTool, /*enabled*/ false);
Arc::make_mut(&mut turn.model_info).shell_type = ConfigShellToolType::UnifiedExec;
update_turn_settings_for_test(turn, |settings| {
Arc::make_mut(&mut settings.model_info).shell_type = ConfigShellToolType::UnifiedExec;
});
duplicate_primary_environment(turn);
})
.await;
@@ -988,7 +1000,9 @@ async fn shell_zsh_fork_keeps_unified_exec_available() {
set_features(turn, &[Feature::ShellTool]);
set_feature(turn, Feature::ShellZshFork, /*enabled*/ true);
set_feature(turn, Feature::UnifiedExecZshFork, /*enabled*/ false);
Arc::make_mut(&mut turn.model_info).shell_type = ConfigShellToolType::UnifiedExec;
update_turn_settings_for_test(turn, |settings| {
Arc::make_mut(&mut settings.model_info).shell_type = ConfigShellToolType::UnifiedExec;
});
})
.await;
@@ -1004,7 +1018,9 @@ async fn shell_zsh_fork_keeps_unified_exec_available() {
Feature::UnifiedExecZshFork,
],
);
Arc::make_mut(&mut turn.model_info).shell_type = ConfigShellToolType::UnifiedExec;
update_turn_settings_for_test(turn, |settings| {
Arc::make_mut(&mut settings.model_info).shell_type = ConfigShellToolType::UnifiedExec;
});
})
.await;
@@ -1116,8 +1132,10 @@ async fn environment_count_controls_environment_backed_tools() {
turn.environments.environments.clear();
set_feature(turn, Feature::ShellTool, /*enabled*/ true);
set_feature(turn, Feature::RequestPermissionsTool, /*enabled*/ true);
Arc::make_mut(&mut turn.model_info).apply_patch_tool_type =
Some(ApplyPatchToolType::Freeform);
update_turn_settings_for_test(turn, |settings| {
Arc::make_mut(&mut settings.model_info).apply_patch_tool_type =
Some(ApplyPatchToolType::Freeform);
});
})
.await;
no_environment.assert_visible_lacks(&[
@@ -1139,8 +1157,10 @@ async fn environment_count_controls_environment_backed_tools() {
duplicate_primary_environment(turn);
set_feature(turn, Feature::ShellTool, /*enabled*/ true);
set_feature(turn, Feature::RequestPermissionsTool, /*enabled*/ true);
Arc::make_mut(&mut turn.model_info).apply_patch_tool_type =
Some(ApplyPatchToolType::Freeform);
update_turn_settings_for_test(turn, |settings| {
Arc::make_mut(&mut settings.model_info).apply_patch_tool_type =
Some(ApplyPatchToolType::Freeform);
});
})
.await;
multiple_environments.assert_visible_contains(&[
@@ -1165,7 +1185,10 @@ async fn environment_count_controls_environment_backed_tools() {
#[tokio::test]
async fn environment_tools_follow_the_step_context() {
let (_session, mut turn) = make_session_and_context().await;
Arc::make_mut(&mut turn.model_info).apply_patch_tool_type = Some(ApplyPatchToolType::Freeform);
update_turn_settings_for_test(&mut turn, |settings| {
Arc::make_mut(&mut settings.model_info).apply_patch_tool_type =
Some(ApplyPatchToolType::Freeform);
});
let environments = turn.environments.clone();
turn.environments.environments.clear();
@@ -1295,7 +1318,9 @@ async fn mcp_and_tool_search_follow_direct_and_deferred_tool_exposure() {
let missing_model_capability = probe_with(
|turn| {
Arc::make_mut(&mut turn.model_info).supports_search_tool = false;
update_turn_settings_for_test(turn, |settings| {
Arc::make_mut(&mut settings.model_info).supports_search_tool = false;
});
},
searchable_mcp(),
)
@@ -1304,7 +1329,9 @@ async fn mcp_and_tool_search_follow_direct_and_deferred_tool_exposure() {
let missing_deferred_tools = probe(|turn| {
set_feature(turn, Feature::Collab, /*enabled*/ false);
Arc::make_mut(&mut turn.model_info).supports_search_tool = true;
update_turn_settings_for_test(turn, |settings| {
Arc::make_mut(&mut settings.model_info).supports_search_tool = true;
});
})
.await;
missing_deferred_tools.assert_visible_lacks(&["tool_search"]);
@@ -1316,7 +1343,9 @@ async fn mcp_and_tool_search_follow_direct_and_deferred_tool_exposure() {
let bedrock_namespace_capability = probe_with(
|turn| {
Arc::make_mut(&mut turn.model_info).supports_search_tool = true;
update_turn_settings_for_test(turn, |settings| {
Arc::make_mut(&mut settings.model_info).supports_search_tool = true;
});
use_bedrock_provider(turn);
},
searchable_mcp(),
@@ -1326,7 +1355,9 @@ async fn mcp_and_tool_search_follow_direct_and_deferred_tool_exposure() {
let enabled = probe_with(
|turn| {
Arc::make_mut(&mut turn.model_info).supports_search_tool = true;
update_turn_settings_for_test(turn, |settings| {
Arc::make_mut(&mut settings.model_info).supports_search_tool = true;
});
},
searchable_mcp(),
)
@@ -1340,7 +1371,9 @@ async fn mcp_and_tool_search_follow_direct_and_deferred_tool_exposure() {
let reserved_namespace = probe_with(
|turn| {
set_feature(turn, Feature::CodeMode, /*enabled*/ true);
Arc::make_mut(&mut turn.model_info).supports_search_tool = true;
update_turn_settings_for_test(turn, |settings| {
Arc::make_mut(&mut settings.model_info).supports_search_tool = true;
});
},
ToolPlanInputs {
tool_runtimes: vec![
@@ -1392,8 +1425,10 @@ async fn tool_namespaces_info_is_opt_in_and_tracks_mcp_exposure() {
config.tool_registry.turn_metadata_includes_tool_info = enabled;
});
set_feature(turn, Feature::CodeMode, /*enabled*/ true);
Arc::make_mut(&mut turn.model_info).supports_search_tool = true;
Arc::make_mut(&mut turn.model_info).use_responses_lite = true;
update_turn_settings_for_test(turn, |settings| {
Arc::make_mut(&mut settings.model_info).supports_search_tool = true;
Arc::make_mut(&mut settings.model_info).use_responses_lite = true;
});
metadata_state = Some(Arc::clone(&turn.turn_metadata_state));
},
ToolPlanInputs {
@@ -1467,7 +1502,9 @@ async fn strict_namespace_ownership_requires_tool_namespace_inventory_opt_in() {
config.tool_registry.error_on_tool_collisions = true;
config.tool_registry.turn_metadata_includes_tool_info = enabled;
});
Arc::make_mut(&mut turn.model_info).use_responses_lite = true;
update_turn_settings_for_test(&mut turn, |settings| {
Arc::make_mut(&mut settings.model_info).use_responses_lite = true;
});
let step_context = StepContext::for_test(Arc::new(turn));
let mut registry = build_core_tool_registry(
step_context.turn.as_ref(),
@@ -1522,7 +1559,10 @@ async fn unified_tool_runtimes_preserve_source_order_and_collision_priority() {
|turn| {
set_features(turn, &[Feature::ShellTool]);
set_feature(turn, Feature::ShellZshFork, /*enabled*/ false);
Arc::make_mut(&mut turn.model_info).shell_type = ConfigShellToolType::UnifiedExec;
update_turn_settings_for_test(turn, |settings| {
Arc::make_mut(&mut settings.model_info).shell_type =
ConfigShellToolType::UnifiedExec;
});
},
ToolPlanInputs {
tool_runtimes: vec![mcp_runtime(
@@ -1718,7 +1758,9 @@ async fn strict_tool_collisions_reject_external_and_synthetic_duplicates() {
if code_mode_enabled {
set_feature(&mut turn, Feature::CodeMode, /*enabled*/ true);
}
Arc::make_mut(&mut turn.model_info).supports_search_tool = search_enabled;
update_turn_settings_for_test(&mut turn, |settings| {
Arc::make_mut(&mut settings.model_info).supports_search_tool = search_enabled;
});
let turn = Arc::new(turn);
let step_context = StepContext::for_test(Arc::clone(&turn));
let mut registry = build_core_tool_registry(
@@ -1876,8 +1918,10 @@ async fn code_mode_uses_the_first_normalized_tool_identity() {
if code_mode_only {
set_feature(turn, Feature::CodeModeOnly, /*enabled*/ true);
}
Arc::make_mut(&mut turn.model_info).supports_search_tool = true;
Arc::make_mut(&mut turn.model_info).use_responses_lite = true;
update_turn_settings_for_test(turn, |settings| {
Arc::make_mut(&mut settings.model_info).supports_search_tool = true;
Arc::make_mut(&mut settings.model_info).use_responses_lite = true;
});
metadata_state = Some(Arc::clone(&turn.turn_metadata_state));
},
ToolPlanInputs {
@@ -1960,7 +2004,9 @@ async fn code_mode_uses_the_first_normalized_tool_identity() {
async fn deferred_extension_tools_are_discoverable_with_tool_search() {
let plan = probe_with(
|turn| {
Arc::make_mut(&mut turn.model_info).supports_search_tool = true;
update_turn_settings_for_test(turn, |settings| {
Arc::make_mut(&mut settings.model_info).supports_search_tool = true;
});
},
ToolPlanInputs {
extension_tool_executors: vec![Arc::new(DeferredExtensionTool)],
@@ -1980,7 +2026,9 @@ async fn tool_search_cache_rebuilds_when_deferred_sources_change() {
let cache = ToolSearchHandlerCache::default();
let (_session, mut first_turn) = make_session_and_context().await;
Arc::make_mut(&mut first_turn.model_info).supports_search_tool = true;
update_turn_settings_for_test(&mut first_turn, |settings| {
Arc::make_mut(&mut settings.model_info).supports_search_tool = true;
});
let first_turn = Arc::new(first_turn);
let first_step_context = StepContext::for_test(Arc::clone(&first_turn));
let mut first_registry = build_core_tool_registry(
@@ -2001,7 +2049,9 @@ async fn tool_search_cache_rebuilds_when_deferred_sources_change() {
let first_plan = ToolPlanProbe::from_router(first_router);
let (_session, mut second_turn) = make_session_and_context().await;
Arc::make_mut(&mut second_turn.model_info).supports_search_tool = true;
update_turn_settings_for_test(&mut second_turn, |settings| {
Arc::make_mut(&mut settings.model_info).supports_search_tool = true;
});
let second_turn = Arc::new(second_turn);
let second_step_context = StepContext::for_test(Arc::clone(&second_turn));
let mut second_registry = build_core_tool_registry(
@@ -2048,7 +2098,9 @@ async fn tool_search_cache_rebuilds_when_deferred_world_state_changes() {
for world_state_enabled in [false, true, false] {
let (_session, mut turn) = make_session_and_context().await;
Arc::make_mut(&mut turn.model_info).supports_search_tool = true;
update_turn_settings_for_test(&mut turn, |settings| {
Arc::make_mut(&mut settings.model_info).supports_search_tool = true;
});
set_feature(
&mut turn,
Feature::DeferredToolWorldState,
@@ -2161,7 +2213,9 @@ async fn request_plugin_install_requires_all_discovery_features() {
async fn request_plugin_install_stays_visible_without_tool_search() {
let plan = probe_with(
|turn| {
Arc::make_mut(&mut turn.model_info).supports_search_tool = false;
update_turn_settings_for_test(turn, |settings| {
Arc::make_mut(&mut settings.model_info).supports_search_tool = false;
});
set_features(
turn,
&[Feature::ToolSuggest, Feature::Apps, Feature::Plugins],
@@ -2297,7 +2351,9 @@ async fn code_mode_only_exposes_configured_dynamic_namespace_directly() {
let plan = probe_with(
|turn| {
set_features(turn, &[Feature::CodeMode, Feature::CodeModeOnly]);
Arc::make_mut(&mut turn.model_info).supports_search_tool = true;
update_turn_settings_for_test(turn, |settings| {
Arc::make_mut(&mut settings.model_info).supports_search_tool = true;
});
update_config(turn, |config| {
config.code_mode.direct_only_tool_namespaces = vec!["direct_only".to_string()];
});
@@ -2361,7 +2417,9 @@ async fn excluded_deferred_namespaces_do_not_enable_nested_tool_guidance() {
|turn| {
set_features(turn, &[Feature::CodeMode, Feature::CodeModeOnly]);
set_feature(turn, Feature::Collab, /*enabled*/ false);
Arc::make_mut(&mut turn.model_info).supports_search_tool = true;
update_turn_settings_for_test(turn, |settings| {
Arc::make_mut(&mut settings.model_info).supports_search_tool = true;
});
update_config(turn, |config| {
config.code_mode.excluded_tool_namespaces = vec!["excluded".to_string()];
});
@@ -2615,7 +2673,9 @@ async fn multi_agent_v2_can_disable_wait_agent() {
async fn tool_mode_selector_overrides_feature_flags() {
let direct = probe(|turn| {
set_features(turn, &[Feature::CodeMode, Feature::CodeModeOnly]);
Arc::make_mut(&mut turn.model_info).tool_mode = Some(ToolMode::Direct);
update_turn_settings_for_test(turn, |settings| {
Arc::make_mut(&mut settings.model_info).tool_mode = Some(ToolMode::Direct);
});
})
.await;
direct.assert_visible_lacks(&[
@@ -2627,7 +2687,9 @@ async fn tool_mode_selector_overrides_feature_flags() {
#[tokio::test]
async fn v1_multi_agent_tools_defer_when_tool_search_available() {
let plan = probe(|turn| {
Arc::make_mut(&mut turn.model_info).supports_search_tool = true;
update_turn_settings_for_test(turn, |settings| {
Arc::make_mut(&mut settings.model_info).supports_search_tool = true;
});
set_feature(turn, Feature::Collab, /*enabled*/ true);
set_feature(turn, Feature::MultiAgentV2, /*enabled*/ false);
})
@@ -2770,8 +2832,11 @@ async fn multi_agent_v2_bedrock_workers_only_delegate_when_model_supports_v2() {
config.multi_agent_v2.tool_namespace = Some("agents".to_string());
});
use_bedrock_provider(turn);
Arc::make_mut(&mut turn.model_info).slug = model.to_string();
Arc::make_mut(&mut turn.model_info).multi_agent_version = model_multi_agent_version;
update_turn_settings_for_test(turn, |settings| {
Arc::make_mut(&mut settings.model_info).slug = model.to_string();
Arc::make_mut(&mut settings.model_info).multi_agent_version =
model_multi_agent_version;
});
turn.session_source = SessionSource::SubAgent(SubAgentSource::ThreadSpawn {
parent_thread_id: ThreadId::new(),
depth: 1,
@@ -2886,7 +2951,10 @@ async fn hosted_web_search_and_standalone_image_generation_follow_runtime_gates(
let image_generation = probe_with(
|turn| {
use_chatgpt_auth(turn);
Arc::make_mut(&mut turn.model_info).input_modalities = vec![InputModality::Image];
update_turn_settings_for_test(turn, |settings| {
Arc::make_mut(&mut settings.model_info).input_modalities =
vec![InputModality::Image];
});
},
ToolPlanInputs {
extension_tool_executors: vec![image_generation_tool.clone()],
@@ -2900,7 +2968,10 @@ async fn hosted_web_search_and_standalone_image_generation_follow_runtime_gates(
|turn| {
use_chatgpt_auth(turn);
set_feature(turn, Feature::ImageGeneration, /*enabled*/ false);
Arc::make_mut(&mut turn.model_info).input_modalities = vec![InputModality::Image];
update_turn_settings_for_test(turn, |settings| {
Arc::make_mut(&mut settings.model_info).input_modalities =
vec![InputModality::Image];
});
},
ToolPlanInputs {
extension_tool_executors: vec![image_generation_tool.clone()],
@@ -2913,7 +2984,9 @@ async fn hosted_web_search_and_standalone_image_generation_follow_runtime_gates(
let text_only_model = probe_with(
|turn| {
use_chatgpt_auth(turn);
Arc::make_mut(&mut turn.model_info).input_modalities = vec![];
update_turn_settings_for_test(turn, |settings| {
Arc::make_mut(&mut settings.model_info).input_modalities = vec![];
});
},
ToolPlanInputs {
extension_tool_executors: vec![image_generation_tool.clone()],
@@ -2926,7 +2999,10 @@ async fn hosted_web_search_and_standalone_image_generation_follow_runtime_gates(
let unsupported_provider = probe_with(
|turn| {
use_bedrock_provider(turn);
Arc::make_mut(&mut turn.model_info).input_modalities = vec![InputModality::Image];
update_turn_settings_for_test(turn, |settings| {
Arc::make_mut(&mut settings.model_info).input_modalities =
vec![InputModality::Image];
});
},
ToolPlanInputs {
extension_tool_executors: vec![image_generation_tool],
@@ -2938,7 +3014,10 @@ async fn hosted_web_search_and_standalone_image_generation_follow_runtime_gates(
let live_web_search = probe(|turn| {
set_web_search_mode(turn, WebSearchMode::Live);
Arc::make_mut(&mut turn.model_info).web_search_tool_type = WebSearchToolType::TextAndImage;
update_turn_settings_for_test(turn, |settings| {
Arc::make_mut(&mut settings.model_info).web_search_tool_type =
WebSearchToolType::TextAndImage;
});
})
.await;
assert_eq!(
@@ -2957,7 +3036,9 @@ async fn hosted_web_search_and_standalone_image_generation_follow_runtime_gates(
use_chatgpt_auth(turn);
set_features(turn, &[Feature::CodeModeOnly, Feature::MultiAgentV2]);
set_web_search_mode(turn, WebSearchMode::Live);
Arc::make_mut(&mut turn.model_info).input_modalities = vec![InputModality::Image];
update_turn_settings_for_test(turn, |settings| {
Arc::make_mut(&mut settings.model_info).input_modalities = vec![InputModality::Image];
});
})
.await;
assert_eq!(
@@ -3034,7 +3115,9 @@ async fn hosted_web_search_and_standalone_image_generation_follow_runtime_gates(
let bedrock_cached_web_search = probe(|turn| {
use_bedrock_provider(turn);
Arc::make_mut(&mut turn.model_info).web_search_tool_type = WebSearchToolType::Text;
update_turn_settings_for_test(turn, |settings| {
Arc::make_mut(&mut settings.model_info).web_search_tool_type = WebSearchToolType::Text;
});
})
.await;
assert_eq!(
@@ -3053,7 +3136,9 @@ async fn hosted_web_search_and_standalone_image_generation_follow_runtime_gates(
set_feature(turn, Feature::StandaloneWebSearch, /*enabled*/ true);
set_web_search_mode(turn, WebSearchMode::Cached);
use_bedrock_provider(turn);
Arc::make_mut(&mut turn.model_info).web_search_tool_type = WebSearchToolType::Text;
update_turn_settings_for_test(turn, |settings| {
Arc::make_mut(&mut settings.model_info).web_search_tool_type = WebSearchToolType::Text;
});
})
.await;
bedrock_with_standalone_web_search.assert_visible_contains(&["web_search"]);