Refresh Apps tools outside the MCP runtime gate (#60639)

## Why

Holding the session MCP gate during `tools/list` blocks other runtime access. Releasing it requires preventing stale refresh results from publishing after configuration or authentication changes.

## What changed

- Capture the Apps client under the session gate, then release the gate before fetching tools.
- Validate runtime and authentication state before publishing the shared cache and client catalog; retry a superseded refresh once.
- Wait for in-flight Apps refreshes before capturing model tools, preparing Apps calls, or shutting down the runtime.

## Testing

Add regression coverage for stale refreshes after runtime invalidation or logout, publication validation after call preparation drains, and a model step that waits for refreshed Apps tools while MCP status queries remain available.

GitOrigin-RevId: 42d4be8c4a9218933f8e3d07fc7f32f2da9cbd9d
This commit is contained in:
Dmitriy Kovalenko
2026-11-10 18:33:49 +00:00
committed by copyberry
parent 057d9140a8
commit 3f797555cd
13 changed files with 405 additions and 42 deletions
+9 -3
View File
@@ -83,14 +83,20 @@ impl SessionTask for RegularTask {
== TurnStartPhase::RegularTaskStart
&& contributor.requires_mcp_runtime(&sess.services.thread_extension_data)
});
let preparation = sess
.emit_turn_start_lifecycle(
let preparation = async {
sess.emit_turn_start_lifecycle(
&ctx,
/*token_usage_at_turn_start*/ None,
TurnStartPhase::RegularTaskStart,
)
.or_cancel(&cancellation_token)
.await;
if prepares_mcp {
// Resource discovery can overlap the fetch. Wait before reprojection.
sess.wait_for_apps_tool_refresh().await;
}
}
.or_cancel(&cancellation_token)
.await;
// Even cancelled discovery may have cleared the previous account's catalog.
if prepares_mcp {
sess.request_mcp_runtime_reprojection(