Skip to content

Use Claude Code with your ChatGPT, Kimi, Cursor or Grok subscription via a local Anthropic-compatible proxy

Rust

fix(codex): stop client retries after empty-completion exhaustion

Wuming Gong0ea44cae97a3
diff --git a/src/providers/codex/mod.rs b/src/providers/codex/mod.rs
index 0165e51..bfc9611 100644
--- a/src/providers/codex/mod.rs
+++ b/src/providers/codex/mod.rs
@@ -1481,7 +1481,17 @@ fn map_codex_error_to_response(err: &client::CodexError) -> Response {
return map_codex_failure_to_response(message);
}
if err.detail.as_deref() == Some(EMPTY_CODEX_COMPLETION_DETAIL) {
- return json_error(StatusCode::SERVICE_UNAVAILABLE, "api_error", &err.message);
+ // The proxy has already spent its own retry budget on this request, so
+ // a client retry only multiplies it: Claude Code resends a 503 up to
+ // ten times, each one repeating the proxy's full retry loop.
+ return (
+ [(
+ HeaderName::from_static("x-should-retry"),
+ HeaderValue::from_static("false"),
+ )],
+ json_error(StatusCode::SERVICE_UNAVAILABLE, "api_error", &err.message),
+ )
+ .into_response();
}
match err.status {
@@ -2162,10 +2172,9 @@ mod tests {
assert_eq!(err.status, 503);
assert_eq!(err.detail.as_deref(), Some(EMPTY_CODEX_COMPLETION_DETAIL));
- assert_eq!(
- map_codex_error_to_response(&err).status(),
- StatusCode::SERVICE_UNAVAILABLE
- );
+ let response = map_codex_error_to_response(&err);
+ assert_eq!(response.status(), StatusCode::SERVICE_UNAVAILABLE);
+ assert_eq!(response.headers()["x-should-retry"], "false");
}
#[test]
diff --git a/tests/smoke_cutover.rs b/tests/smoke_cutover.rs
index 86aecc8..1387ff1 100644
--- a/tests/smoke_cutover.rs
+++ b/tests/smoke_cutover.rs
@@ -1497,6 +1497,7 @@ async fn smoke_codex_http_empty_completions_exhaust_to_service_unavailable() {
let response = call_messages("gpt-5.5").await;
let status = response.status();
+ let should_retry = response.headers().get("x-should-retry").cloned();
let body = axum::body::to_bytes(response.into_body(), usize::MAX)
.await
.unwrap();
@@ -1507,6 +1508,11 @@ async fn smoke_codex_http_empty_completions_exhaust_to_service_unavailable() {
StatusCode::SERVICE_UNAVAILABLE,
"exhausted empty completions must surface an explicit error: {body_text}"
);
+ assert_eq!(
+ should_retry.as_ref().and_then(|v| v.to_str().ok()),
+ Some("false"),
+ "the proxy already retried; the client must not multiply it"
+ );
assert!(
body_text.contains("Codex completed without producing output"),
"unexpected exhaustion body: {body_text}"