Skip to content

Reuse MCP tool snapshot within a sampling request#31292

Merged
sayan-oai merged 1 commit into
mainfrom
codex/cache-mcp-tool-snapshot
Jul 8, 2026
Merged

Reuse MCP tool snapshot within a sampling request#31292
sayan-oai merged 1 commit into
mainfrom
codex/cache-mcp-tool-snapshot

Conversation

@sayan-oai

@sayan-oai sayan-oai commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator

Follow-up to #30226.

Why

#30226 makes Apps World State inspect the MCP tool list, while tool-router construction reads the same list again later in the sampling request. list_all_tools() walks the MCP clients and may reconnect or wait for tools, so doing that work twice adds latency and lets context and tool construction observe different MCP states for one request.

What

  • Add a lazy MCP tool snapshot to StepContext.
  • Reuse that snapshot for Apps World State and tool-router construction.
  • Let each new StepContext refresh naturally for the next sampling request, without manager-level caching or invalidation.

Testing

  • just test -p codex-core apps_instructions
  • just test -p codex-core apps_guidance_appears_after_background_recovery_within_a_turn

@sayan-oai sayan-oai requested a review from a team as a code owner July 6, 2026 21:02
Base automatically changed from codex/reactive-app-guidance to main July 6, 2026 21:29
@sayan-oai sayan-oai force-pushed the codex/cache-mcp-tool-snapshot branch from a8751a9 to a1a0d9d Compare July 6, 2026 21:33
}
}

pub(crate) async fn mcp_tools(&self) -> &[ToolInfo] {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

If this field is purely computable based on McpRuntimeSnapshot it should stay on McpRuntimeSnapshot and be invalidated when it is changed.

@sayan-oai sayan-oai merged commit bdaad68 into main Jul 8, 2026
35 checks passed
@sayan-oai sayan-oai deleted the codex/cache-mcp-tool-snapshot branch July 8, 2026 20:35
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 8, 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