Codex "stream disconnected before completion": Proxy, Cert, WSL Fixes
When Codex reports stream disconnected before completion, the request went out and the model started streaming a response, but the connection was dropped before the answer finished. It is only an outer wrapper. The real cause is written after the colon, and it usually falls into one of four buckets: an outage on the official service, a local proxy that isn't picking up traffic or that cuts long-lived connections, a bad certificate or system clock, or a WSL network that isn't the same as the one Windows uses. Spend one minute checking whether it's an official outage, then pick one path based on the text after the colon. That is faster than repeatedly changing the proxy port.
What does this error actually mean?
Codex and the server hold a streaming connection. After the request is sent, the server pushes data back as it generates it, until it emits a "completed" event. stream disconnected before completion means the client never received that event before the connection dropped.
The break can happen at any hop: the server closing the connection, an intermediate proxy or security product timing out and cutting it, a local TLS verification failure, or packet loss on WSL's virtual network adapter. So the same message can have completely different causes on different machines. The popular advice to "just change the proxy port" only helps in one of those cases.
Codex automatically retries a dropped stream and only surfaces this error after the retries are used up. So when you see it, it is usually not a single random packet loss.
Step 1: What does the text after the colon say?
The full error usually looks like this (examples):
stream disconnected before completion: error sending request for url (https://...)
stream disconnected before completion: Transport error: ... connection reset
stream disconnected before completion: idle timeout waiting for SSE
Match the part after the colon against this table:
| Keyword after the colon | Most likely cause | Where to look |
|---|---|---|
error sending request, connection refused, dns error | The request never left: proxy not in effect, or DNS resolution failed | Proxy |
connection reset, broken pipe, unexpected EOF | Connection cut midway: proxy or security software, or a server-side problem | Check for an outage first, then the proxy |
idle timeout, timed out | No data for a long time: the network is stuck, or the server is queuing | Outage, WSL |
certificate, invalid peer certificate, UnknownIssuer | Certificate chain not trusted, or wrong system time | Certificates and clock |
| An HTTP status code is returned (such as 5xx) | Server or gateway problem | Outage |
| Only in WSL; native Windows terminal works | WSL network mode and proxy address | WSL |
If the error includes an identifier such as a request id, write it down together with the time. Whether you report it to the vendor or compare it against a status page later, those two items are far more useful than "it dropped again."
Next, check Codex's local logs. The CLI generally writes logs under ~/.codex/log/. You can view recent errors like this:
tail -n 100 ~/.codex/log/codex-tui.log | grep -iE "error|disconnect|retry|websocket"
If the log contains something like falling back from websockets to HTTPS transport, the WebSocket connection Codex tried to open did not come up, and it fell back to a plain HTTPS streaming request. That is not necessarily an error by itself, but it often hints that a proxy in the path does not support connection upgrades or blocks them, which is a lead for the proxy checks below.
Is OpenAI having a problem?
This step saves the most time, so do it first.
- Open /en/down/codex. It aggregates the official status page, an API probe every 5 minutes, and one-click reports from other users. If many people have reported "can't connect" or "slow" in a short period, the problem is very likely not just you.
- Open /en/status/openai to see the probe results for the API endpoint and recent official incidents.
- If both look normal, move on to your own machine.
Here is a checkable example. cdnping's probe from the Cloudflare Denver (DEN) node to api.openai.com, in the window 2026-10-17 08:40–10:05 (UTC), showed a latest round trip of 111 ms, a window median of 96 ms, p95 of 194 ms, and 100% availability. That means the OpenAI API endpoint was reachable from an overseas edge at that time. It does not mean your route is fine: the probe sits in the US, while your traffic first goes through your local network and proxy. cdnping only began collecting data on 2026-10-17, so this is a single point-in-time example, not long-term statistics.
The official status page also records Codex-related incidents. In the OpenAI status page records synced by cdnping, there is a "Degraded performance in Codex and ChatGPT Work" entry at 2026-10-14 07:05 (UTC), severity minor, lasting about 167 minutes, and a "Widespread feature degradation" entry at 2026-10-15 16:29 (UTC), severity major, lasting about 146 minutes. From 2026-09-17 to 2026-10-17, the OpenAI status page recorded 4 major incidents and 19 minor ones in total. For how to read incident severity, see How to read the OpenAI and Claude status pages. If your error time falls inside an incident window like these, stop fiddling with your machine. The approach is the same as in Is ChatGPT down? Three steps to tell an outage from your own network.
Proxy: is Codex in the terminal really using the proxy?
This is the most common category. Many people turn on a proxy in system settings, see that the browser works, and assume the terminal does too. In fact, the Codex CLI is a command-line program and reads environment variables in the terminal, such as HTTPS_PROXY, HTTP_PROXY and ALL_PROXY, not the system proxy settings.
How do I check the proxy variables in the terminal?
# macOS / Linux / WSL
env | grep -i proxy
# Windows PowerShell
Get-ChildItem Env: | Where-Object Name -match proxy
No output means the requests Codex sends go out directly. Set them to the address your local proxy software actually listens on (the port below is only an example):
export HTTPS_PROXY=http://127.0.0.1:7890
export HTTP_PROXY=http://127.0.0.1:7890
Then use curl to verify that this path returns a complete response:
curl -sv https://api.openai.com/v1/models -o /dev/null 2>&1 | grep -E "Connected|HTTP/|issuer"
Seeing HTTP/2 401 or HTTP/1.1 401 is normal. It means the connection, TLS and server all work, and you simply didn't send a key. If it hangs or reports Connection refused, the problem is still in the proxy layer.
One more thing to note: when you sign in to Codex with a ChatGPT account versus an API key, the request domains are not exactly the same. For which domains and ports need to be allowed, see Network requirements for Claude Code and Codex. If your proxy routes by domain and misses one of them, you get "works sometimes, drops sometimes." For how routing rules work, see /en/learn/split-tunneling.
Why do short prompts work but long tasks drop midway?
This is usually a middlebox cutting long connections. When Codex runs an agent task, one stream can last several minutes, with stretches in between that carry no data. The following can cut it off:
- a short idle timeout on the proxy client or the upstream node;
- the egress gateway on a corporate network;
- security or antivirus software that does HTTPS inspection (TLS decryption), terminating TLS locally and re-originating it, which doesn't always handle streaming responses completely.
To verify, use a streaming request that keeps producing output for a while and see whether it drops after a fixed duration:
time curl -sN https://api.openai.com/v1/responses \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model":"<your model>","input":"Write a very long essay","stream":true}' \
| tail -n 3
If it drops at about the same point every time, check the timeout settings of your proxy or security software. If you can see the completion event at the end, the link can sustain a long stream, and the problem is more likely in Codex's configuration or on the server side.
Environment variables behave similarly across tools. The NO_PROXY pitfalls covered in Claude Code proxy settings not working: checking HTTPS_PROXY, NO_PROXY and certificate variables one by one, such as it accidentally matching internal addresses, apply to Codex as well.
Certificates and system time: is something wrong at the TLS layer?
If certificate or UnknownIssuer appears after the colon, you can pretty much pin the problem to this layer.
Who issued the certificate you are seeing?
openssl s_client -connect api.openai.com:443 -servername api.openai.com </dev/null 2>/dev/null \
| openssl x509 -noout -issuer -dates
Normally the issuer is a public certificate authority. If you see a company name, an antivirus product name or a proxy tool's name, some software in the middle is decrypting TLS. A browser trusting that root certificate doesn't mean Codex does: command-line programs often use their own certificate store. There are two fixes: add the relevant domains to the security software's no-inspection list, or add the company root certificate to a certificate store Codex can read, for example by updating the system CA bundle on Linux or setting SSL_CERT_FILE to a file containing that root. Whether Codex supports other dedicated variables is something to confirm in the official documentation.
Is the system time correct?
Certificates have validity periods, and if the local clock is far off, verification fails outright. You can compare the notBefore and notAfter from the command above with your local time:
date -u
If it differs from your phone's time by more than a few minutes, correct it. A clock that falls behind after Windows sleep and wake is common in WSL. You can run sudo hwclock -s, or simply restart WSL (wsl --shutdown in PowerShell).
WSL: why does Windows work but Codex in WSL keeps dropping?
Many people run Codex inside WSL while the proxy client is installed on Windows. In the default NAT networking mode, 127.0.0.1 inside WSL refers to WSL itself, not Windows, so copying the proxy address from Windows doesn't work.
Check in this order:
- Confirm the networking mode. In
%UserProfile%\.wslconfigon Windows, look fornetworkingMode=mirrored. In mirrored mode, WSL and Windows share the network and127.0.0.1works directly. This mode has Windows version requirements, so follow Microsoft's official documentation. - In NAT mode, use the host address instead (replace the port with the one your proxy software actually listens on):
You also need to enable "Allow LAN connections" in the proxy client and confirm Windows Firewall isn't blocking that port.HOST_IP=$(ip route show default | awk '{print $3}') export HTTPS_PROXY=http://$HOST_IP:7890 curl -sv https://api.openai.com/v1/models -o /dev/null 2>&1 | grep "HTTP/" - Check the MTU. When WSL's virtual adapter is stacked with a proxy or VPN, large packets may be dropped. The symptom is a successful handshake, then a stall after a short while, ending in a timeout or disconnect.
ip link show eth0shows the current MTU; for how to diagnose and adjust it, see What MTU should I use? Large-packet black holes that hang HTTPS. - Compare against the native Windows terminal. Run Codex, or the curl above, in PowerShell at the same time. If Windows works and WSL doesn't, the problem is in the WSL segment.
Can I tune Codex's own timeouts and retries?
Yes, but that only eases occasional stream drops and cannot fix the root causes above. In Codex's config.toml, the provider settings support fields such as a stream idle timeout and retry counts, for example stream_idle_timeout_ms, stream_max_retries and request_max_retries. Field names and defaults may change between versions. For syntax, see Codex CLI config.toml field reference, and treat the official documentation as final.
Tuning makes sense when you have already confirmed the link can complete a long stream and it only occasionally drops during network jitter. It does not make sense when it drops at the same point every time, or when certificate verification fails. In those cases, raising retries just delays the failure.
A checklist you can follow
| Order | Check | Command or page | Normal result |
|---|---|---|---|
| 1 | Record the reason after the colon, the time and the request id | The error text, ~/.codex/log/ | A complete record |
| 2 | Is the official service down? | /en/down/codex, /en/status/openai | No ongoing incident, no obvious rise in user reports |
| 3 | Does the terminal have proxy variables? | env | grep -i proxy | Yes, and the address matches the proxy software |
| 4 | Is the proxy path reachable? | curl -sv https://api.openai.com/v1/models | Returns 401 |
| 5 | Can a long stream finish? | Streaming curl with time | The completion event appears, no drop at a fixed duration |
| 6 | Certificate issuer | openssl s_client ... | openssl x509 -issuer | A public certificate authority |
| 7 | System time | date -u | Very close to standard time |
| 8 | WSL networking | .wslconfig, host IP, MTU | Proxy address points to Windows, sensible MTU |
| 9 | Egress and latency profile | /en/ip | Egress location matches expectations, no abnormal round-trip gap |
Item 9 is there to confirm where your traffic finally exits. Check your egress IP at /en/ip, then look at the latency profile: if the browser-measured round trip and the TCP round trip Cloudflare measures at the exit differ greatly, there is an extra relay layer in between, and the longer the path, the more chances a long-lived connection gets cut. For the principle, see How websites detect proxies from latency. The browser measures the browser's path; the terminal's path has to be verified separately with the curl commands above.
If it still drops after all that?
Gather the following before posting to the official community or a GitHub issue: the Codex version (codex --version), your operating system and whether you are in WSL, the full reason after the colon, the request id, the time it happened (with time zone), and the results from the checklist above.
If you are using a third-party compatible endpoint rather than the official OpenAI endpoint, the drop may also happen on the gateway side. Take AGI Plan as an example (AGI Plan is a commercial partner of cdnping). It publishes availability based on real requests, counts only 5xx as platform failures, and cdnping's /en/status/agiplan page mirrors it, so you can compare your error time against failure spikes at the gateway. For how to change the endpoint address, see Custom API endpoints for Claude Code, Codex and OpenCode. Whichever path you take, follow the terms of service and local regulations.