Repository navigation
codex: stop re-sending a request after the response header timeout - #160
Merged
Merged
Conversation
The HTTP transport hardcoded a 60s wait for the Codex response headers. That figure suits a request whose head comes back as soon as the backend accepts it, but Codex withholds the head until the model produces its first output, so the wait tracks how much reasoning the request asks for. A large request to a high-effort model routinely needs longer than 60s, and the timeout firing fails the request outright. `codex.headerTimeoutMs` and `CCP_CODEX_HEADER_TIMEOUT_MS` set the bound, with the usual environment, file, default precedence. The default moves to 300_000ms, matching IMAGE_HEADER_TIMEOUT_MS, which was already raised to five minutes for the same reason. Values below 1000ms are ignored rather than clamped, so a typo does not hide behind a working default.
Running out of patience for the Codex response headers produced a statusless error whose message begins "Timed out waiting", and is_retryable_transport_error classifies any statusless error with that substring as a transport failure. stream_codex_http_events therefore re-sent the whole request three more times, so one timeout cost 4 * header_timeout plus 10.5s of backoff before the client saw a 502. Re-sending cannot help. The request reached Codex, which withholds the response head until the model produces its first output, so a re-send starts that reasoning from scratch and the new attempt runs out of time exactly like the last one. It also pays to upload the request body again, which is the expensive part of a large-context turn. Clients that retry a 502 quietly turn this into a long silent stall. The timeout error now carries a detail marker and the classifier refuses it, which covers both the streaming and the buffered HTTP paths. Retries still apply to what they were built for: connection failures before any bytes reach the server, and retryable upstream statuses. There is no retry for a timeout that fires while the body is still being written, because that case is indistinguishable from the rest from inside the timeout, and the request may already have been received in full. header_timeout_retries goes with it. It was carried through the constructors and the test helper but never read.
rikbrown
force-pushed
the
fix/codex-header-timeout
branch
from
September 19, 2026 19:52
0914542 to
e51f12e
Compare
rikbrown
added a commit
to rikbrown/claude-code-proxy
that referenced
this pull request
Sep 19, 2026
Carries the header-timeout fix from raine#160: a response header timeout now fails once instead of being re-sent up to four times. Co-Authored-By: Claude Fable 5.1 <[email protected]>
raine
force-pushed
the
fix/codex-header-timeout
branch
from
September 19, 2026 20:34
e51f12e to
c48d47c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The failure
Behind a pooling proxy, one deployment logged 85 failed Codex requests in a day. Every one was the same: HTTP 502, elapsed 250,5xx ms,
"Timed out waiting 60000ms for Codex response headers". Every one was a large-context request (~2 MB body) to a high-effort model. Smaller models on the same proxy never failed, and short requests to the same model never failed — their headers arrive in seconds. The largest head latency that succeeded under the 60s bound was 55.8s.Claude Code retries a 502 silently, so the user sees a 10-20 minute stall, not an error.
The mechanism
start_post_httpwrapssend()intokio::time::timeout(header_timeout_ms)and, on expiry, returns a statuslessCodexErrorwhose message begins"Timed out waiting".is_retryable_transport_errormatches any statusless error containing that substring, sostream_codex_http_eventstreats it as a transport failure and re-sends. WithMAX_BUFFERED_TRANSPORT_RETRIES = 3that is four sends: 4 x 60,000ms plus 1,500 + 3,000 + 6,000ms of backoff = 250,500ms, which is the elapsed figure in every log line.The re-sends cannot succeed. The request reached Codex, which withholds the response head until the model produces its first output, so a re-send restarts the reasoning from scratch and the new attempt runs out of time exactly like the last one. It also re-uploads the request body, which is the expensive part of a large-context turn.
What changed
Commit 1 makes the bound configurable as
codex.headerTimeoutMs/CCP_CODEX_HEADER_TIMEOUT_MS(env, file, default precedence; values below 1000ms ignored rather than clamped) and moves the default from 60s to 300s.IMAGE_HEADER_TIMEOUT_MSwas already 300s for the same reason.Commit 2 gives the timeout error a
detailmarker,http_response_headers, alongside the existinghttp_response_bodyandhttp_response_ssemarkers, and makesis_retryable_transport_errorrefuse it. That covers the streaming path (retryable_http_stream_errordelegates to it) and the buffered path (post_codex_with_transport). The status and message the client sees are unchanged: still 502, still the same text, just once.header_timeout_retriesis removed — it was carried through the constructors and the test helper behind#[allow(dead_code)]and never read.Left alone
tokio::time::timeoutthat case is indistinguishable from the rest, and the server may already have the body in full.http_response_bodyerrors.retryable_live_start_codex_errorinmod.rs.live_stream_responsealready returns immediately forCodexErrorOrigin::Http, so the provider layer never multiplied these attempts.Tests
http_stream_does_not_resend_after_a_header_timeout— an upstream that accepts the connection, reads the request and never answers. Asserts the error status, message and detail, that the call returns before the first retry backoff would even have elapsed, and that the server accepted exactly one connection. Reverting the classifier change fails it.header_timeout_is_not_retried_by_either_classifier— direct assertion onis_retryable_transport_errorandretryable_http_stream_error.codex_header_timeout_defaults_overrides_and_floors— default, file value, env precedence, and that a sub-floor value falls back to the default rather than being clamped.cargo fmt --all -- --check,cargo clippy --all-targets -- -D warningsandcargo test --allpass on each commit separately.🤖 Generated with Claude Code