Use thread-scoped model catalogs for model lookups (#61421)

## Why

Model lookups through the startup catalog can use the wrong provider's capabilities or instructions after a default provider switch or when a thread has its own catalog.

## What changed

- Resolve model metadata for sampling, prediction forks, and memory writes through the owning thread's catalog.
- Make the thread's models manager available to extensions before startup callbacks and use it for guardian sampler configuration.
- Import external sessions using the destination provider and originator's catalog, loading its offline cache only when no refreshed catalog is available.

## Testing

Add regression coverage for sampling after a default provider switch, parent-specific prediction fork capabilities, thread-scoped model lookups, and imported sessions retaining destination provider instructions and originator.

GitOrigin-RevId: c86081b9e55c5e2b42a7f082966485d7fb5139d4
This commit is contained in:
Abhinav
2026-11-14 00:32:02 +00:00
committed by copyberry
parent 51f0b53d8b
commit 4598f33790
15 changed files with 215 additions and 36 deletions
+11
View File
@@ -25,6 +25,7 @@ use codex_extension_api::ConversationHistorySnapshot;
use codex_extension_api::ThreadIdleCause;
use codex_features::Feature;
use codex_history::RolloutItem;
use codex_models_manager::ModelsManagerConfig;
use codex_otel::SessionTelemetry;
use codex_otel::current_span_w3c_trace_context;
use codex_protocol::ThreadId;
@@ -41,6 +42,7 @@ use codex_protocol::models::ActivePermissionProfile;
use codex_protocol::models::PermissionProfile;
use codex_protocol::models::ProfileWorkspaceRoot;
use codex_protocol::models::ResponseItem;
use codex_protocol::openai_models::CatalogModel;
use codex_protocol::openai_models::ModelInfo;
use codex_protocol::openai_models::ReasoningEffort;
use codex_protocol::protocol::AskForApproval;
@@ -1205,6 +1207,15 @@ impl CodexThread {
self.session.selected_model_info().await
}
/// Looks up a named model in the catalog selected for this thread's provider and credentials.
pub async fn model_info(&self, model: &str, config: &ModelsManagerConfig) -> CatalogModel {
self.session
.services
.models_manager
.get_model_info(model, config)
.await
}
pub async fn config_snapshot(&self) -> ThreadConfigSnapshot {
self.session.thread_config_snapshot().await
}
+2
View File
@@ -42,6 +42,8 @@ mod compact_remote_v2;
mod compact_retained_tool_outputs;
mod compact_token_budget;
mod thread_startup_metadata;
/// Catalog handle installed in each thread's extension data before startup callbacks.
pub use codex_models_manager::manager::SharedModelsManager;
pub use codex_network_proxy::EnvironmentNetworkPolicy;
pub use codex_network_proxy::NetworkDomainPermission;
pub use codex_network_proxy::NetworkDomainPermissionEntry;
+1
View File
@@ -1054,6 +1054,7 @@ impl Session {
thread_extension_init.insert(codex_extension_api::ThreadOriginator(
session_configuration.originator.clone(),
));
thread_extension_init.insert(Arc::clone(&models_manager));
// Publish the already resolved model before extensions make startup decisions.
// Turn construction refreshes this attachment when the selected model changes.
thread_extension_init.insert(Arc::unwrap_or_clone(model_info.model));
+2
View File
@@ -1107,6 +1107,8 @@ impl ThreadManager {
Arc::clone(&self.state.git_root_discovery)
}
/// Returns the startup catalog. Use [`CodexThread::model_info`] for a live chat or
/// [`Self::models_manager_for_config`] for a new destination.
pub fn get_models_manager(&self) -> SharedModelsManager {
self.state.model_catalog.manager.clone()
}