Last updated: · Applies to: Codex CLI; error reports span different versions and providers
Codex stream disconnected before completion: fixes
Codex “stream disconnected before completion” means a response stream ended before normal completion. Check service status, update Codex, run codex doctor, and inspect the configured provider and endpoint. For the WebSocket variant, the Codex source specifically detects closure before response.completed.
What does stream disconnected before completion mean?
The error means Codex did not receive the stream’s normal completion before the connection ended.
For WebSocket responses, the response handler tracks whether response.completed arrived. The message describes an incomplete stream; the accompanying cause and provider matter when diagnosing it.
These exact variants appear in user reports in the official repository:
stream disconnected before completion: error sending request for url (https://chatgpt.com/backend-api/codex/responses)Source: user report #12207.
stream disconnected before completion: websocket closed by server before response.completedSource: user report #24533. Older reports also used a stream error: prefix, as in issue #1597. These reports document symptoms, not one proven cause for every occurrence.
Which official checks should I run first?
Start with service status and the documented CLI update and diagnostic commands.
Check service status
Check OpenAI Status for relevant Codex or API incidents.
Update the installed CLI
The CLI reference documents
codex updatefor releases that support self-update. Otherwise use the update path from the official installation guide.Run diagnostics
Run
codex doctorto check the local installation, configuration, authentication and runtime. Follow the findings that match your environment; the command is documented in the CLI reference.
codex update
codex doctorThese are documented diagnostic and maintenance commands, not a guarantee that updating resolves every dropped stream.
What provider and TLS settings should I inspect?
Inspect ~/.codex/config.toml to confirm that the selected provider and endpoint are the ones you intend to use.
The advanced configuration guide documents model_provider, custom model_providers entries and openai_base_url for the built-in OpenAI endpoint. A custom gateway and the built-in service need different endpoint settings; check your configuration before applying provider-specific advice.
For corporate TLS interception or a private root CA, the official environment-variable reference supports an organization-provided PEM CA bundle through CODEX_CA_CERTIFICATE, with SSL_CERT_FILE as a fallback. This applies to HTTPS, login and secure WebSocket clients. Use this when diagnostics identify a certificate-trust problem.
How many times does Codex reconnect?
The provider source sets the default stream reconnect budget to 5 attempts after a dropped stream.
The current model-provider source defines these defaults:
| Setting | Source default | Meaning |
|---|---|---|
stream_max_retries | 5 | Reconnect attempts after a streaming response drops. |
request_max_retries | 4 | HTTP request retry budget, separate from stream reconnection. |
stream_idle_timeout_ms | 300000 ms (5 minutes) | Allowed inactivity in a response stream, not a maximum total generation time. |
The configuration reference lists these keys under [model_providers.<id>]. The advanced guide says built-in provider IDs cannot be overridden. Do not expect a [model_providers.openai] retry block to change built-in OpenAI behavior. These documented custom-provider settings are not a universal repair for the ChatGPT-backed connection.
Should I resume or start a new session?
Resume when you need the saved conversation, or use /new to start a fresh chat in the current CLI session.
codex resume --lastThe resume command selects the most recent saved chat in the current directory; --all broadens the scope. Resuming restores saved history and does not guarantee recovery of every interrupted response. The command documentation describes /new; starting fresh is a session choice, not a documented cure for a connection failure.
What should I report if it keeps happening?
Use /feedback to send a reproducible report with the available logs and diagnostics.
The official command documentation describes feedback, and an OpenAI contributor in #12207 requests it for this stream error. Include the thread ID requested by the contributor, the exact error, installed version, provider, and the conditions under which it repeats.
Historical explanations need context: in a contributor comment on #8865, delayed token batches were said to be able to exceed an HTTP timeout, and the contributor believed that incident had been mitigated. This describes that incident; it does not establish that every current disconnection is a long-generation timeout. The same issue includes Azure-specific reports that should not be generalized to all providers.
FAQ
What does Codex stream disconnected before completion mean?
It means the response stream ended before normal completion. For the WebSocket variant, the source checks for response.completed before the server closes the connection.
Does Codex automatically reconnect after a dropped stream?
The current provider source defaults to 5 stream reconnect attempts. This is separate from the HTTP request retry default of 4.
Can I fix the built-in provider by setting stream_max_retries?
The current advanced configuration guide says built-in provider IDs cannot be overridden. These retry settings are documented for custom providers; do not assume an openai retry block changes the built-in provider.
Can I resume after a disconnected response?
Use codex resume --last to reopen the most recent saved chat in the current directory. Saved history can be resumed, but recovery of every interrupted response is not guaranteed.
Sources
OpenAI documentation and repository source support the commands and defaults; linked issues are labeled reports or attributed contributor comments.
This is an independent, unofficial guide. It is not affiliated with or endorsed by OpenAI. Check the linked official documentation for your version and environment.