Preserve model catalogs when starting child agents (#60049)

## Why

Child startup can lose remote model capabilities such as `tool_search` when the selected catalog is uninitialized or disk data is older than the parent's in-memory snapshot.

## What changed

- Initialize the final provider, auth, and originator catalog before resolving a child's startup model, then read it from memory.
- Preserve loaded catalogs, including empty responses and updates that failed to persist, without overwriting concurrent refreshes.
- Reuse catalogs across retry and WebSocket transport overrides while retaining routing and header distinctions.

## Testing

Add regression coverage for child tool search with warm, cold, and disabled caches; failed cache writes; concurrent refreshes; empty catalogs; and Guardian reviewer catalog reuse.

GitOrigin-RevId: 01d995a65b623cc7d6f26e2dc9b6e8cf380de782
This commit is contained in:
evanz-oai
2026-11-07 03:16:52 +00:00
committed by copyberry
parent 358e464528
commit 44ccf39457
15 changed files with 682 additions and 80 deletions
+38 -20
View File
@@ -1116,12 +1116,16 @@ impl ThreadManager {
/*parent_originator*/ None,
)
.await;
let manager = self.state.models_for_thread(
&options.config,
&self.state.auth_manager,
&self.state.runtime_auth,
&originator,
);
let manager = self
.state
.models_for_thread(
&options.config,
&self.state.auth_manager,
&self.state.runtime_auth,
&originator,
&source,
)
.await;
let (_, info) = Session::resolve_startup_model(
manager.as_ref(),
&options.config,
@@ -1919,12 +1923,13 @@ impl ThreadManager {
}
impl ThreadManagerState {
fn models_for_thread(
async fn models_for_thread(
&self,
config: &Config,
auth_manager: &Arc<AuthManager>,
runtime_auth: &crate::runtime_auth::RuntimeAuthSlot,
originator: &str,
session_source: &SessionSource,
) -> SharedModelsManager {
let runtime = crate::runtime_auth::runtime_for_config(
runtime_auth,
@@ -1932,13 +1937,16 @@ impl ThreadManagerState {
Arc::clone(auth_manager),
&self.installation_id,
);
let manager = self.model_catalog.for_thread(
config,
Arc::clone(auth_manager),
runtime,
Arc::ptr_eq(auth_manager, &self.auth_manager),
);
manager.for_originator(originator).unwrap_or(manager)
self.model_catalog
.for_thread(
config,
Arc::clone(auth_manager),
runtime,
Arc::ptr_eq(auth_manager, &self.auth_manager),
originator,
session_source,
)
.await
}
pub(crate) fn shared_thread_instructions_provider(
@@ -2775,12 +2783,22 @@ impl ThreadManagerState {
} else {
Arc::new(mcp_manager.for_plugins_manager(Arc::clone(&plugins_manager)))
};
let models_manager = self.models_for_thread(
&config,
&auth_manager,
&runtime_auth,
&startup_context.originator,
);
let models_manager = tokio::select! {
biased;
_ = agent_control.runtime().shutdown.cancelled() => {
if let Some(startup_guard) = startup_guard {
startup_guard.cleanup().await;
}
return Err(CodexErr::TurnAborted);
}
manager = self.models_for_thread(
&config,
&auth_manager,
&runtime_auth,
&startup_context.originator,
&session_source,
) => manager,
};
let spawn_result = Session::spawn(SessionSpawnArgs {
attached_thread,
startup,