Treat explicit provider model catalogs as authoritative (#49135)

## Why

Providers with `model_catalog_url` could advertise bundled models absent from their catalog or reuse stale models after a failed refresh. Model metadata could also match by prefix or namespaced suffix instead of the provider's exact model ID.

## What changed

- Suppress bundled model fallback and merging for explicit provider catalogs, including when discovery is disabled.
- Require unique, non-empty catalog slugs and match metadata by exact model ID.
- Serialize explicit catalog refreshes and invalidate in-memory and persisted catalog entries after fetch failures, preventing stale cache reuse.
- Report a clear configuration error when startup has no available model, while allowing an explicitly configured `model`.

## Testing

Add regression coverage for exact model matching, hidden catalog entries, cache invalidation across restart and recovery, invalid slugs, and empty-catalog startup with and without an explicit model. Update app-server model-list expectations and verify the TUI configuration error.

GitOrigin-RevId: ac323a94178e3c48df8d4a159a86fdbac20b03a2
This commit is contained in:
andrewgu-oai
2026-09-29 02:33:55 +00:00
committed by copyberry
parent a9118edae8
commit 458f7046a5
10 changed files with 409 additions and 97 deletions
@@ -946,6 +946,7 @@ async fn remote_models_apply_legacy_instructions(auth: CodexAuth) -> Result<()>
cwd,
config,
thread_manager,
home: _home,
..
} = builder.build(&server).await?;
@@ -1484,6 +1485,51 @@ fn test_remote_model_with_policy(
}
}
#[test_case(None; "without explicit model")]
#[test_case(Some("gateway-conversation"); "with explicit model")]
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn empty_model_catalog_requires_explicit_model(configured_model: Option<&str>) -> Result<()> {
skip_if_no_network!(Ok(()));
let server = MockServer::start().await;
Mock::given(method("GET"))
.and(path("/codex/models"))
.respond_with(ResponseTemplate::new(/*s*/ 200).set_body_json(ModelsResponse::default()))
.expect(1)
.mount(&server)
.await;
let response = mount_sse_once(
&server,
sse(vec![ev_response_created("resp-1"), ev_completed("resp-1")]),
)
.await;
let catalog_url = format!("{}/codex/models", server.uri());
let model = configured_model.map(str::to_string);
let result = test_codex()
.with_auth(CodexAuth::from_api_key("gateway-api-key"))
.with_config(move |config| {
config.model = model;
config.model_provider.model_catalog_url = Some(catalog_url.into());
config
.features
.enable(Feature::ApiKeyModelDiscovery)
.expect("enable API-key discovery");
})
.build_with_auto_env(&server)
.await;
if let Some(model) = configured_model {
let test = result?;
test.submit_turn("hello").await?;
assert_eq!(response.single_request().body_json()["model"], model);
} else {
let error = result.err().expect("startup requires a model");
assert_eq!(
error.to_string(),
"No models are available. Set `model` explicitly or check your model catalog configuration."
);
}
Ok(())
}
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn model_catalog_url_supplies_conversation_model_and_instructions() -> Result<()> {
skip_if_no_network!(Ok(()));