codex - 💡(How to fix) Fix Responses WebSocket closes before response.completed [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openai/codex#20739Fetched 2026-05-03 04:46:28
View on GitHub
Comments
1
Participants
2
Timeline
6
Reactions
1
Author
Timeline (top)
labeled ×3commented ×1cross-referenced ×1unlabeled ×1

Codex intermittently loses the Responses WebSocket stream before receiving response.completed, causing turns to retry or fail with:

stream disconnected before completion: websocket closed by server before response.completed

Reference/session id from the affected Codex run:

019de6d6-2863-7401-99e4-af3ed9b0f4a9

Root Cause

The stream appears to close at the transport layer rather than because of project code. The active project has no OpenAI/WebSocket streaming implementation; this is coming from Codex runtime logs.

Code Example

stream disconnected before completion: websocket closed by server before response.completed

---

019de6d6-2863-7401-99e4-af3ed9b0f4a9

---

model_client.stream_responses_websocket{model=gpt-5.5 wire_api=responses transport="responses_websocket" api.path="responses" turn.has_metadata_header=true websocket.warmup=false}: codex_core::client: new
model_client.websocket_connection{provider=OpenAI wire_api=responses transport="responses_websocket" api.path="responses" turn.has_metadata_header=true}: codex_core::client: new
model_client.websocket_connection{provider=OpenAI wire_api=responses transport="responses_websocket" api.path="responses" turn.has_metadata_header=true}: codex_core::client: close
codex_core::session::turn: stream disconnected - retrying sampling request (1/5 in 206ms)...

---

dscacheutil -q host -a name api.openai.com
name: api.openai.com
ip_address: 172.66.0.243
ip_address: 162.159.140.245

nc -vz api.openai.com 443
Connection to api.openai.com port 443 [tcp/https] succeeded!
RAW_BUFFERClick to expand / collapse

Summary

Codex intermittently loses the Responses WebSocket stream before receiving response.completed, causing turns to retry or fail with:

stream disconnected before completion: websocket closed by server before response.completed

Reference/session id from the affected Codex run:

019de6d6-2863-7401-99e4-af3ed9b0f4a9

Environment

  • Codex CLI: codex-cli 0.128.0
  • OS: macOS 26.4.1, Darwin 25.4.0, arm64
  • Model: gpt-5.5
  • Wire API: responses
  • Transport: responses_websocket
  • Provider: OpenAI

What is happening

During normal Codex turns, the runtime opens a Responses WebSocket connection, then the connection closes before the stream emits a final response.completed event. The client retries the sampling request, but this has been recurring across turns.

Representative local log lines:

model_client.stream_responses_websocket{model=gpt-5.5 wire_api=responses transport="responses_websocket" api.path="responses" turn.has_metadata_header=true websocket.warmup=false}: codex_core::client: new
model_client.websocket_connection{provider=OpenAI wire_api=responses transport="responses_websocket" api.path="responses" turn.has_metadata_header=true}: codex_core::client: new
model_client.websocket_connection{provider=OpenAI wire_api=responses transport="responses_websocket" api.path="responses" turn.has_metadata_header=true}: codex_core::client: close
codex_core::session::turn: stream disconnected - retrying sampling request (1/5 in 206ms)...

The stream appears to close at the transport layer rather than because of project code. The active project has no OpenAI/WebSocket streaming implementation; this is coming from Codex runtime logs.

Network sanity check

I checked local connectivity outside the Codex sandbox:

dscacheutil -q host -a name api.openai.com
name: api.openai.com
ip_address: 172.66.0.243
ip_address: 162.159.140.245

nc -vz api.openai.com 443
Connection to api.openai.com port 443 [tcp/https] succeeded!

Inside the sandbox, DNS/connectivity probes can fail, but the host network itself can resolve and connect to api.openai.com:443.

Expected behavior

Codex should keep the Responses WebSocket stream open until it receives response.completed, or surface a more specific upstream/server-close reason when the server closes the socket before completion.

Actual behavior

The WebSocket closes before response.completed, producing repeated stream disconnected retries and occasionally interrupting completion of the turn.

Notes

This looks upstream/runtime-side rather than repository/app-side:

  • The affected project is a small Vite app with no OpenAI streaming code.
  • The failure happens in Codex's responses_websocket transport path.
  • Host-level DNS and TCP connectivity to api.openai.com:443 succeed.

extent analysis

TL;DR

The issue can be mitigated by investigating the OpenAI WebSocket connection closure and potentially adjusting the Codex configuration or retry mechanism.

Guidance

  • Investigate the OpenAI server-side logs to determine the reason for the premature WebSocket closure.
  • Verify the Codex configuration to ensure that the responses_websocket transport is properly set up and that there are no misconfigured settings that could lead to the connection closure.
  • Consider increasing the retry timeout or adjusting the retry mechanism in the Codex runtime to handle temporary connection closures.
  • Check for any updates or known issues with the codex-cli version 0.128.0 that may be related to the WebSocket connection closure.

Example

No code snippet is provided as the issue seems to be related to the Codex runtime and OpenAI WebSocket connection.

Notes

The issue appears to be upstream/runtime-side, and the provided information suggests that the problem is not with the project code. Further investigation into the OpenAI server-side logs and Codex configuration is necessary to determine the root cause.

Recommendation

Apply workaround: Adjust the Codex retry mechanism to handle temporary connection closures, as the root cause of the issue is likely related to the OpenAI WebSocket connection closure, which may require changes to the Codex configuration or OpenAI server-side settings.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

FAQ

Expected behavior

Codex should keep the Responses WebSocket stream open until it receives response.completed, or surface a more specific upstream/server-close reason when the server closes the socket before completion.

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

codex - 💡(How to fix) Fix Responses WebSocket closes before response.completed [1 comments, 2 participants]