mirror of
https://github.com/openai/codex.git
synced 2026-11-26 23:40:43 +00:00
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:
@@ -12,6 +12,7 @@ use codex_model_provider_info::ModelProviderInfo;
|
||||
use codex_models_manager::manager::ModelCatalogSettings;
|
||||
use codex_models_manager::manager::SharedModelsManager;
|
||||
use codex_protocol::openai_models::ModelsResponse;
|
||||
use codex_protocol::protocol::SessionSource;
|
||||
use codex_runtime_agent_instance::RuntimeAuthManager;
|
||||
use std::sync::Arc;
|
||||
|
||||
@@ -115,23 +116,35 @@ impl ThreadModelCatalog {
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn for_thread(
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub(super) async fn for_thread(
|
||||
&self,
|
||||
config: &Config,
|
||||
credentials: Arc<AuthManager>,
|
||||
runtime: Option<Arc<RuntimeAuthManager>>,
|
||||
same_owner: bool,
|
||||
originator: &str,
|
||||
session_source: &SessionSource,
|
||||
) -> SharedModelsManager {
|
||||
let models = config.model_catalog.as_ref().or_else(|| {
|
||||
self.catalog
|
||||
.as_ref()
|
||||
.filter(|_| self.provider == config.model_provider)
|
||||
.filter(|_| self.matches_catalog_provider(&config.model_provider))
|
||||
});
|
||||
let auth = ProviderAuthContext {
|
||||
credentials,
|
||||
runtime_auth: runtime.map(|runtime| (runtime, config.runtime_auth_mode)),
|
||||
};
|
||||
self.for_config(config, models, auth, same_owner)
|
||||
let manager = self.for_config(config, models, auth, same_owner);
|
||||
let manager = manager.for_originator(originator).unwrap_or(manager);
|
||||
if session_source.is_non_root_agent() {
|
||||
// The final provider/auth/originator catalog may be new even when the base
|
||||
// manager was reused. Preserve loaded snapshots, including unsaved updates.
|
||||
manager
|
||||
.ensure_initialized(config.http_client_factory())
|
||||
.await;
|
||||
}
|
||||
manager
|
||||
}
|
||||
|
||||
pub(super) fn for_config(
|
||||
@@ -145,7 +158,7 @@ impl ThreadModelCatalog {
|
||||
config.features.enabled(Feature::ApiKeyModelDiscovery);
|
||||
if same_owner
|
||||
&& self.runtime_mode == auth.runtime_auth.as_ref().map(|(_, mode)| *mode)
|
||||
&& self.provider == config.model_provider
|
||||
&& self.matches_catalog_provider(&config.model_provider)
|
||||
&& self.catalog.as_ref() == models
|
||||
&& self.api_key_model_discovery_default == api_key_model_discovery_default
|
||||
{
|
||||
@@ -158,6 +171,18 @@ impl ThreadModelCatalog {
|
||||
)
|
||||
}
|
||||
|
||||
fn matches_catalog_provider(&self, provider: &ModelProviderInfo) -> bool {
|
||||
// Guardian overrides inference transport and retries without changing the catalog.
|
||||
// Keep all other provider fields, including routing and headers, in the comparison.
|
||||
self.provider
|
||||
== ModelProviderInfo {
|
||||
request_max_retries: self.provider.request_max_retries,
|
||||
stream_max_retries: self.provider.stream_max_retries,
|
||||
supports_websockets: self.provider.supports_websockets,
|
||||
..provider.clone()
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn set_api_key_model_discovery_enabled(&self, enabled: bool) {
|
||||
self.factory.set_api_key_model_discovery_enabled(enabled);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user