From 83c4934e45d22dab962c55817fdbdc134e98dca6 Mon Sep 17 00:00:00 2001 From: Ahmed Ibrahim Date: Tue, 23 Jun 2026 00:31:56 -0700 Subject: [PATCH] Remove redundant Codex Apps cache guard (#29575) ## Why Codex Apps cache writes are already restricted to Codex Apps call paths: startup invokes the helper only from the Codex Apps branch, and hard refresh operates on the reserved Codex Apps server directly. Rechecking the server name inside the cache helper duplicates that classification and leaves the helper with an argument that cannot change valid behavior. ## What changed - Remove the redundant server-name check and parameter from the cache writer. - Rename the helper to `write_codex_apps_tools_cache` to reflect its narrower contract. - Update production and test callsites to use the simplified API. --- codex-rs/codex-mcp/src/codex_apps.rs | 8 +------- codex-rs/codex-mcp/src/connection_manager.rs | 5 ++--- codex-rs/codex-mcp/src/connection_manager_tests.rs | 12 +++--------- codex-rs/codex-mcp/src/rmcp_client.rs | 5 ++--- 4 files changed, 8 insertions(+), 22 deletions(-) diff --git a/codex-rs/codex-mcp/src/codex_apps.rs b/codex-rs/codex-mcp/src/codex_apps.rs index 53b546b8a..437e750de 100644 --- a/codex-rs/codex-mcp/src/codex_apps.rs +++ b/codex-rs/codex-mcp/src/codex_apps.rs @@ -8,7 +8,6 @@ use std::path::PathBuf; use std::time::Instant; -use crate::mcp::CODEX_APPS_MCP_SERVER_NAME; use crate::runtime::emit_duration; use crate::tools::MCP_TOOLS_CACHE_WRITE_DURATION_METRIC; use crate::tools::ToolInfo; @@ -125,16 +124,11 @@ pub(crate) fn normalize_codex_apps_callable_namespace( } } -pub(crate) fn write_cached_codex_apps_tools_if_needed( - server_name: &str, +pub(crate) fn write_codex_apps_tools_cache( cache_context: Option<&CodexAppsToolsCacheContext>, server_info: &McpServerInfo, tools: &[ToolInfo], ) { - if server_name != CODEX_APPS_MCP_SERVER_NAME { - return; - } - if let Some(cache_context) = cache_context { let cache_write_start = Instant::now(); write_cached_codex_apps_tools(cache_context, tools); diff --git a/codex-rs/codex-mcp/src/connection_manager.rs b/codex-rs/codex-mcp/src/connection_manager.rs index a881e865d..be2784307 100644 --- a/codex-rs/codex-mcp/src/connection_manager.rs +++ b/codex-rs/codex-mcp/src/connection_manager.rs @@ -16,7 +16,7 @@ use std::time::Instant; use crate::McpAuthStatusEntry; use crate::codex_apps::CodexAppsToolsCacheContext; use crate::codex_apps::CodexAppsToolsCacheKey; -use crate::codex_apps::write_cached_codex_apps_tools_if_needed; +use crate::codex_apps::write_codex_apps_tools_cache; use crate::elicitation::ElicitationRequestManager; use crate::elicitation::ElicitationReviewerHandle; use crate::mcp::CODEX_APPS_MCP_SERVER_NAME; @@ -521,8 +521,7 @@ impl McpConnectionManager { &[], ); - write_cached_codex_apps_tools_if_needed( - CODEX_APPS_MCP_SERVER_NAME, + write_codex_apps_tools_cache( managed_client.codex_apps_tools_cache_context.as_ref(), &managed_client.server_info, &tools, diff --git a/codex-rs/codex-mcp/src/connection_manager_tests.rs b/codex-rs/codex-mcp/src/connection_manager_tests.rs index 05b391702..455697392 100644 --- a/codex-rs/codex-mcp/src/connection_manager_tests.rs +++ b/codex-rs/codex-mcp/src/connection_manager_tests.rs @@ -5,7 +5,7 @@ use crate::codex_apps::load_startup_cached_codex_apps_server_info; use crate::codex_apps::load_startup_cached_codex_apps_tools_snapshot; use crate::codex_apps::read_cached_codex_apps_tools; use crate::codex_apps::write_cached_codex_apps_tools; -use crate::codex_apps::write_cached_codex_apps_tools_if_needed; +use crate::codex_apps::write_codex_apps_tools_cache; use crate::declared_openai_file_input_param_names; use crate::elicitation::ElicitationRequestManager; use crate::elicitation::elicitation_is_rejected_by_policy; @@ -704,12 +704,7 @@ fn startup_cached_codex_apps_tools_loads_from_disk_cache() { "calendar_search", )]; let server_info = create_test_server_info("Codex Apps"); - write_cached_codex_apps_tools_if_needed( - CODEX_APPS_MCP_SERVER_NAME, - Some(&cache_context), - &server_info, - &cached_tools, - ); + write_codex_apps_tools_cache(Some(&cache_context), &server_info, &cached_tools); let startup_tools = load_startup_cached_codex_apps_tools_snapshot(Some(&cache_context)) .expect("expected startup snapshot to load from cache"); @@ -758,8 +753,7 @@ fn codex_apps_server_info_cache_survives_legacy_tools_cache_write() { Some("user-one"), ); let server_info = create_test_server_info("Codex Apps"); - write_cached_codex_apps_tools_if_needed( - CODEX_APPS_MCP_SERVER_NAME, + write_codex_apps_tools_cache( Some(&cache_context), &server_info, &[create_test_tool( diff --git a/codex-rs/codex-mcp/src/rmcp_client.rs b/codex-rs/codex-mcp/src/rmcp_client.rs index f8173b600..f9cc6a5e8 100644 --- a/codex-rs/codex-mcp/src/rmcp_client.rs +++ b/codex-rs/codex-mcp/src/rmcp_client.rs @@ -25,7 +25,7 @@ use crate::codex_apps::load_startup_cached_codex_apps_tools_snapshot; use crate::codex_apps::normalize_codex_apps_callable_name; use crate::codex_apps::normalize_codex_apps_callable_namespace; use crate::codex_apps::normalize_codex_apps_tool_title; -use crate::codex_apps::write_cached_codex_apps_tools_if_needed; +use crate::codex_apps::write_codex_apps_tools_cache; use crate::elicitation::ElicitationRequestManager; use crate::mcp::CODEX_APPS_MCP_SERVER_NAME; use crate::mcp::ToolPluginProvenance; @@ -581,8 +581,7 @@ async fn start_server_task( ); let server_info = mcp_server_info_from_implementation(initialize_result.server_info); let codex_apps_tools_cache_context = if is_codex_apps_mcp_server { - write_cached_codex_apps_tools_if_needed( - &server_name, + write_codex_apps_tools_cache( codex_apps_tools_cache_context.as_ref(), &server_info, &tools,