Skip to content

Avoid duplicate codex_apps tool refresh on force refetch#22196

Open
mzeng-openai wants to merge 1 commit into
mainfrom
dev/mzeng/avoid_duplicate_codex_apps_tools_refresh
Open

Avoid duplicate codex_apps tool refresh on force refetch#22196
mzeng-openai wants to merge 1 commit into
mainfrom
dev/mzeng/avoid_duplicate_codex_apps_tools_refresh

Conversation

@mzeng-openai
Copy link
Copy Markdown
Collaborator

Why

app/list(force_refetch = true) creates a fresh temporary McpConnectionManager so it can read current codex_apps tools. That fresh manager already performs an uncached tools/list during startup and writes the result into the Codex Apps tools cache.

The old force-refetch branch then immediately called hard_refresh_codex_apps_tools_cache() on that same fresh manager, which issued a second uncached tools/list against the same server connection before any caller could observe the first result. That duplicated a live inventory request without making the data any fresher.

This is separate from the repeated in-process inventory reads that can happen during normal codex exec startup. Those reads reuse the already-loaded tool snapshot; the redundant network call was specific to the fresh-manager force-refetch flow.

Relevant code:

What changed

  • For force_refetch, wait for the freshly-created temporary manager's codex_apps startup to complete, then reuse list_all_tools() from that manager instead of forcing a second live refresh.
  • Keep the existing fallback behavior when codex_apps is not ready: continue with the startup/cached tools path rather than changing visible behavior.
  • Extend the existing app-list integration coverage to count tools/list calls and assert:
    • the warm request performs one inventory fetch
    • the later force-refetch request adds exactly one more fetch, not two

Regression coverage:

Verification

  • cargo test -p codex-app-server list_apps_force_refetch_patches_updates_from_cached_snapshots
  • cargo test -p codex-core connectors
  • just fix -p codex-core

@mzeng-openai mzeng-openai requested a review from a team as a code owner May 11, 2026 19:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant