WebSocket connection fails due to HTTP/2 ALPN negotiation — needs an HTTP/1.1 option

Open 💬 1 comment Opened May 26, 2026 by oneyearice

Problem

Codex Desktop WebSocket connection may fail with repeated "Reconnecting 1/5 ... 5/5" in certain network environments.

After testing, the issue appears to be related to HTTP/2 ALPN negotiation when establishing the WebSocket connection.

Root Cause

When Codex establishes a WebSocket connection to:

api.openai.com/v1/realtime

the TLS ClientHello may offer both h2 and http/1.1 via ALPN.

In some environments, the server selects h2. However, the current WebSocket Upgrade flow relies on the HTTP/1.1 Upgrade mechanism. When HTTP/2 is negotiated, the request fails with HTTP/2 405 instead of returning 101 Switching Protocols.

Proof

Default (h2 negotiated) - FAILS:

curl -v -H "Upgrade: websocket" -H "Connection: Upgrade" -H "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==" -H "Sec-WebSocket-Version: 13" "https://api.openai.com/v1/realtime?model=gpt-4o-realtime-preview"

Result:
ALPN: server accepted h2
using HTTP/2
HTTP/2 405 - Invalid method for URL (GET /v1/realtime)

Force HTTP/1.1 - SUCCEEDS:

curl -v --http1.1 -H "Upgrade: websocket" -H "Connection: Upgrade" -H "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==" -H "Sec-WebSocket-Version: 13" "https://api.openai.com/v1/realtime?model=gpt-4o-realtime-preview"

Result:
ALPN: server accepted http/1.1
using HTTP/1.1
HTTP/1.1 101 Switching Protocols

Environment

Codex Desktop on Windows
Certain network environments where HTTP/2 is negotiated via ALPN
The issue does not appear to be caused by network reachability, because forcing HTTP/1.1 works correctly

Suggested Fix

Please add a network setting to force HTTP/1.1 for WebSocket connections.

Settings -> Network -> HTTP Protocol -> HTTP/1.1
or:
Settings -> Network -> WebSocket HTTP Compatibility -> Force HTTP/1.1

This would make Codex work reliably in network environments where HTTP/2 ALPN negotiation causes the WebSocket handshake to fail.

Thank you very much for considering this improvement.

View original on GitHub ↗

This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗