mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
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:
1 parent
d43f1e7eb2
commit
39d193d72d
17 files changed
+917
-88
No files matched your search
@@ -5,6 +5,7 @@ use codex_config::ConfigLayerStack;
|
||||
use codex_config::LoaderOverrides;
|
||||
use codex_config::ThreadConfigLoader;
|
||||
use codex_config::loader::load_config_layers_state;
|
||||
use codex_config::loader::load_managed_requirements_state;
|
||||
use codex_core::config::Config;
|
||||
use codex_core::config::ConfigBuilder;
|
||||
use codex_core::config::ConfigOverrides;
|
||||
@@ -12,6 +13,10 @@ use codex_exec_server::LOCAL_FS;
|
||||
use codex_features::feature_for_key;
|
||||
use codex_login::AuthManager;
|
||||
use codex_login::default_client::set_default_client_residency_requirement;
|
||||
use codex_model_provider_info::AMAZON_BEDROCK_PROVIDER_ID;
|
||||
use codex_model_provider_info::AMAZON_BEDROCK_RUNTIME_PROVIDER_ID;
|
||||
use codex_model_provider_info::built_in_model_providers;
|
||||
use codex_model_provider_info::merge_configured_model_providers;
|
||||
use codex_utils_absolute_path::AbsolutePathBuf;
|
||||
use codex_utils_json_to_toml::json_to_toml;
|
||||
use std::collections::BTreeMap;
|
||||
@@ -25,6 +30,12 @@ use toml::Value as TomlValue;
|
||||
use tracing::instrument;
|
||||
use tracing::warn;
|
||||
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
#[error(
|
||||
"Your organization's required model provider settings changed. Restart Codex to apply them; this request was not sent"
|
||||
)]
|
||||
pub(crate) struct ModelProviderRequirementsChanged;
|
||||
|
||||
/// Shared app-server entry point for loading effective Codex configuration.
|
||||
#[derive(Clone)]
|
||||
pub(crate) struct ConfigManager {
|
||||
@@ -167,6 +178,62 @@ impl ConfigManager {
|
||||
Ok(config)
|
||||
}
|
||||
|
||||
/// Checks the retained session route against current managed provider requirements.
|
||||
pub(crate) async fn check_thread_model_provider(
|
||||
&self,
|
||||
current: &Config,
|
||||
) -> std::io::Result<()> {
|
||||
// Existing threads retain their session route; only managed
|
||||
// requirements can invalidate it.
|
||||
let requirements = load_managed_requirements_state(
|
||||
LOCAL_FS.as_ref(),
|
||||
&self.codex_home,
|
||||
codex_config::ConfigLoadOptions {
|
||||
loader_overrides: self.loader_overrides.clone(),
|
||||
strict_config: self.strict_config,
|
||||
cloud_config_bundle: self.current_cloud_config_bundle(),
|
||||
},
|
||||
)
|
||||
.await?;
|
||||
let selection_changed = requirements
|
||||
.model_provider
|
||||
.as_ref()
|
||||
.is_some_and(|provider_id| provider_id != ¤t.model_provider_id);
|
||||
let required_provider = requirements
|
||||
.model_providers
|
||||
.as_ref()
|
||||
.and_then(|providers| providers.get(¤t.model_provider_id))
|
||||
.cloned();
|
||||
let required_provider = match required_provider {
|
||||
Some(provider)
|
||||
if matches!(
|
||||
current.model_provider_id.as_str(),
|
||||
AMAZON_BEDROCK_PROVIDER_ID | AMAZON_BEDROCK_RUNTIME_PROVIDER_ID
|
||||
) =>
|
||||
{
|
||||
// Bedrock requirements contain overrides of the built-in provider.
|
||||
merge_configured_model_providers(
|
||||
built_in_model_providers(/*openai_base_url*/ None),
|
||||
HashMap::from([(current.model_provider_id.clone(), provider)]),
|
||||
)
|
||||
.map_err(|message| std::io::Error::new(std::io::ErrorKind::InvalidData, message))?
|
||||
.remove(¤t.model_provider_id)
|
||||
}
|
||||
Some(provider) => Some(provider),
|
||||
None => None,
|
||||
};
|
||||
let definition_changed = required_provider
|
||||
.as_ref()
|
||||
.is_some_and(|provider| provider != ¤t.model_provider);
|
||||
if selection_changed || definition_changed {
|
||||
return Err(std::io::Error::new(
|
||||
std::io::ErrorKind::PermissionDenied,
|
||||
ModelProviderRequirementsChanged,
|
||||
));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) async fn load_default_config(&self) -> std::io::Result<Config> {
|
||||
let mut loader_overrides = self.loader_overrides.clone();
|
||||
loader_overrides.ignore_user_config = true;
|
||||
@@ -326,6 +393,10 @@ impl ConfigManager {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "config_manager_provider_tests.rs"]
|
||||
mod provider_tests;
|
||||
|
||||
pub(crate) fn protected_feature_keys(config_layer_stack: &ConfigLayerStack) -> BTreeSet<String> {
|
||||
let mut protected_features = config_layer_stack
|
||||
.effective_config()
|
||||
|
||||
Reference in new issue
Block a user