Repository navigation
Description
Cortex breaks WebSocket upgrades, and agents that want one fall back to HTTPS. Filing the analysis because the obvious fix is a regression, and that is worth recording before someone reaches for it.
What happens today
stripForUpstream deletes the hop-by-hop headers on every request it forwards — correctly, per RFC 9110 — and Upgrade and Connection are among them (core/listener/forwardproxy/server.go). A WebSocket handshake is a GET carrying exactly those two headers, so it reaches the upstream as a bare GET.
Codex is the live case. It prefers wss://chatgpt.com/backend-api/codex/responses; that endpoint accepts a POST or an upgrade, and a bare GET is neither:
ERROR codex_api::endpoint::responses_websocket: failed to connect to websocket:
HTTP error: 405 Method Not Allowed, url: wss://chatgpt.com/backend-api/codex/responses
warning: Falling back from WebSockets to HTTPS transport.
The 405 comes from chatgpt.com, not Cortex — error.kind: "backend_error" is set from the upstream's status, and bytesDown: 31 matches {"detail":"Method Not Allowed"}. Cortex causes it by stripping the upgrade; the server answers it.
Codex then retries over HTTPS, which Cortex parses fully. Verified: model, 13,747 prompt tokens, completion, tool calls, named session, and now cost.
Why "just support WebSockets" is the wrong move
Forwarding the upgrade and relaying bytes is the cheap version, and it would make Codex less observable than it is now. An opaque tunnel has no protocol parse at all — pipeline.SessionEvent.Tunnel's own doc:
"the bytes are not HTTP, so there's no protocol parse" … "a client that rejected the bridge certificate means every plugin is blind to that traffic"
So passthrough trades today's full telemetry for two tunnel rows and a byte count. No model, no tokens, no cost, no tool calls, nothing for ibac/opa/tool-prune to act on. For a product whose entire purpose is seeing agent traffic, that is a straight downgrade.
The version worth having needs two parsers: WebSocket framing (RFC 6455 — masking, fragmentation, continuation, control frames, and permessage-deflate, which the capture shows Codex negotiating), and then the Responses protocol riding inside it. Plus the listener work to hold a long-lived bidirectional connection open through a pipeline built around request/response. That is a substantial piece, not a header tweak.
Recommendation: defer
The HTTPS fallback is not a degraded path for observability — it is the better one. Three reasons to leave it:
- Full telemetry today, none under passthrough.
- No agent is known to be blocked. Codex falls back automatically.
- The expensive version is only worth building for an agent that has no fallback, and none has appeared.
What would change this:
- An agent with no HTTPS fallback. That agent is simply unobservable, and the calculus flips.
- A provider dropping the HTTPS path. Same outcome, forced.
- An agent where the fallback is materially worse — streaming latency, or features only offered over WS.
Worth fixing cheaply, separately
Two small things that are not WebSocket support:
- The 405 reads as a Cortex fault. Users see
ERROR … 405 Method Not Allowedin Codex's own output and reasonably conclude Cortex broke something, when the request succeeds moments later. A note indocs/agents/codex.mdcosts nothing. (It is in thedocs/agents/codex.mdknown-issues list for Codex already; the general case is not documented anywhere.) - No event explains it. The 405 lands as a bare
backend_error/405with no hint that an upgrade was stripped. AtunnelReason-style marker — "upgrade-stripped" — would let an operator see why in the timeline instead of in a provider's stderr. This is the piece I would actually build, because it makes the situation legible without the parsing work.
Assisted-By: Claude (Anthropic AI) [email protected]
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
feat: Record the stripped Upgrade, so a WebSocket 405 explains itself