Keep discovered Apps tools available during startup recovery (#53672)

## Why

A transient Apps MCP startup failure can remove cached tools that the model has already discovered, preventing a later Code Mode invocation from using them.

## What changed

Keep cached Apps tools in the model's tool catalog while startup recovery runs. Let invocation readiness start or join a shared retry before acquiring the tool execution lock, while tool discovery remains nonblocking. Keep recovery running if a waiting invocation is cancelled.

## Testing

Extend connection-manager tests to cover cached tool bindings and shared recovery. Add a Code Mode regression test that discovers a cached Calendar tool, invokes it after startup fails, and verifies that it succeeds after recovery while unrelated tools remain able to execute.

GitOrigin-RevId: e888501a1050884a50a473e71b893cf6672fe256
This commit is contained in:
jif
2026-10-13 13:59:41 +00:00
committed by copyberry
parent 816fa702ec
commit 4c1cd8bbcc
7 changed files with 316 additions and 44 deletions
@@ -364,7 +364,12 @@ impl McpConnectionSet {
.client
.startup_complete
.load(Ordering::Acquire);
let accepts_cached_catalog = view.startup_readiness == McpStartupReadiness::Catalog;
// A transient Apps startup failure must not remove functions already discovered
// by the model. Keep retrying even when the cached catalog supplies this step.
view.connection.client.reconnect_failed_startup().await;
let accepts_cached_catalog = view.startup_readiness == McpStartupReadiness::Catalog
|| (view.connection.client.is_codex_apps_mcp_server
&& !view.connection.client.cancel_token.is_cancelled());
let cached_tools = if startup_pending
|| (accepts_cached_catalog && view.connection.client.ready_client().is_none())
{
@@ -383,7 +388,6 @@ impl McpConnectionSet {
{
return None;
}
view.connection.client.reconnect_failed_startup().await;
let Ok(mut client) = view.connection.client().await else {
trace!(server_name = %server_name, "omitting MCP server without an exact ready client");
return None;
@@ -544,6 +548,7 @@ impl McpConnectionSet {
if !view.tool_filter.allows(&advertised_tool.tool.name) {
return None;
}
// Recovery belongs to readiness, before the caller acquires the tool execution lock.
let mut client = view.connection.client().await.ok()?;
client.tool_timeout = view.tool_timeout;
let snapshot = client.tool_catalog.read(Arc::new).await;