Defer MCP auth discovery until startup failure

This commit is contained in:
Alexey Ldokov
2026-07-03 17:26:13 +01:00
parent da4c8ca57d
commit dbd107a7f3
7 changed files with 162 additions and 72 deletions
+1 -9
View File
@@ -330,14 +330,6 @@ impl Session {
turn_context.cwd.to_path_buf()
});
let mcp_runtime_context = McpRuntimeContext::new(environment_manager, cwd);
let auth_statuses = compute_auth_statuses(
mcp_servers.iter(),
mcp_config.mcp_oauth_credentials_store_mode,
mcp_config.auth_keyring_backend_kind,
auth.as_ref(),
&mcp_runtime_context,
)
.await;
let mcp_startup_cancellation_token = {
let mut guard = self.services.mcp_startup_cancellation_token.lock().await;
// The previous runtime owns the old token and may still be serving an in-flight step.
@@ -351,7 +343,7 @@ impl Session {
&mcp_servers,
mcp_config.mcp_oauth_credentials_store_mode,
mcp_config.auth_keyring_backend_kind,
auth_statuses,
HashMap::new(),
&turn_context.approval_policy,
turn_context.sub_id.clone(),
self.get_tx_event(),
-1
View File
@@ -334,7 +334,6 @@ use codex_core_plugins::PluginsManager;
use codex_core_plugins::RecommendedPluginCandidatesInput;
use codex_git_utils::get_git_repo_root;
use codex_mcp::McpConfig;
use codex_mcp::compute_auth_statuses;
use codex_mcp::effective_mcp_servers;
use codex_otel::SessionTelemetry;
use codex_otel::THREAD_STARTED_METRIC;
+3 -18
View File
@@ -676,7 +676,6 @@ impl Session {
.unwrap_or_else(|| session_configuration.cwd().to_path_buf());
let mcp_runtime_context =
McpRuntimeContext::new(Arc::clone(&environment_manager), mcp_runtime_cwd);
let mcp_runtime_context_for_auth = mcp_runtime_context.clone();
let auth_and_mcp_fut = async move {
let auth = auth_manager_clone.auth().await;
let mcp_config = mcp_manager_for_mcp
@@ -689,21 +688,7 @@ impl Session {
.await;
let mcp_servers = codex_mcp::effective_mcp_servers(&mcp_config, auth.as_ref());
let tool_plugin_provenance = codex_mcp::tool_plugin_provenance(&mcp_config);
let auth_statuses = compute_auth_statuses(
mcp_servers.iter(),
config_for_mcp.mcp_oauth_credentials_store_mode,
config_for_mcp.auth_keyring_backend_kind(),
auth.as_ref(),
&mcp_runtime_context_for_auth,
)
.await;
(
auth,
mcp_config,
mcp_servers,
auth_statuses,
tool_plugin_provenance,
)
(auth, mcp_config, mcp_servers, tool_plugin_provenance)
}
.instrument(info_span!(
"session_init.auth_mcp",
@@ -714,7 +699,7 @@ impl Session {
let (
thread_persistence_result,
state_db_ctx,
(auth, mcp_config, mcp_servers, auth_statuses, tool_plugin_provenance),
(auth, mcp_config, mcp_servers, tool_plugin_provenance),
) = tokio::join!(thread_persistence_fut, state_db_fut, auth_and_mcp_fut);
let mut live_thread_init =
@@ -1197,7 +1182,7 @@ impl Session {
&mcp_servers,
config.mcp_oauth_credentials_store_mode,
config.auth_keyring_backend_kind(),
auth_statuses,
HashMap::new(),
&session_configuration.approval_policy,
INITIAL_SUBMIT_ID.to_owned(),
tx_event.clone(),