Refresh MCP headers before Codex Apps tool calls#15132
Open
Refresh MCP headers before Codex Apps tool calls#15132
Conversation
Co-authored-by: Codex <noreply@openai.com>
Co-authored-by: Codex <noreply@openai.com>
Co-authored-by: Codex <noreply@openai.com>
Set Codex Apps MCP request headers once per active turn and clear them on turn end, instead of threading request-scoped headers through every tool call. Keep RMCP header injection limited to streamable HTTP tools/call requests so list/init paths stay unchanged and concurrent tool calls on the same client are not serialized. Co-authored-by: Codex <noreply@openai.com>
Add the new request_headers test fixture state, update the streamable HTTP recovery test to pass the new client constructor argument, and satisfy the argument comment lint for clearing turn-scoped MCP request headers. Co-authored-by: Codex <noreply@openai.com>
Contributor
|
I have read the CLA Document and I hereby sign the CLA You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot. |
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.
Summary
tools/callrequests pick up the refreshed headersProblem
PR #15011 snapshots the Codex Apps MCP request headers at turn start.
That is usually fine for
session_idandturn_id, butTurnMetadataStatecan enrich thex-codex-turn-metadatapayload later in the same turn after async git/workspace inspection completes. When a tool call happens after that enrichment, the MCPtools/callrequest can still carry the old turn-start snapshot instead of the enriched metadata.In practice, that means downstream MCP services can miss workspace/git context that became available after the turn started.
Example scenario
A realistic sequence looks like this:
x-codex-turn-metadatainitially contains only basic fields liketurn_idandsandbox.workspacesinformation.tools/callrequest still used the stale step-2 header, so the tool call missed the workspace metadata discovered in step 3.That exact sequence occurs in the integration test added here: the turn starts in a temp git repo, enrichment picks up workspace metadata, and the later Apps tool call is expected to forward it.
Fix
Refresh the Codex Apps MCP request headers again immediately before
Session::call_tool(...)forwards thetools/callrequest.This preserves the original behavior for which requests get headers, but makes the header contents current at tool-call time instead of freezing them at turn start.
Before / After proof
I verified this with the same realistic apps-flow integration scenario on both branches:
Before: untouched
pr-15011I ran the same runtime probe against the original PR branch in a clean worktree. The MCP
tools/callrequest only carried:{ "sandbox": "seatbelt", "turn_id": "..." }workspaceswas missing, so the later git/workspace enrichment did not make it into the tool-call header.After: this follow-up branch
Running the same scenario on this branch passes, and the MCP
tools/callrequest contains enriched workspace metadata inx-codex-turn-metadata.Testing
Targeted local validation
cargo fmt --all --check --manifest-path /Users/ychhabria/repos/codex/codex-rs/Cargo.tomlcargo test -q -p codex-core --lib call_tool_refreshes_codex_apps_request_headers_from_active_turn --manifest-path /Users/ychhabria/repos/codex/codex-rs/Cargo.tomlcargo test -q -p codex-core --test all search_tool --manifest-path /Users/ychhabria/repos/codex/codex-rs/Cargo.tomlcargo test -q -p codex-core apps_mcp_tool_call_uses_enriched_turn_metadata_header --test all --manifest-path /Users/ychhabria/repos/codex/codex-rs/Cargo.tomlBefore/after reproduction
cargo test -q -p codex-core apps_mcp_tool_call_uses_enriched_turn_metadata_header --test all --manifest-path /Users/ychhabria/repos/codex-pr15011-base/codex-rs/Cargo.tomlworkspaceswas absent from the MCPtools/callheaderNotes
The current PR CI still shows unrelated failures:
cla: CLA signature requirementbuild-test: missing/downloadable native artifacts from a referenced workflowI did not find a code-level CI failure attributable to this MCP header refresh change.