Skip to content

Keep MCP elicitation routable across runtime refreshes - #30127

Merged
jif-oai merged 3 commits into
mainfrom
jif/resolve-elicitation-after-env-refresh
Jun 26, 2026
Merged

Keep MCP elicitation routable across runtime refreshes#30127
jif-oai merged 3 commits into
mainfrom
jif/resolve-elicitation-after-env-refresh

Conversation

@jif-oai

@jif-oai jif-oai commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Why

An MCP tool call can still be waiting for an elicitation response when an environment update replaces the thread's MCP runtime.

Before this change:

runtime A starts a tool call and asks the user
environment becomes ready, so runtime B is published
client answers the prompt through runtime B
runtime B cannot find runtime A's pending responder

The response is lost and the original tool call stays blocked.

What changed

All MCP runtimes for one thread now share a small elicitation router:

runtime A ---\
               shared router: response token -> exact pending responder
runtime B ---/

When Codex surfaces an MCP elicitation, it assigns a unique opaque response token. The router records which pending request owns that token. A replacement runtime reuses the same router, so the latest runtime can deliver a response to a request started by the previous runtime.

The Codex-owned token also prevents two runtime connections that reuse the same MCP server request ID from receiving each other's responses.

This does not retain or search old MCP managers. Only the pending responder map is shared.

Covered scenario

The integration test exercises the complete failure mode:

  1. A thread starts while its selected environment is still unavailable.
  2. A configured MCP server starts a tool call and asks the client for input.
  3. The environment becomes ready, causing Codex to publish a replacement MCP runtime.
  4. The client answers the original prompt after the replacement.
  5. The original tool call receives that answer and completes.

A focused routing test also creates two runtimes with the same server request ID and verifies that each response reaches the exact request that emitted its token.

Scope

This PR changes only elicitation response routing across MCP runtime replacement. It does not change when runtimes are rebuilt, which environments contribute MCP configuration, or how environment availability is detected.

@jif-oai
jif-oai requested a review from a team as a code owner June 25, 2026 21:37

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 93a891cd88

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread codex-rs/core/src/state/service.rs Outdated
Comment thread codex-rs/core/src/session/mcp.rs Outdated
@jif-oai
jif-oai force-pushed the jif/extension-owned-selected-capabilities branch 6 times, most recently from 690b95b to 885cdb7 Compare June 26, 2026 00:27
Base automatically changed from jif/extension-owned-selected-capabilities to main June 26, 2026 00:36
@jif-oai
jif-oai force-pushed the jif/resolve-elicitation-after-env-refresh branch from 93a891c to a66a118 Compare June 26, 2026 00:41
@jif-oai jif-oai changed the title Route MCP elicitation to its live runtime Keep MCP elicitation routable across runtime refreshes Jun 26, 2026
Comment thread codex-rs/app-server/tests/suite/v2/mcp_tool.rs Outdated
Comment thread codex-rs/codex-mcp/src/elicitation.rs
@jif-oai
jif-oai enabled auto-merge (squash) June 26, 2026 01:15
@jif-oai
jif-oai merged commit fb8598d into main Jun 26, 2026
31 checks passed
@jif-oai
jif-oai deleted the jif/resolve-elicitation-after-env-refresh branch June 26, 2026 01:28
@github-actions github-actions Bot locked and limited conversation to collaborators Jun 26, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants