mirror of
https://github.com/openai/codex.git
synced 2026-10-31 19:28:49 +00:00
Refresh MCP runtimes when session auth changes (#35146)
## What changed - Track the authentication state used by each published MCP runtime and mark the runtime dirty when the auth mode, account details, or token changes. - Refresh plugin auth mode before evaluating pending MCP work, and rebuild the initial MCP projection if authentication changes during session startup. - Carry one auth snapshot through runtime construction so plugin discovery and MCP connections use consistent credentials. ## Testing - Add a regression test that replaces an API key, reloads authentication, and verifies that MCP refresh publishes a runtime using the new credentials. GitOrigin-RevId: 219c2f7a157f53b5467116e18bfe70a8c3dca695
This commit is contained in:
@@ -707,6 +707,7 @@ impl Session {
|
||||
session_init.ephemeral = config.ephemeral,
|
||||
));
|
||||
|
||||
let mut mcp_auth_changes = auth_manager.auth_change_receiver();
|
||||
let auth_manager_clone = Arc::clone(&auth_manager);
|
||||
let config_for_mcp = Arc::clone(&config);
|
||||
let mcp_manager_for_mcp = Arc::clone(&mcp_manager);
|
||||
@@ -1216,9 +1217,34 @@ impl Session {
|
||||
}
|
||||
turn_environments.start_connection_event_forwarding(tx_event.clone());
|
||||
|
||||
let mcp_auth_changes = sess.services.auth_manager.auth_change_receiver();
|
||||
let startup_auth_changed = mcp_auth_changes.has_changed().unwrap_or(false);
|
||||
if startup_auth_changed {
|
||||
mcp_auth_changes.mark_unchanged();
|
||||
}
|
||||
let latest_auth = sess.services.auth_manager.auth().await;
|
||||
let mcp_projection = if startup_auth_changed
|
||||
|| mcp_auth_changes.has_changed().unwrap_or(false)
|
||||
{
|
||||
sess.services
|
||||
.plugins_manager
|
||||
.set_auth_mode(latest_auth.as_ref().map(CodexAuth::api_auth_mode));
|
||||
sess.services
|
||||
.mcp_manager
|
||||
.runtime_config_for_step(
|
||||
config.as_ref(),
|
||||
&sess.services.mcp_thread_init,
|
||||
&sess.services.thread_extension_data,
|
||||
&session_configuration.originator,
|
||||
/*ready_selected_capability_roots*/ &[],
|
||||
/*executor_capability_discovery*/ None,
|
||||
)
|
||||
.await
|
||||
} else {
|
||||
mcp_projection
|
||||
};
|
||||
sess.install_initial_mcp_runtime(
|
||||
&session_configuration,
|
||||
latest_auth,
|
||||
mcp_projection,
|
||||
&resolved_environments,
|
||||
mcp_runtime_cwd,
|
||||
|
||||
Reference in New Issue
Block a user