Keep active-turn model settings stable across updates (#38785)

## Why

Thread settings can change while a turn is still active, including between sampling requests. Those updates should apply to the next turn instead of changing the model configuration partway through the current turn.

## What changed

- Snapshot the model, reasoning settings, service tier, approval settings, and model-attributed telemetry in `StepContext`.
- Build prompts, model requests, world state, tracing, and startup prewarms from that step-scoped snapshot.
- Share immutable model metadata between turn and step contexts.

## Testing

Added an integration test that pauses an active turn, updates its thread settings, and verifies that all requests in the active turn retain the original settings while the next turn uses the updates.

GitOrigin-RevId: c51352218e463dcc9b7338566d16742292c49fbf
This commit is contained in:
joeflorencio-openai authored and copyberry committed 2026-08-15 16:58:08 +00:00
1 parent c4941302c7
commit 00f6a8a60e
13 files changed
+307 -104

No files matched your search

+22
View File
@@ -7,10 +7,32 @@ use crate::tools::router::ToolRouter;
use codex_exec_server::ExecutorCapabilityDiscoverySnapshot;
use codex_exec_server::ResolvedSelectedCapabilityRoot;
use codex_mcp::McpBinding;
use codex_otel::SessionTelemetry;
use codex_protocol::config_types::ApprovalsReviewer;
use codex_protocol::config_types::ReasoningSummary;
use codex_protocol::openai_models::ModelInfo;
use codex_protocol::openai_models::ReasoningEffort;
use codex_protocol::protocol::AskForApproval;
/// Request-scoped state that may change between model sampling requests.
pub(crate) struct StepContext {
pub(crate) turn: Arc<TurnContext>,
/// Concrete model and capabilities used by this sampling request.
pub(crate) model_info: Arc<ModelInfo>,
/// Reasoning effort selected for this sampling request.
pub(crate) reasoning_effort: Option<ReasoningEffort>,
/// Reasoning summary resolved for this sampling request.
pub(crate) reasoning_summary: ReasoningSummary,
/// Effective service tier supported by this sampling request's model.
pub(crate) service_tier: Option<String>,
/// Effective approval policy used by this sampling request's tool actions.
/// Model-specific Guardian requirements can change this during a model switch.
pub(crate) approval_policy: AskForApproval,
/// Effective reviewer selected for this sampling request's approvals.
/// Model-specific Guardian requirements can change this during a model switch.
pub(crate) approvals_reviewer: ApprovalsReviewer,
/// Telemetry context tagged with this sampling request's model.
pub(crate) session_telemetry: SessionTelemetry,
pub(crate) environments: TurnEnvironmentSnapshot,
/// Capability roots bound to ready environments in this exact step.
pub(crate) selected_capability_roots: Vec<ResolvedSelectedCapabilityRoot>,