Codex "stream disconnected before completion": fixes
"Stream disconnected before completion" means the reply Codex was streaming from OpenAI broke off before the final response.completed event. Codex retries on its own (the Reconnecting 1/5 counter), and when every retry fails the turn stops, so you need to find out what keeps cutting the stream.
Contents
"Stream disconnected before completion" means the reply Codex was streaming from OpenAI broke off before its final response.completed event arrived. Codex retries on its own, which is the Reconnecting... 1/5 counter you see. When all five tries fail, it prints the error and the turn stops. Your session is still saved, so the job is finding out what keeps cutting the stream.
The text after the colon is the clue. These are the versions people paste into Codex's issue tracker:
stream disconnected before completion: error sending request for url (https://chatgpt.com/backend-api/codex/responses)
stream error: stream disconnected before completion: Transport error: error decoding response body
stream disconnected before completion: stream closed before response.completed
stream disconnected before completion: websocket closed by server before response.completed
What "stream disconnected before completion" means#
Codex's source raises this error when the stream "disconnects or errors out after the HTTP handshake has succeeded but before it finished emitting response.completed", and treats it as transient: it retries the turn by itself. The defaults, read on 24 October 2026:
| Setting | Default | What it covers |
|---|---|---|
stream_max_retries |
5 | Tries after a stream breaks off (the 1/5 counter) |
request_max_retries |
4 | Tries when the HTTP request itself fails |
stream_idle_timeout_ms |
300000 (5 minutes) | How long a stream may send nothing before Codex drops it |
stream disconnected before completion: Incomplete response returned, reason: content_filter is the odd one out. OpenAI's content filter ended that reply, and nothing on the network side will change it. Codex retries it like the others. When it comes back every time, reword the request.
Why Codex keeps disconnecting#
Start with one test, a one-line prompt in a fresh session. If even that fails, the fault is everywhere; if it works, it's in the one conversation.
| What you see | Most likely cause |
|---|---|
| Every prompt fails, even "hi" in a new session, and other people report it at the same time | An OpenAI incident |
| Every prompt fails on this network, works on another (phone hotspot, VPN off) | VPN, proxy, firewall or antivirus that inspects TLS |
Fails right after you changed config.toml |
A wrong openai_base_url, base_url or model_provider |
| Long turns die partway, short ones work | An old Codex version, or a stream that went quiet past the idle timeout |
| One old conversation fails, new ones work | Something in that session's history |
Four issues on Codex's tracker line up with those rows. They are reports, not fixes.
- #11741, 13 February 2026: a run of
Reconnecting... 1/5ending inerror sending request for url. Two more people reported it within half an hour, one of them on very short prompts, and the maintainer asked for logs through/feedback. - #3478: turns cut off at about 150 seconds on codex-cli 0.33.0. Closed in September 2025 as fixed in newer versions.
- #54407: one conversation fails with
stream closed before response.completedafter its original model stopped being supported with a ChatGPT sign-in. Fresh chats on the same machine work. - #55730, filed from the Codex app: an image-heavy chat built a request larger than the WebSocket transport accepts. Five retries failed, then Codex fell back to HTTP and the request went through.
How to fix stream disconnected before completion#
- Update Codex.
codex updateapplies an update "when the installed release supports self-update", in the words of OpenAI's command reference. For a release that can't, reinstall through whatever put it there:npm install -g @openai/codex,brew upgrade --cask codex, or the script athttps://chatgpt.com/codex/install.sh. - Check status.openai.com. It has a Codex group with its own CLI row. If it shows an incident, waiting is the fix.
- Test a short prompt in a new session. Run
codexin an empty folder and ask something one line long. If that works and your real session doesn't, skip to step 6. - Take the network out of it. Turn the VPN off or try another network. Behind a company proxy that decrypts TLS, point Codex at the proxy's certificate: OpenAI documents
CODEX_CA_CERTIFICATEas "a PEM CA bundle for environments with corporate TLS interception", withSSL_CERT_FILEas the fallback (environment variables). OpenAI lists it for HTTPS, login and WebSocket clients alike, so it is the same fix as for a Codex login that fails behind a proxy. - Check
~/.codex/config.toml. Look atmodel_provider,openai_base_urland anybase_urlunder[model_providers.<id>]. Codex ignores those keys in a project's.codex/config.toml, so set them in your user config.codex doctorreports on installation, config and auth in one go. Our config.toml guide has the layout of the file. - Resume, or start clean. The session survived the error. Send the message again where you were; after closing the terminal,
codex resume --lastin the same folder picks it up. A conversation that keeps failing while new ones work has the cause in its history, and/forkcopies that history along with it./newis the clean start, with the context typed in again. Every resume and fork command is listed in resuming a Codex session. - Report it with logs.
/feedbacksends logs to the Codex maintainers, which is what the maintainer asked for on #11741.
Raising the retry count#
stream_max_retries, request_max_retries and stream_idle_timeout_ms are per-provider keys under [model_providers.<id>], capped at 100 retries in Codex's source. OpenAI's config reference says the built-in openai, ollama and lmstudio IDs "are reserved and cannot be overridden", so with a plain ChatGPT sign-in the defaults stay. For a provider you define yourself:
model_provider = "myproxy"
[model_providers.myproxy]
name = "My OpenAI-compatible server"
base_url = "https://llm.example.internal/v1"
wire_api = "responses"
env_key = "MYPROXY_API_KEY"
stream_max_retries = 10
request_max_retries = 6
Stream error or usage limit?#
A limit has its own message. Codex says "You've hit your usage limit" and usually gives a time to try again, and resending won't help before then. A stream error can clear on the next try. Codex usage limit reached covers the limit messages and what to do about each.
How Shuriken handles a dropped Codex stream#
Shuriken runs Codex chats on your own computers and servers, through Codex itself, so Codex's five retries run first. When Codex gives up with this error, the chat doesn't stop. It shows a line like "Connection lost: retrying (1) · next in 5 s", with Retry now and Stop retrying, then sends "Continue where you left off." into the same conversation after 5, 10, 20 and 40 seconds, then about once a minute. After about five hours of failures it tries every five minutes. If the computer itself is offline, the chat says "Waiting for the connection…" and spends no tries. This is on by default.
For an OpenAI-compatible endpoint you add as a Codex source, Shuriken also sets Codex's own stream_max_retries and request_max_retries to 100, the most Codex allows. A ChatGPT sign-in keeps Codex's defaults, for the reason above. A usage limit takes a different path: the chat moves to another ChatGPT account you've added when its current turn ends. Use only accounts you own and are entitled to use; providers' terms may not allow sharing a subscription sign-in. If you want a second agent next to Codex, Claude Code vs Codex compares the two, and you can download Shuriken to run both in one place.
Sources
- openai/codex on GitHub: codex-rs/protocol/src/error.rs (the error and when it is raised) (accessed 24 October 2026)
- openai/codex on GitHub: codex-rs/model-provider-info/src/lib.rs (retry and idle-timeout defaults) (accessed 24 October 2026)
- OpenAI: Codex config reference (model_providers, openai_base_url) (accessed 24 October 2026)
- OpenAI: Codex environment variables (CODEX_CA_CERTIFICATE, SSL_CERT_FILE) (accessed 24 October 2026)
- OpenAI: Codex CLI command reference (codex update, codex doctor, /feedback) (accessed 24 October 2026)
- openai/codex on GitHub: README (install with the script, npm or Homebrew) (accessed 24 October 2026)
- OpenAI status page (accessed 24 October 2026)
- openai/codex issue #3478: requests cut off at about 150 s (accessed 24 October 2026)
- openai/codex issue #11741: error sending request for url (accessed 24 October 2026)
- openai/codex issue #54407: resuming one conversation fails, fresh chats work (accessed 24 October 2026)
- openai/codex issue #55730: image-heavy chat over the WebSocket size limit (accessed 24 October 2026)
Frequently asked questions
What does Reconnecting 1/5 mean in Codex?
Codex lost the streamed reply and is sending the request again. 5 is the default stream_max_retries; when the fifth try fails as well, Codex prints stream disconnected before completion and the turn stops.
Is stream disconnected before completion the same as hitting my usage limit?
No. A usage limit comes with its own message, starting You've hit your usage limit, and usually names a time to try again. A stream error is the connection dropping mid-reply, and the same message sent again can go through at once.
Can I raise the number of retries in Codex?
Only for a provider you define yourself, under model_providers in ~/.codex/config.toml (stream_max_retries and request_max_retries). Per OpenAI's config reference the built-in openai provider is reserved and can't be overridden, so a ChatGPT sign-in stays at 5 and 4.
Do I lose my work when Codex says stream disconnected?
No. Codex writes the session to ~/.codex/sessions while it runs. Send the message again in the same session; if you closed it, codex resume --last in the same folder reopens it.
Why does only one old conversation fail while new ones work?
On Codex's GitHub it shows up with image-heavy histories, and with a session that began on a model a ChatGPT sign-in no longer supports. The cause sits in the history, which a fork copies, so a fork can fail the same way; start a new chat with /new and give it the context it needs.