Bound model catalog decode errors and classify request timeouts (#45928)

## Why

Model catalog decode errors can include the full response body and payload values from deserialization errors. Catalog request deadlines also report a generic timeout instead of a request timeout.

## What changed

- Report only the JSON error category, line, column, and response byte count when model catalog decoding fails.
- Return `CodexErr::RequestTimeout` when the model catalog refresh deadline expires.

## Testing

Add regression tests for invalid response shapes, large payload values, malformed and truncated JSON, and a delayed catalog response that must return `RequestTimeout`.

GitOrigin-RevId: 6fe5111a3e3b113d79942b3c213f8e94d773eb5a
This commit is contained in:
jif authored and copyberry committed 2026-09-16 11:46:37 +00:00
1 parent 8f38d5a877
commit 977193486d
4 files changed
+101 -3

No files matched your search

@@ -15,6 +15,8 @@ use codex_protocol::openai_models::TruncationPolicyConfig;
use codex_protocol::openai_models::default_input_modalities;
use http::HeaderMap;
use http::Method;
use pretty_assertions::assert_eq;
use serde_json::json;
use std::sync::Arc;
use wiremock::Mock;
use wiremock::MockServer;
@@ -46,6 +48,55 @@ fn provider(base_url: &str) -> Provider {
}
}
#[tokio::test]
async fn invalid_models_response_reports_bounded_decode_metadata() {
let server = MockServer::start().await;
for (body, category, column_offset) in [
(
json!({ "data": [{ "id": "private-model" }] }).to_string(),
"Data",
0,
),
(
json!({ "models": "private-value".repeat(4096) }).to_string(),
"Data",
1,
),
(r#"{"models":]}"#.to_string(), "Syntax", 1),
(r#"{"models":["#.to_string(), "Eof", 0),
] {
let response = Mock::given(method("GET"))
.and(path("/models"))
.respond_with(ResponseTemplate::new(200).set_body_string(&body))
.expect(1)
.mount_as_scoped(&server)
.await;
let transport = ReqwestTransport::from_http_client(
HttpClientBuilder::new()
.build_direct()
.expect("test HTTP client should build"),
);
let provider = provider(&server.uri());
let request_url = ModelsClient::<ReqwestTransport>::request_url(&provider, "0.1.0");
let client = ModelsClient::new(transport, provider, Arc::new(DummyAuth));
let error = client
.list_models(request_url, HeaderMap::new())
.await
.expect_err("invalid catalog should fail to decode");
assert_eq!(
error.to_string(),
format!(
"stream error: failed to decode models response: {category} at line 1 column {} (body: {} bytes)",
body.len() - column_offset,
body.len()
)
);
drop(response);
}
}
#[tokio::test]
async fn models_client_hits_models_endpoint() {
let server = MockServer::start().await;