Skip to content

feat(core, mcp): cache codex_apps tools in memory - #29003

Merged
owenlin0 merged 1 commit into
mainfrom
owen/cache_codex_apps_tools_in_mem
Jun 25, 2026
Merged

feat(core, mcp): cache codex_apps tools in memory#29003
owenlin0 merged 1 commit into
mainfrom
owen/cache_codex_apps_tools_in_mem

Conversation

@owenlin0

@owenlin0 owenlin0 commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Description

This makes Codex Apps tool reads use a shared in-memory snapshot instead of rereading the disk cache every time list_all_tools() runs. Disk still seeds the cache on startup and gets updated after successful fetches, but it is no longer the live read path.

The core change is that McpManager now owns a process-scoped CodexAppsToolsCache. Codex threads in the same app-server process now share this Codex Apps in-memory tools snapshot. The snapshot is keyed by the Codex home plus the Codex Apps identity: the active Codex auth user/workspace and the effective Codex Apps MCP source config.

There's already code to hard-refresh the cache, so we respect it in this PR.

Local benchmark

I ran a local steady-state microbenchmark of the exact repeated Codex Apps cached-tools read this PR removes, using the same real local cache payload in both trees: 3,678,138 bytes and 381 tools. The cache file was already warm in the OS page cache, so this measures same-process reread/deserialization work rather than cold-disk latency or full turn latency. Each run is 25 iterations (mimicking a turn that makes 25 inference calls).

Version Run 1 Run 2 Avg
origin/main disk read + JSON deserialize + filter_tools 50.755 ms 52.894 ms 51.825 ms
This branch in-memory current_tools + filter_tools 0.740 ms 0.778 ms 0.759 ms

That removes about 51 ms from each repeated Codex Apps cached-tools read on this machine, roughly 68x faster for that subpath. It is useful evidence for the hot path this PR changes, but not a claim that every production turn gets 51 ms faster; end-to-end impact also depends on the rest of list_all_tools() and tool-payload construction.

This is on my M2 Max macbook, so with a slower disk this would be much worse (and indeed we did see this really blew up turn runtime with a slow disk).

@owenlin0 owenlin0 changed the title Owen/cache codex apps tools in mem feat(core, mcp): cache codex_apps tools in memory Jun 18, 2026
@owenlin0
owenlin0 force-pushed the owen/cache_codex_apps_tools_in_mem branch from 7c52039 to 85996d1 Compare June 22, 2026 15:31
@owenlin0
owenlin0 marked this pull request as ready for review June 22, 2026 15:47
@owenlin0
owenlin0 requested a review from a team as a code owner June 22, 2026 15:47
@owenlin0
owenlin0 requested a review from mzeng-openai June 22, 2026 15:49

@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: 85996d140d

ℹ️ 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/codex-mcp/src/codex_apps_cache.rs Outdated
Comment thread codex-rs/codex-mcp/src/rmcp_client.rs
@owenlin0
owenlin0 requested a review from aibrahim-oai June 22, 2026 16:00
@owenlin0
owenlin0 force-pushed the owen/cache_codex_apps_tools_in_mem branch from 2cb705f to c613db7 Compare June 22, 2026 17:47
Comment thread codex-rs/codex-mcp/src/codex_apps_cache.rs Outdated
Comment thread codex-rs/codex-mcp/src/codex_apps_cache.rs Outdated
Comment thread codex-rs/codex-mcp/src/connection_manager.rs Outdated
@owenlin0
owenlin0 force-pushed the owen/cache_codex_apps_tools_in_mem branch from c613db7 to d1acfbe Compare June 23, 2026 21:58
@owenlin0
owenlin0 force-pushed the owen/cache_codex_apps_tools_in_mem branch from e3e9a72 to e6b16cf Compare June 24, 2026 16:06
owenlin0 added a commit that referenced this pull request Jun 24, 2026
@owenlin0
owenlin0 force-pushed the owen/cache_codex_apps_tools_in_mem branch from 0c8e68b to 4083532 Compare June 25, 2026 20:41
@owenlin0
owenlin0 enabled auto-merge (squash) June 25, 2026 20:48
@owenlin0
owenlin0 merged commit 703793c into main Jun 25, 2026
31 checks passed
@owenlin0
owenlin0 deleted the owen/cache_codex_apps_tools_in_mem branch June 25, 2026 20:54
@github-actions github-actions Bot locked and limited conversation to collaborators Jun 25, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants