Skip to content

Using cached connector directory for discoverable tools list#21497

Merged
mzeng-openai merged 9 commits into
mainfrom
dev/mzeng/cached-tool-suggest-discoverables
May 8, 2026
Merged

Using cached connector directory for discoverable tools list#21497
mzeng-openai merged 9 commits into
mainfrom
dev/mzeng/cached-tool-suggest-discoverables

Conversation

@mzeng-openai
Copy link
Copy Markdown
Collaborator

@mzeng-openai mzeng-openai commented May 7, 2026

Summary

Startup tool construction currently depends on connector directory metadata for tool_suggest discoverables. On a cold directory cache, that can put slow connector-directory requests on the blocking path even though the tools array only needs directory data for install suggestions, not for the live connector MCP tools themselves.

This PR keeps the discoverables path off that cold network fetch:

  • read connector directory metadata from cache only when building discoverable tools
  • persist connector directory metadata to ~/.codex/cache/codex_app_directory/<hash>.json and use it to hydrate the in-memory cache on later runs before the normal refresh path updates it
  • use connector-directory-specific cache naming to distinguish this metadata cache from the separate Codex Apps tools-spec cache

This reduces first-turn startup work without changing how live connector MCP tools are sourced. Longer term, directory-backed install suggestions should move to a search-based flow so they no longer need to be inlined into the tools prompt at all.

Testing

  • cargo test -p codex-connectors
  • cargo test -p codex-chatgpt
  • cargo test -p codex-core request_plugin_install_is_available_without_search_tool_after_discovery_attempts
  • cargo test -p codex-core tool_suggest_uses_connector_id_fallback_when_directory_cache_is_empty

@mzeng-openai mzeng-openai requested a review from a team as a code owner May 7, 2026 06:01
@mzeng-openai mzeng-openai marked this pull request as draft May 7, 2026 06:02
@mzeng-openai mzeng-openai changed the title Avoid fetching connector directory for tool suggestions Using cached connector directory for discoverable tools list May 7, 2026
@mzeng-openai mzeng-openai marked this pull request as ready for review May 7, 2026 06:35
@mzeng-openai mzeng-openai force-pushed the dev/mzeng/cached-tool-suggest-discoverables branch from 597b264 to 86745f4 Compare May 7, 2026 07:17
Comment thread codex-rs/core/src/connectors.rs Outdated

pub fn cached_all_connectors(cache_key: &AllConnectorsCacheKey) -> Option<Vec<AppInfo>> {
let mut cache_guard = ALL_CONNECTORS_CACHE
pub fn cached_directory_connectors(
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

renamed for better semantics

return Some(cached_connectors);
}

let directory_cache::CachedConnectorDirectoryDiskLoad::Hit { connectors } =
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Disk cache hydrates in-memory cache at first read.

pub fn cached_directory_connectors(
cache_context: &ConnectorDirectoryCacheContext,
) -> Option<Vec<AppInfo>> {
if let Some(cached_connectors) = cached_directory_connectors_in_memory(&cache_context.cache_key)
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

in-memory directory cache is still the source-of-truth

list_directory_connectors_for_tool_suggest_with_auth(config, auth).await?;
let connector_ids = tool_suggest_connector_ids(config).await;
let directory_connectors = codex_connectors::merge::merge_plugin_connectors(
cached_directory_connectors_for_tool_suggest_with_auth(config, auth).await,
Copy link
Copy Markdown
Collaborator Author

@mzeng-openai mzeng-openai May 8, 2026

Choose a reason for hiding this comment

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

Always constructs directory data from cache because it affects the startup path (prewarm).
For the first run in a new environment, it will not block startup but can cause a kv cache miss if the directory cache is empty at the time the prompt is sent and cache is refreshed later. This will not be an issue when plugin suggestion is migrated to search-based approach.

@mzeng-openai mzeng-openai requested a review from xl-openai May 8, 2026 07:13
Copy link
Copy Markdown
Collaborator

@pakrym-oai pakrym-oai left a comment

Choose a reason for hiding this comment

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

Worth adding an integration test?

Comment thread codex-rs/connectors/src/directory_cache.rs
@mzeng-openai
Copy link
Copy Markdown
Collaborator Author

Worth adding an integration test?

There is already an integration test for the main user-visible regression in requeset_plugin_install.rs!

@mzeng-openai mzeng-openai merged commit 2f3a2d7 into main May 8, 2026
26 checks passed
@mzeng-openai mzeng-openai deleted the dev/mzeng/cached-tool-suggest-discoverables branch May 8, 2026 21:14
@github-actions github-actions Bot locked and limited conversation to collaborators May 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.

3 participants