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

@@ -122,7 +122,7 @@ impl OpenAiModelsEndpoint {
.map_err(map_api_error)
})
.await
.map_err(|_| CodexErr::Timeout)??;
.map_err(|_| CodexErr::RequestTimeout)??;
Ok(ModelsEndpointResponse {
models,
etag,
@@ -301,6 +301,10 @@ impl RequestTelemetry for ModelsRequestTelemetry {
}
}
#[cfg(test)]
#[path = "models_endpoint_timeout_tests.rs"]
mod timeout_tests;
#[cfg(test)]
mod tests {
use std::num::NonZeroU64;
@@ -0,0 +1,40 @@
use super::*;
use codex_http_client::OutboundProxyPolicy;
use codex_protocol::error::CodexErrorDetails;
use wiremock::Mock;
use wiremock::MockServer;
use wiremock::ResponseTemplate;
use wiremock::matchers::method;
use wiremock::matchers::path;
#[tokio::test]
async fn catalog_deadline_returns_request_timeout() {
let server = MockServer::start().await;
Mock::given(method("GET"))
.and(path("/models"))
.respond_with(
ResponseTemplate::new(200)
.set_body_json(serde_json::json!({ "models": [] }))
.set_delay(MODELS_REFRESH_TIMEOUT * 2),
)
.expect(1)
.mount(&server)
.await;
let endpoint = OpenAiModelsEndpoint::new(
ModelProviderInfo::create_openai_provider(Some(server.uri())),
/*auth_manager*/ None,
);
let error = endpoint
.list_models(
"0.0.0",
HttpClientFactory::new(OutboundProxyPolicy::ReqwestDefault),
)
.await
.expect_err("delayed catalog request should time out");
assert!(
matches!(error.details(), CodexErrorDetails::RequestTimeout),
"{error}"
);
}