Enforce managed provider requirements on existing app-server threads (#44944)

## Why

Existing threads retain their model provider configuration, which can stop matching managed requirements after those requirements change.

## What changed

- Check retained providers against current managed `model_provider` and `model_providers` requirements before turn start/steer, review, compaction, manual queue start, and active goal updates. Reject requests when requirements cannot be loaded or no longer match; provider mismatches prompt users to restart Codex.
- Load managed requirements independently of user, project, system defaults, and thread configuration, and resolve Bedrock provider overrides before comparison.
- Keep interrupt, realtime stop, and goal pause/clear available. Realtime connections use separate routing and are outside these checks.
- Make detached reviews inherit their parent thread's configuration.

## Testing

Add unit and integration coverage for provider selection and definition changes, Bedrock overrides, requirement load failures, unchanged queue and goal state after rejection, and continued operation after local configuration changes. Extend detached review coverage to verify inheritance of the parent's provider route.

GitOrigin-RevId: 21abf08ad2bcc2ea4698209fa33a17485eed4740
This commit is contained in:
alexsong-oai authored and copyberry committed 2026-09-12 00:12:26 +00:00
1 parent d43f1e7eb2
commit 39d193d72d
17 files changed
+917 -88

No files matched your search

@@ -26,6 +26,7 @@ pub(crate) struct ThreadGoalRequestProcessor {
thread_state_manager: ThreadStateManager,
state_db: Option<StateDbHandle>,
goal_service: Arc<GoalService>,
config_manager: ConfigManager,
}
impl ThreadGoalRequestProcessor {
@@ -36,6 +37,7 @@ impl ThreadGoalRequestProcessor {
thread_state_manager: ThreadStateManager,
state_db: Option<StateDbHandle>,
goal_service: Arc<GoalService>,
config_manager: ConfigManager,
) -> Self {
Self {
thread_manager,
@@ -44,6 +46,7 @@ impl ThreadGoalRequestProcessor {
thread_state_manager,
state_db,
goal_service,
config_manager,
}
}
@@ -135,6 +138,26 @@ impl ThreadGoalRequestProcessor {
.await?;
self.reconcile_thread_goal_rollout(thread_id, &state_db)
.await?;
// Active goals can immediately inject an objective or start an idle turn.
// Stopping a goal must remain possible after managed policy changes.
let existing_goal = self
.goal_service
.get_thread_goal(&state_db, thread_id)
.await
.map_err(goal_service_error)?;
let resulting_status = params
.status
.map(ThreadGoalStatus::to_core)
.or_else(|| existing_goal.as_ref().map(|goal| goal.status))
.unwrap_or(codex_protocol::protocol::ThreadGoalStatus::Active);
if resulting_status == codex_protocol::protocol::ThreadGoalStatus::Active
&& let Ok(thread) = self.thread_manager.get_thread(thread_id).await
{
self.config_manager
.check_thread_model_provider(thread.config().await.as_ref())
.await
.map_err(|error| config_load_error(&error))?;
}
let max_goal_token_budget = match self.thread_manager.get_thread(thread_id).await {
Ok(thread) => thread.config().await.max_goal_token_budget,
Err(_) => self.config.max_goal_token_budget,
@@ -2329,6 +2329,10 @@ impl ThreadRequestProcessor {
let (_, thread) = self.load_thread(&thread_id).await?;
ensure_direct_input_allowed(thread.as_ref()).await?;
self.config_manager
.check_thread_model_provider(thread.config().await.as_ref())
.await
.map_err(|error| config_load_error(&error))?;
self.submit_core_op(request_id, thread.as_ref(), Op::Compact)
.await
.map_err(|err| internal_error(format!("failed to start compaction: {err}")))?;
@@ -1,3 +1,4 @@
use crate::config_manager::ConfigManager;
use std::sync::Arc;
use crate::error_code::internal_error;
@@ -38,6 +39,7 @@ use codex_thread_store::ThreadStore;
use codex_thread_store::ThreadStoreError;
use super::TurnRequestProcessor;
use super::config_load_error;
use super::thread_input::DIRECT_INPUT_TO_MULTI_AGENT_V2_SUBAGENT_ERROR;
use super::thread_input::can_accept_direct_input;
use super::thread_processor::THREAD_LIST_DEFAULT_LIMIT;
@@ -51,6 +53,7 @@ pub(crate) struct ThreadQueueRequestProcessor {
thread_manager: Arc<ThreadManager>,
thread_store: Arc<dyn ThreadStore>,
outgoing: Arc<OutgoingMessageSender>,
config_manager: ConfigManager,
service: Option<Arc<QueuedItemService>>,
}
@@ -59,12 +62,14 @@ impl ThreadQueueRequestProcessor {
thread_manager: Arc<ThreadManager>,
thread_store: Arc<dyn ThreadStore>,
outgoing: Arc<OutgoingMessageSender>,
config_manager: ConfigManager,
service: Option<Arc<QueuedItemService>>,
) -> Self {
Self {
thread_manager,
thread_store,
outgoing,
config_manager,
service,
}
}
@@ -187,6 +192,10 @@ impl ThreadQueueRequestProcessor {
ensure_direct_input_allowed(loaded_thread.as_deref(), &source)?;
let thread = loaded_thread
.ok_or_else(|| invalid_request("resume the thread before starting a queued message"))?;
self.config_manager
.check_thread_model_provider(thread.config().await.as_ref())
.await
.map_err(|error| config_load_error(&error))?;
let submission = self
.service()?
.start(
@@ -531,6 +531,10 @@ impl TurnRequestProcessor {
})?;
self.ensure_direct_input_allowed(&request_id, thread.as_ref())
.await?;
self.config_manager
.check_thread_model_provider(thread.config().await.as_ref())
.await
.map_err(|error| config_load_error(&error))?;
if let Some(tool_output) = &params.tool_output {
if !params.input.is_empty() {
return Err(invalid_request(
@@ -1032,6 +1036,10 @@ impl TurnRequestProcessor {
})?;
self.ensure_direct_input_allowed(request_id, thread.as_ref())
.await?;
self.config_manager
.check_thread_model_provider(thread.config().await.as_ref())
.await
.map_err(|error| config_load_error(&error))?;
if params.expected_turn_id.is_empty() {
return Err(invalid_request("expectedTurnId must not be empty"));
@@ -1457,7 +1465,7 @@ impl TurnRequestProcessor {
"paginated threads do not support detached review",
));
}
let mut config = self.config.as_ref().clone();
let mut config = parent_thread.config().await.as_ref().clone();
if let Some(review_model) = &config.review_model {
config.model = Some(review_model.clone());
}
@@ -1550,6 +1558,10 @@ impl TurnRequestProcessor {
let (_, parent_thread) = self.load_thread(&thread_id).await?;
self.ensure_direct_input_allowed(request_id, parent_thread.as_ref())
.await?;
self.config_manager
.check_thread_model_provider(parent_thread.config().await.as_ref())
.await
.map_err(|error| config_load_error(&error))?;
let (review_request, display_text, target_prompt) =
Self::review_request_from_target(target)?;
match delivery.unwrap_or(ApiReviewDelivery::Inline).to_core() {