Repository navigation
fix(daemon): let a Codex first turn wait for slow MCP servers - #2800
Merged
Merged
Conversation
Codex builds a turn's tool list after waiting at most 1 s for MCP servers that are still starting, and leaves the rest out of that turn. A remote HTTP server that takes a second or more to answer `initialize` therefore misses the first turn of every new or loaded session, and the agent reports the tool as missing. Every Codex spawn now sets `mcp_optional_startup_grace_ms` to 10 s in CODEX_CONFIG, unless the runtime config already chose a value. The wait ends as soon as the servers are ready; a server that never starts costs the first turn at most the grace, after which the turn runs without it. The setting is applied in AcpHost, so local and cluster launches both receive it. Refs #2770 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
zfy0701
enabled auto-merge (squash)
October 5, 2026 09:00
Contributor
There was a problem hiding this comment.
Reviewed d7ed0fc. No blocking findings.
The 10-second default is applied before the shared local/cluster launch, preserves explicit CODEX_CONFIG values (including zero), and composes with the existing account-app and user-input settings. The pending-server diagnostic remains an explicitly documented follow-up under #2770.
Validation: direct helper assertions and git diff --check passed. The focused Vitest suites were not run to completion: dependency bootstrap was slow and was stopped before tests started.
sent by review-bot (Codex · gpt-6-astra) · open in session
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refs #2770
Problem
When Codex builds a turn's tool list, it waits at most 1 s (
DEFAULT_OPTIONAL_MCP_STARTUP_GRACE) for MCP servers that are still starting, and leaves the rest out of that turn. A remote HTTP MCP server that needs a second or more to answerinitializetherefore misses the first turn of every new or loaded session. The agent then says the tool does not exist, or its first call fails, even though the daemon passed the server correctly.Change
codexConfigWithMcpStartupGrace()setsmcp_optional_startup_grace_msto 10 s inCODEX_CONFIG. A value the runtime config already sets is kept.AcpHost.start()applies it to every Codex spawn, next to the account-app andrequest_user_inputsettings. Cluster launches build their env on the same path, so both local and pool sessions get it.The setting is a top-level Codex config key, so codex-acp needs no change: it already merges
CODEX_CONFIGinto the config of everythread/startandthread/resume, including the resume behindsession/load.Why this and not the alternatives
required = trueon each MCP server also makes the turn wait, but Codex then failsthread/start/thread/resumewhen that server cannot start, so one broken server would break the whole agent._meta.mcpStartupAwaitTimeoutMscoverssession/newandsession/resumeonly. Its own docs saysession/loadignores it, and a load is how the daemon reopens an idle session.Verification
Reproduced locally against codex-acp 2.1.1-agentconnect.1 with its bundled Codex 0.159.3. The MCP server was an HTTP server that answers
initializeafter 3 s, passed through ACPmcpServersas the daemon does. A stub Responses endpoint recorded the tools Codex sent in the first model request.CODEX_CONFIGsession/newsession/loadsession/newsession/loadUnit tests cover the helper and the env each Codex spawn receives.
Not covered
The issue also asks for a daemon log line when a turn starts with a configured server still pending. That is not part of this change. With the longer grace, the only remaining silent case is a server still not ready after 10 s.
🤖 Generated with Claude Code · Claude Opus 5.5