mirror of
https://github.com/openai/codex.git
synced 2026-11-18 22:20:48 +00:00
Preserve enterprise MCP authorization across runtime refreshes (#55696)
## Why Configuration reloads must cancel stale enterprise MCP startups while preserving access for running threads that still pass validation. Replacing a runtime during `thread/revert` must also leave the replacement able to use enterprise tools. ## What changed - Separate pending startup cancellation from published thread lifetimes, with independent startup state for forks and replacement runtimes. - Retain eligible enterprise MCP connections across refreshes and explicit reconnects while applying updated tool restrictions and approvals. Do not create replacement enterprise connections after initial startup. - Revoke enterprise authorization when a thread is removed, drain requests when access is disabled, and revoke a connection's authority when token renewal requires authentication. ## Testing Extend regression coverage to verify enterprise tool calls survive `thread/revert`, inherited fork configurations are cancelled after a reload, and enterprise calls fail after logout while ordinary MCP calls remain available. GitOrigin-RevId: 2d634be3011854b57f73c741bd1ec6b5aed94ee5
This commit is contained in:
@@ -14,18 +14,20 @@ use tracing::warn;
|
||||
|
||||
impl Session {
|
||||
pub(crate) async fn disable_mcp_enterprise_auth(&self) {
|
||||
let mut state = self.state.lock().await;
|
||||
let mut config = state
|
||||
.session_configuration
|
||||
.original_config_do_not_use
|
||||
.as_ref()
|
||||
.clone();
|
||||
config.config_layer_stack.mcp_ema_cancellation().cancel();
|
||||
config.disable_mcp_enterprise_auth();
|
||||
state.session_configuration.original_config_do_not_use = Arc::new(config);
|
||||
self.services.mcp_runtime.invalidate_resource_caches();
|
||||
self.mark_mcp_runtime_dirty();
|
||||
drop(state);
|
||||
{
|
||||
let mut state = self.state.lock().await;
|
||||
let mut config = state
|
||||
.session_configuration
|
||||
.original_config_do_not_use
|
||||
.as_ref()
|
||||
.clone();
|
||||
config.config_layer_stack.mcp_ema_cancellation().cancel();
|
||||
config.disable_mcp_enterprise_auth();
|
||||
state.session_configuration.original_config_do_not_use = Arc::new(config);
|
||||
self.services.mcp_runtime.invalidate_resource_caches();
|
||||
self.mark_mcp_runtime_dirty();
|
||||
}
|
||||
self.services.mcp_runtime.quiesce_ema().await;
|
||||
self.schedule_mcp_prewarm();
|
||||
}
|
||||
|
||||
@@ -164,6 +166,17 @@ impl Session {
|
||||
if config.mcp_enterprise_managed_auth.is_none() {
|
||||
config.config_layer_stack.mcp_ema_cancellation().cancel();
|
||||
}
|
||||
if !matches!(scope, RuntimeConfigRefresh::UserFiles) {
|
||||
let cancellation = config
|
||||
.config_layer_stack
|
||||
.mcp_ema_cancellation()
|
||||
.refreshed(next_config.config_layer_stack.mcp_ema_cancellation());
|
||||
let config = Arc::make_mut(&mut config);
|
||||
config.config_layer_stack = config
|
||||
.config_layer_stack
|
||||
.clone()
|
||||
.with_mcp_ema_cancellation(cancellation);
|
||||
}
|
||||
state.session_configuration.original_config_do_not_use = Arc::clone(&config);
|
||||
drop(policy_guard);
|
||||
if matches!(scope, RuntimeConfigRefresh::Mcp) {
|
||||
@@ -174,6 +187,13 @@ impl Session {
|
||||
.then(|| self.build_effective_session_config(&state.session_configuration));
|
||||
(previous_config, new_config)
|
||||
};
|
||||
if config
|
||||
.config_layer_stack
|
||||
.mcp_ema_cancellation()
|
||||
.is_cancelled()
|
||||
{
|
||||
self.services.mcp_runtime.quiesce_ema().await;
|
||||
}
|
||||
self.emit_config_changed_contributors(previous_config.as_ref(), new_config.as_ref());
|
||||
self.schedule_mcp_prewarm();
|
||||
self.refresh_hooks(config).await;
|
||||
|
||||
Reference in New Issue
Block a user