Skip to content

fix(codex): use Responses WebSocket for managed ChatGPT sessions - #3

Merged
nazedeshouu merged 1 commit into
naze/mainfrom
naze/codex-managed-websockets
Nov 17, 2026
Merged

nazedeshouu merged 1 commit into
naze/mainfrom
naze/codex-managed-websockets

Conversation

@nazedeshouu

@nazedeshouu nazedeshouu commented Nov 16, 2026 •

Copy link
Copy Markdown
Owner

Codex threads that use a connected ChatGPT account got slower with every image they opened. A motion review that opened 40 filmstrips took 45–180 minutes, and some reviews failed partway through. Claude reviewers working from the same images finished in about 5 minutes.

The managed provider started Codex with supports_websockets=false, so Codex sent every request as a fresh HTTP POST carrying the whole conversation. Each image from view_image is about 2.5 MB of base64, so 40 images in, every request uploaded about 100 MB. One review re-uploaded 2.6 GB for about 170k tokens of actual input. On a 17.7 Mbps uplink shared with other Codex threads doing the same, uploads ran at about 4–6 Mbps. The OpenAI response stream didn't start until about 3 minutes after a step's request was sent; the model then took about 5 seconds to answer. Large uploads also hit idle timeout waiting for SSE and connection failures, and each retry sent the full body again.

With supports_websockets=true, Codex sends each request over a Responses WebSocket as a continuation, so a step uploads only what is new. In each benchmark run, Codex opened two connections: a warm-up when the session started, and one for the turn about 80 ms later. The managed token works over the WebSocket: Codex gets it from the same auth helper when it connects (status=101, provider OpenAI Token Sharing). A comment above the provider now says why the flag is on, so a later upstream sync doesn't quietly turn it off again.

Evidence

The benchmark ran codex exec 0.166.0, the version T3's managed app-server runs, with a fresh CODEX_HOME per run. Each run used T3's provider string, copied from the running app-server, with only supports_websockets changed. The task was 20 filmstrips from a real motion-review pack, opened one per step, on gpt-6.1-sol at low effort. Uploaded bytes come from sampling per-connection counters with nettop every 0.5 s, so they're close estimates.

Variant Wall time Uploaded Requests
HTTP (before), PNG 870 s 618.7 MB 21
WebSocket (this PR), PNG 152 s 33.1 MB 21
WebSocket (this PR), PNG, repeat 119 s 32.3 MB 21
  • Time per image step: on HTTP it grew from 7.5 s to 79.7 s. On WebSocket it stayed between 2.7 s and 11.3 s. The final step, which writes the answer, took 20–24 s on every WebSocket run.
  • Same content reached the model: every run read the same frame labels and diff counts from all 20 images. Total input tokens per run were within 4% of each other, and single requests within 5% of the HTTP run.
  • Noise: the HTTP and WebSocket runs were about 15 minutes apart on an uplink shared with other running threads, so wall times are noisy. The byte counts don't depend on that.

Tests

  • CodexManagedRuntime.test.ts asserts supports_websockets=true in the managed launch args. The same test still checks that the provider string parses, the provider ID is unchanged, and the helper renews the token.
  • Lint job, run locally: vp check, knip:check and generate --check pass.
  • Typecheck, run locally: passes.
  • Full server suite, run locally on this branch and on naze/main: both give 8,695 passed, 31 failed, 23 skipped. The 31 failures are the same tests on both sides, and all come from this machine's setup, for example: missing Node runtime APIs, npm-global install detection, macOS /private symlink paths, local Claude plugin files, browser recording, and launcher, port and setup-script checks. None of them involve this change.
  • CI on this fork can't run the main jobs: they request blacksmith-2vcpu-ubuntu-2404 runners, which only upstream has, so they stay queued. PR fix(web): themed composer card no longer turns plain when a banner attaches #2 and naze/file-mentions are stuck the same way. Agent context budget compares against the fork's main rather than naze/main, so it fails on every PR into naze/main. This change doesn't touch agent context.

Rollout

  • No migration or config change. Codex reads the flag when T3 starts its app-server, so it applies after the next T3 build and restart. Existing rollouts resume, because the provider ID is unchanged.
  • Fallback: if the WebSocket can't be used, for example retries run out or the server answers 426, Codex falls back to HTTP for the rest of that session. The worst case is today's behaviour. A brief failure doesn't trigger it: in one benchmark run the warm-up connection got a 503, and the turn still connected over WebSocket.
  • Token renewal: in Codex 0.166.0, a 401 while connecting goes through the same recover_from_unauthorized path as HTTP, which calls the auth helper again. Connections are keyed by auth revision, so a renewed token gets a new socket. The server also closes sockets after 60 minutes and Codex reconnects. The case that isn't proven live is a reconnect that first tries an expired cached token.
  • What to watch: check ~/.codex/logs_2.sqlite and the app-server's stderr for falling back to HTTP, provider authentication recovery failed, or errors from codex_api::endpoint::responses_websocket. Accounts with their own Codex home write their logs there too, because those homes link to the shared one. The existing 401s there come from model discovery and are unrelated.
  • Older user-installed Codex: T3 also runs the managed provider on a compatible user-installed codex. Only 0.166.0 was benchmarked; the HTTP fallback covers older versions.
  • Revert: flip the flag back.

Review

Rounds: 2

Reviewer Round 1 Round 2
A 8/10 9/10
B 9/10 9/10

Neither reviewer raised a blocker in either round. Round 1 asked for a comment on why the flag is on, and for more precise wording in this description. Round 2 asked for small wording fixes: the connection pattern, the effective upload rate, the failing-test categories, and where shadow homes write logs. Both rounds' changes are in. Both reviewers re-ran the focused tests (78–80 passing) and checked the benchmark and full-suite numbers against the raw reports.

@github-actions github-actions Bot added vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. size:XS labels Nov 16, 2026
The managed token-sharing provider disabled WebSockets, so every sampling
request re-uploaded the full conversation, including every image a tool
had returned. Image-heavy Codex turns grew to ~100 MB per request and
took minutes per step on ordinary uplinks.

With supports_websockets=true Codex sends continuations over the Responses
WebSocket instead of the whole history, and falls back to HTTP for the
session if the WebSocket cannot be used.
@nazedeshouu
nazedeshouu force-pushed the naze/codex-managed-websockets branch from dfee72a to 0236bbc Compare November 17, 2026 04:03
@nazedeshouu
nazedeshouu merged commit 0236bbc into naze/main Nov 17, 2026
10 of 13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XS vouch:trusted PR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant