Reuse executor Discovery V2 inventories across turns (#62640)

## Why

Starting a turn discarded the discovery cache and forced MCP to rebuild
from a fresh inventory even when the executor context was unchanged.
An MCP refresh could also discover a different inventory from the one
the step had already captured.

## What changed

Keep a per-thread cache keyed by environment, executor session, working
directory, and sandbox. Explicit invalidation reloads discovery on the
next lookup and lets in-flight readers finish with their captured results.

Use the step's captured inventory for MCP reconciliation and bind it
with the current MCP policy. Apply the binding's plugin policy when
selecting skills and hooks.

## Testing

Cover cache reuse across turns, lazy invalidation during in-flight
discovery, and MCP refresh with a captured inventory after a server
has been revoked.

GitOrigin-RevId: 8d4087dffdb3d6feef2456918a08ae7724cf18e4
This commit is contained in:
Anthony Tafoya
2026-11-20 01:48:00 +00:00
committed by copyberry
parent 9224da4ce1
commit e720e6c80b
15 changed files with 841 additions and 366 deletions
+7
View File
@@ -1602,6 +1602,13 @@ impl CodexThread {
.await
}
/// Invalidates this thread's executor DiscoveryV2 inventory. The next discovery
/// consumer reloads it; unchanged turns and other reads share the cached inventory.
/// Environment/session, cwd, and sandbox changes also trigger discovery independently.
pub fn invalidate_executor_discovery(&self) {
self.session.invalidate_executor_discovery();
}
/// Refreshes this thread's Apps tools before returning their runtime state.
pub async fn refresh_codex_apps_tools(
&self,