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
+13 -13
View File
@@ -145,7 +145,7 @@ pub(crate) async fn run_pending_session_start_hooks(
#[allow(deprecated)]
cwd: turn_context.cwd.clone(),
transcript_path: sess.hook_transcript_path().await,
model: turn_context.model_info.slug.clone(),
model: turn_context.model_info().slug.clone(),
permission_mode: hook_permission_mode(turn_context),
target,
};
@@ -187,7 +187,7 @@ pub(crate) async fn run_pre_tool_use_hooks(
#[allow(deprecated)]
cwd: turn_context.cwd.clone(),
transcript_path: sess.hook_transcript_path().await,
model: turn_context.model_info.slug.clone(),
model: turn_context.model_info().slug.clone(),
permission_mode: hook_permission_mode(turn_context),
tool_name: tool_name.name().to_string(),
matcher_aliases: tool_name.matcher_aliases().to_vec(),
@@ -248,7 +248,7 @@ pub(crate) async fn run_permission_request_hooks(
#[allow(deprecated)]
cwd: turn_context.cwd.to_path_buf(),
transcript_path: sess.hook_transcript_path().await,
model: turn_context.model_info.slug.clone(),
model: turn_context.model_info().slug.clone(),
permission_mode: hook_permission_mode(turn_context),
tool_name: payload.tool_name.name().to_string(),
matcher_aliases: payload.tool_name.matcher_aliases().to_vec(),
@@ -290,7 +290,7 @@ pub(crate) async fn run_post_tool_use_hooks(
#[allow(deprecated)]
cwd: turn_context.cwd.clone(),
transcript_path: sess.hook_transcript_path().await,
model: turn_context.model_info.slug.clone(),
model: turn_context.model_info().slug.clone(),
permission_mode: hook_permission_mode(turn_context),
tool_name,
matcher_aliases,
@@ -366,8 +366,8 @@ pub(crate) async fn run_turn_stop_hooks(
let request_metadata = turn_context
.turn_metadata_state
.current_meta_value_for_mcp_request(McpTurnMetadataContext {
model: step_context.model_info.slug.as_str(),
reasoning_effort: step_context.reasoning_effort.clone(),
model: step_context.settings.model_info.slug.as_str(),
reasoning_effort: step_context.settings.reasoning_effort().cloned(),
})
.map(|turn_metadata| {
serde_json::Map::from_iter([(
@@ -381,7 +381,7 @@ pub(crate) async fn run_turn_stop_hooks(
#[allow(deprecated)]
cwd: turn_context.cwd.clone(),
transcript_path,
model: turn_context.model_info.slug.clone(),
model: turn_context.model_info().slug.clone(),
permission_mode: hook_permission_mode(turn_context),
request_metadata,
stop_hook_active,
@@ -450,7 +450,7 @@ pub(crate) async fn run_turn_interrupt_hooks(sess: &Arc<Session>, turn_context:
#[allow(deprecated)]
cwd: turn_context.cwd.clone(),
transcript_path: sess.hook_transcript_path().await,
model: turn_context.model_info.slug.clone(),
model: turn_context.model_info().slug.clone(),
permission_mode: hook_permission_mode(turn_context),
};
if let Err(err) = sess.flush_rollout().await {
@@ -474,7 +474,7 @@ pub(crate) async fn run_pre_compact_hooks(
#[allow(deprecated)]
cwd: turn_context.cwd.clone(),
transcript_path: sess.hook_transcript_path().await,
model: turn_context.model_info.slug.clone(),
model: turn_context.model_info().slug.clone(),
trigger: compaction_trigger_label(trigger).to_string(),
};
let preview_runs = sess.hooks().preview_pre_compact(&request);
@@ -511,7 +511,7 @@ pub(crate) async fn run_post_compact_hooks(
#[allow(deprecated)]
cwd: turn_context.cwd.clone(),
transcript_path: sess.hook_transcript_path().await,
model: turn_context.model_info.slug.clone(),
model: turn_context.model_info().slug.clone(),
trigger: compaction_trigger_label(trigger).to_string(),
};
let preview_runs = sess.hooks().preview_post_compact(&request);
@@ -608,7 +608,7 @@ pub(crate) async fn inspect_pending_input(
#[allow(deprecated)]
cwd: turn_context.cwd.clone(),
transcript_path: sess.hook_transcript_path().await,
model: turn_context.model_info.slug.clone(),
model: turn_context.model_info().slug.clone(),
permission_mode: hook_permission_mode(turn_context),
prompt: UserMessageItem::new(content).message(),
};
@@ -845,7 +845,7 @@ fn hook_run_analytics_payload(
) -> (codex_analytics::TrackEventsContext, HookRunFact) {
(
build_track_events_context(
turn_context.model_info.slug.clone(),
turn_context.model_info().slug.clone(),
thread_id,
completed
.turn_id
@@ -1071,7 +1071,7 @@ mod tests {
assert_eq!(tracking.thread_id, "thread-123");
assert_eq!(tracking.turn_id, "turn-from-hook");
assert_eq!(tracking.model_slug, turn_context.model_info.slug);
assert_eq!(tracking.model_slug, turn_context.model_info().slug);
assert_eq!(hook.event_name, HookEventName::Stop);
assert_eq!(hook.handler_type, HookHandlerType::Command);
assert_eq!(hook.execution_mode, HookExecutionMode::Sync);