mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
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:
1 parent
ba6cf9c692
commit
68301fa45f
68 files changed
+1393
-516
No files matched your search
@@ -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()
|
||||
|
||||
@@ -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())
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in new issue
Block a user