# Codex says "stream disconnected before completion" or keeps "Reconnecting... 5/5"

> Markdown mirror of https://router.one/codex-stream-disconnected for AI assistants and crawlers. Router One is a unified, OpenAI-compatible LLM API gateway.
> Last updated: 2026-11-30

This error is normally a broken stream or network hop, not a usage limit: the response ended before `response.completed` arrived (per openai/codex rust-v0.172.0, checked 2026-11-30). Codex retries interrupted streams up to `stream_max_retries` times (default 5, cap 100), printing `Reconnecting... n/5`; on the built-in OpenAI provider, which starts on WebSockets, release builds hide `1/5`, and after 5 retries Codex falls back to HTTPS for another round. Read the exact suffix below — two non-network cases share this prefix: `content_filter` output blocks and server messages such as ChatGPT Subscription Sharing limits.

## Match the text after the colon

Each variant below comes from the openai/codex rust-v0.172.0 source or from openai/codex GitHub issues (checked 2026-11-30). Lines with an `os error` or `tls handshake eof` come from WebSocket connections, so from the built-in `openai` provider:

| Message or suffix | Meaning | First check |
| --- | --- | --- |
| `stream closed before response.completed` | SSE or WebSocket hit EOF before `response.completed`. | Check your provider's status page (Router One: https://router.one/status), then test without proxies or VPNs. |
| `idle timeout waiting for SSE` / `idle timeout waiting for websocket` | No event or frame arrived within `stream_idle_timeout_ms` (default 300,000 ms / 5 min). SSE comments (`: ping`) do not reset the timer. | Raise `stream_idle_timeout_ms` (e.g., `600000`) on your custom provider block and check stalled proxies. |
| `websocket closed by server before response.completed` | Server or WebSocket proxy sent a Close frame mid-turn. | Let Codex fall back to HTTPS, or use a custom provider (`supports_websockets` defaults to `false`). |
| `error sending request` (older builds add `for url (…)`) | The HTTP request failed after the connection was up and before any response. A failed connection (DNS, refused port, TLS, unreachable proxy) now shows as `Connection failed: error sending request` under `Reconnecting... waiting for network`. | Check `HTTPS_PROXY` / `HTTP_PROXY` / `ALL_PROXY` and `~/.codex/.env`; run a key-free `curl` test (https://router.one/api-connection-troubleshooting). |
| `Transport error: network error: error decoding response body` | The HTTPS stream was cut or damaged after it had started; this is what an HTTPS provider prints where WebSocket users see the `os error` lines. | Try another network or bypass the proxy; check your provider's status page (https://router.one/status on Router One). |
| `tls handshake eof` | Connection closed during TLS negotiation. | Check local proxy (TUN/HTTP), corporate TLS inspection, or ISP reset; test another network or `curl`. |
| `Connection refused (os error 61)` / `No connection could be made because the target machine actively refused it. (os error 10061)` | Nothing listens on the host and port Codex dialed (macOS 61; Windows 10061). An HTTPS provider shows `Reconnecting... waiting for network` instead. | Look for an old proxy line in `~/.codex/.env` (it overrides the shell) and in your shell, then for a base URL in `config.toml` that points at a local port. |
| `IO error: Broken pipe (os error 32)` | macOS/Linux: Codex wrote to a socket that was already closed. | Check the proxy's idle limits, run `/compact`, or try an HTTPS custom provider (`supports_websockets` off). |
| `IO error: … (os error 10053)` / `(os error 10054)` | Windows drops. `10053`: the connection was aborted on your machine, possibly after a timeout or protocol error (Microsoft's Winsock docs); security software, a VPN or a proxy can also be involved. `10054`: the other end, or something in between, reset it. | Check the Windows proxy, VPN/TUN, firewall and TLS scanners, and try another network. |
| `Incomplete response returned, reason: content_filter` | Not a network error. Output content filtering stopped the reply; Codex still retries with guidance (`Reconnecting... n/5`). | Do not debug your network. Rephrase the prompt, avoid verbatim triggering text, or run `/model`. |
| `Reconnecting... waiting for network` (second line: `Connection failed: error sending request`) | The HTTP connection could not be opened (`ConnectionFailed`). With `unbounded_connection_retries` (on by default), a normal model turn retries indefinitely with 5 s–60 s backoff. | Press `Ctrl-C` / `Esc`, then fix DNS, proxy, cert trust, or offline network (https://router.one/api-connection-troubleshooting). |

- Subscription Sharing exception: Codex prints unrecognized `response.failed` messages after `stream disconnected before completion:`. If the text says `The ChatGPT user has reached their Subscription Sharing usage limit`, it is a sharing limit, not a network drop — see https://router.one/chatgpt-subscription-sharing-errors.

## Fix order: seven steps from server to prompt

Follow this order so you do not tune timeouts for a dead proxy or debug networks for a content filter:

### 1. Check for a provider outage

Check your provider's status page (https://router.one/status on Router One). If a fresh thread works while one long thread fails, jump to step 6.

### 2. Check proxies, VPNs, and ~/.codex/.env

Per rust-v0.172.0 (checked 2026-11-30), Codex loads `~/.codex/.env` when it starts and its lines win over your shell, so look there first for an old `HTTPS_PROXY`, `HTTP_PROXY` or `ALL_PROXY`. WebSocket connections use only those variables and `NO_PROXY`; HTTP requests can also pick up a macOS or Windows system proxy when no proxy variable is set. Following the system proxy everywhere is the experimental `respect_system_proxy` feature, off by default (`/experimental`, or `codex features enable respect_system_proxy`). Compare with a key-free `curl` (https://router.one/api-connection-troubleshooting). In openai/codex #44517 a user traced `os error 10061` and an endless `waiting for network` to an old proxy line in `~/.codex/.env`.

### 3. Check base_url and model_provider

Inspect user `~/.codex/config.toml` (project-local `.codex/config.toml` ignores `model_provider` and `model_providers`, Codex docs checked 2026-11-30). Confirm `base_url` targets a live Responses host (`https://api.router.one/v1` for Router One).

### 4. Avoid WebSocket drops with a custom HTTPS provider

Per `model-provider-info/src/lib.rs` (rust-v0.172.0, checked 2026-11-30), only built-in `openai` sets `supports_websockets = true`; custom `[model_providers.<id>]` blocks default to `false` and use HTTPS SSE, so `websocket closed by server` cannot occur there. Connection resets still can: users report them on the HTTPS fallback too (openai/codex #37089), and one reporter saw no change after turning WebSockets off (#44099).

### 5. Tune stream_idle_timeout_ms and stream_max_retries

For slow reasoning turns hitting `idle timeout`, raise `stream_idle_timeout_ms` (default 300,000 ms) and adjust `stream_max_retries` (default 5, cap 100) or `request_max_retries` (default 4, cap 100) on your custom provider block. Built-in IDs (`openai`, `ollama`, `lmstudio`) cannot take these keys: putting them in a `[model_providers.openai]` block makes Codex reject the whole config.

### 6. Compact long contexts and drop large media

Long histories and screenshots make requests larger and slower to start; in openai/codex #44099 a user saw `Broken pipe` more often on turns with several images. Codex switches to HTTPS without using up its retries when a message exceeds the peer's WebSocket size limit, or when the server answers the upgrade with HTTP 426. Run `/compact` or start a new thread; see https://router.one/codex-context-window.

### 7. Handle content_filter on the prompt side

For `Incomplete response returned, reason: content_filter`, skip network checks: rephrase the prompt, avoid verbatim reproduction of filtered passages, or switch models with `/model`.

## Custom HTTPS provider config.toml with stream timeouts

This `~/.codex/config.toml` sends Codex to Router One over HTTPS SSE. Custom providers leave `supports_websockets` at `false`; keep `requires_openai_auth` off, because the key comes from `ROUTER_ONE_API_KEY`. Router One does not end a named model's native `/v1/responses` stream for being idle, so an idle timeout is Codex's own timer; Dashboard → Logs then shows HTTP 499 `client_cancelled`, and each retry is a separate request (what a cancelled stream is billed: https://router.one/llm-streaming). Logs cover each request the gateway forwards to a model; a stream that failed before any output may have no record:

`~/.codex/config.toml`

```toml
# ~/.codex/config.toml
model = "gpt-6.2-sol"
model_provider = "router"

[model_providers.router]
name = "router"
base_url = "https://api.router.one/v1"
env_key = "ROUTER_ONE_API_KEY"
wire_api = "responses"
stream_idle_timeout_ms = 600000
stream_max_retries = 5
request_max_retries = 4
# supports_websockets defaults to false on custom providers (uses HTTPS SSE)

# in the shell that starts codex (or in ~/.codex/.env):
# export ROUTER_ONE_API_KEY="sk-your-router-one-key"
```

## FAQ

### Why does Codex show "Reconnecting... 2/5" first, or retry a second round?

Per `core/src/responses_retry.rs` (rust-v0.172.0, checked 2026-11-30), release builds hide `1/5` while WebSockets are enabled on built-in `openai`, so `2/5` appears first. When those 5 WebSocket retries run out, Codex logs `Falling back from WebSockets to HTTPS transport.`, switches the session to HTTPS, and resets retries to 0 for a second round up to `5/5`.

### Why is Codex stuck on "Reconnecting... waiting for network" forever?

`unbounded_connection_retries` is stable and enabled by default in rust-v0.172.0 (`features/src/lib.rs`, `responses_retry.rs`, checked 2026-11-30). When the HTTP connection for a normal model turn cannot be opened (`ConnectionFailed`), Codex retries indefinitely with 5 s–60 s backoff instead of stopping at `5/5`. Cancel with `Ctrl-C` / `Esc` and fix DNS, proxy, certificate trust, or `~/.codex/.env` (https://router.one/api-connection-troubleshooting).

### How do I fix "idle timeout waiting for SSE" or "idle timeout waiting for websocket"?

Codex received no SSE event or WebSocket frame for `stream_idle_timeout_ms` (default 300,000 ms / 5 minutes); SSE comment keepalives (`: ping`) are dropped by the parser and do not reset it. Raise `stream_idle_timeout_ms` (e.g., `600000`) on your custom `[model_providers.<id>]` block in `~/.codex/config.toml` and check for stalling proxies.

### Can I set stream_max_retries or stream_idle_timeout_ms on the built-in openai provider?

No. Per `config/src/config_toml.rs` (rust-v0.172.0, checked 2026-11-30), `openai`, `ollama` and `lmstudio` are reserved IDs: a block that sets retry, timeout or `supports_websockets` keys on them stops the config from loading with `model_providers contains reserved built-in provider IDs`. Define a custom `[model_providers.<id>]` block (such as `[model_providers.router]`) and select it with `model_provider` in `~/.codex/config.toml`.

### Why do I get "Connection refused (os error 61 / 10061)" when curl works?

Codex and `curl` may be taking different routes. Users have reported two causes: an old `HTTPS_PROXY` / `HTTP_PROXY` / `ALL_PROXY` line in `~/.codex/.env`, which Codex loads at startup over your shell (openai/codex #44517), and a base URL in `config.toml` that points at a local port with no server behind it (#53222). Check both, then restart Codex.

### What do "Broken pipe (os error 32)", "os error 10053", "os error 10054", and "tls handshake eof" mean?

All four are dropped connections on a WebSocket. `Broken pipe (os error 32)` (macOS/Linux): Codex wrote to a socket that was already closed. Windows `10053`: the connection was aborted on your machine, possibly after a timeout or protocol error. `10054`: the other end or something in between reset it. `tls handshake eof`: the connection closed during the TLS handshake. Trying another network and an HTTPS-only custom provider helps tell a WebSocket problem from a network one.

### Does "stream disconnected before completion" mean I hit my usage limit?

Normally no — most variants are network, proxy, WebSocket, timeout, or `content_filter` issues. The exception is a server message forwarded from `response.failed`, such as `The ChatGPT user has reached their Subscription Sharing usage limit` (see https://router.one/chatgpt-subscription-sharing-errors). Standard ChatGPT plan limits print `You’ve hit your usage limit` instead (https://router.one/codex-usage-limit).

## See also

- Codex unexpected status errors (402/403/404/413/502): https://router.one/codex-unexpected-status
- ChatGPT Subscription Sharing errors: https://router.one/chatgpt-subscription-sharing-errors
- Codex context window: https://router.one/codex-context-window
- Codex Responses API: https://router.one/codex-responses-api
- Codex 401 and missing variable fix: https://router.one/codex-401-unauthorized
- Codex exceeded retry limit (429): https://router.one/codex-exceeded-retry-limit
- Codex model at capacity: https://router.one/codex-model-at-capacity
- Codex usage limit: https://router.one/codex-usage-limit
- API connection troubleshooting (DNS/TLS/proxy): https://router.one/api-connection-troubleshooting
- LLM streaming guide: https://router.one/llm-streaming
- LLM API error codes: https://router.one/llm-api-error-codes
- Live model status: https://router.one/status
- Canonical page: https://router.one/codex-stream-disconnected
- Models and per-model token rates: https://router.one/models (markdown: https://router.one/models.md)
- Pricing: https://router.one/pricing
- API docs (markdown): https://router.one/docs.md
- Company facts: https://router.one/facts/company.md
