跪拜 Guibai
← All articles
AI · Architecture · OpenAI

Why Codex Waits for 5/5 Reconnects: Retry Budget, WebSocket Fallback, and Proxy Routing

By AAA爱学习的刘哥 ·
Read original on juejin.cn ↗ Google Translate ↗ Alt translation

Choosing a diagnosis based on the reconnect count sends developers chasing proxy settings that aren't the problem. Separating retry budget, transport fallback, and proxy routing turns an opaque wait into a testable chain of events, so you fix the real layer instead of guessing.

Summary

Codex users see 'Reconnecting…' climb toward 5/5 before the first response arrives, then subsequent turns work normally. The common assumption is that the first five attempts bypass the proxy and only the sixth uses it, but that conflates transport protocol with network routing. The counter is actually a retry budget for stream resumptions, controlled by stream_max_retries (default 5), distinct from request_max_retries (default 4) for HTTP requests.

The likely path is a WebSocket failure: the client retries the stream, exhausts its budget, then logs 'Falling back from WebSockets to HTTPS transport.' and resets counters. In Codex 0.166.0 this fallback state persists for the session, so later turns skip the WebSocket attempt and use HTTPS directly. That explains why the first round is slow and later rounds are not.

Debugging requires separating three layers: model API (what task is submitted), transport (WebSocket vs HTTPS+SSE), and proxy routing (which network path carries the data). A diagnostic test is setting supports_websockets = false for a custom provider and observing whether the wait disappears. The retry counter alone cannot distinguish a WebSocket handshake failure, a proxy misconfiguration, or a gateway issue.

Takeaways
— stream_max_retries defaults to 5 and request_max_retries to 4; they control different retry phases.
— In Codex 0.166.0, exhausting WebSocket retries triggers a message 'Falling back from WebSockets to HTTPS transport.' and resets retry counts.
— The transport fallback state is kept for the rest of the session, making subsequent turns faster.
— The reconnect counter is not a count of total connection attempts; the first try isn't a retry and other steps like pre-connection or auth recovery exist.
— Separate three layers when debugging: model API, transport, and proxy routing; an HTTP proxy or CONNECT tunnel does not equal switching from direct to proxied.
— Setting supports_websockets = false for a custom provider is a diagnostic test, not a permanent config; it only narrows the scope.
— Claude Code uses different channels for model requests, MCP connections, and remote sessions, so its retry counts cannot be inferred from Codex's.
Conclusions

The 5/5 counter misleads because it is a configurable retry budget, yet users read it as a count of connection attempts; that mismatch is why the proxy explanation persists.

Session-level fallback state creates an asymmetry: the first turn pays the WebSocket retry cost, but later turns inherit the fallback, so intermittent startup slowness is expected rather than a network anomaly.

The diagnostic approach of disabling WebSocket support to see if the wait disappears is a clean isolation test, but it cannot alone identify proxy versus gateway failure, so it still requires proxy logs and transport-level tracing.

Concepts & terms
stream_max_retries
The upper bound for retrying a streaming response after an interruption in the Codex client; default is 5. It is separate from request_max_retries.
request_max_retries
The upper bound for retrying a failed HTTP request in the Codex client; default is 4.
Server-Sent Events (SSE)
A technique for streaming event data over a single HTTP response; used to deliver tokens and tool call events without a bidirectional channel.
Transport fallback
When a client switches from WebSocket to HTTPS/SSE after exhausting WebSocket retries; in Codex this state is remembered for the rest of the session.
From the discussion
Featured comments
用户21607634083

The '5/5' part hits the nail on the head. Here's a similar trap I hit over the past couple of days: in Node, the fetchOptions.timeout at the simple-get layer doesn't actually take effect when passed down. It hangs for a solid ten-plus seconds and then gives 'Request timed out'. Packet capture shows TCP already connected — it's stuck on reading the response body. I finally switched to my own node:https plugin, using Buffer.concat to collect everything, explicitly setting content-length, and stretching req.setTimeout, and that stabilized it. So the retry counter on the UI almost always points to the application layer; the real pit is usually down at the socket layer.

See top comments, translated →
Source: juejin.cn ↗ Google Translate ↗ Backup ↗