Why Codex Waits for 5/5 Reconnects: Retry Budget, WebSocket Fallback, and Proxy Routing
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.
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.
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.
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.