Repository navigation
feat(link): a Child carries Codex's Responses WebSocket over its link when the Home advertises it (behind a closed Child gate) - #8619
Conversation
…s Home leg (not wired yet) A Child relays Codex's model requests to its Home over HTTP only, so every request re-sends the whole conversation through the link. This is the first Child-side piece of carrying the Responses WebSocket instead. - Every relay-auth preflight takes a number when it starts; a verified answer's x-opencodex-link-ws-state applies only when its number is higher than the last applied one for the link, so a late answer never overwrites a newer one. No pair, or a pair whose proof fails, is off. - openLinkWebsocket runs the preflight and the upgrade on one authenticated connection, proceeds only on that answer's own verified on, and accepts only a complete 101 on that socket. - A client RFC 6455 framer for the Home leg: Bun resolves ws to its built-in shim, whose framer is not implemented. Nothing calls the transport yet and a Child-side release gate stays closed, so Codex's upgrade still gets today's 426.
… order and text exact Review round 1 of the Child's link WebSocket pieces: - the relay-transport hook (preflight numbers, the state pair checked on every verified answer, the exports the Home leg needs) was missing from the previous commit, so link-ws-transport.ts could not load; - evicting a link from the 256-entry book no longer drops its ordering: an answer for a link without an entry applies only when its preflight started after every evicted entry's last applied one; - a leading U+FEFF in a text message or close reason is kept; - fragments are written into one reassembly buffer of the maximum message size, so a fragmented message holds at most that much.
…nk when the Home advertises it A Child answered Codex's upgrade with 426, so every model request went over HTTP and re-sent the whole conversation. With the Child's release gate open (it stays closed) and the Home advertising the feature on its last applied relay answer, the Child now accepts the upgrade and relays whole text messages over the link's authenticated socket. - Fallbacks: a local Origin, no link key, the caps (8 open, 4 setting up), the 256 MiB memory budget, a failed tunnel, a preflight that is refused or not on, a Home refusal, a broken 101 and the 8 s setup budget all answer today's 426. A Child-initiated tunnel that is still reconnecting after a 3 s hold answers 503 link_websocket_unavailable. - Relay: binary from Codex closes both legs (1003); a Home message over 4 MiB + 64 KiB closes Codex with 1011; close codes are relayed with 1005/1006/1015 as 1011; a second unflushed message from Codex closes both legs (1013/1001); the Home leg pauses above 1 MiB buffered toward Codex. The local 101 advertises the 8 MiB message limit. - Any listener stop closes link sockets with 1001 on both legs. - A socket counts as one request in the Child's traffic book (payload bytes); fixed-word diagnostics link_ws_open/close/fallback. - The release gate's 503 sequence now runs the real Child listener.
…er links from voiding an answer Review round 2: - the reassembly buffer of a fragmented message is dropped once that message is complete, so it never coexists with the next message's own buffer; heldBytes() lets a test check the bound; - an evicted link keeps its own watermark (at most 1,024), so answers for links that were never evicted are not compared against other links' numbers; only a dropped watermark raises a shared floor.
…lay registered close codes Review round 1 of the Child relay: - a listener stop aborts every upgrade still in its tunnel hold or at the Home, and keeps nothing set up after the stop began; - a close decided before Bun opened Codex's socket is applied when it opens, so a Home that is gone by then never leaves Codex waiting; - a socket keeps its slot and memory reservation until its Home connection has actually closed, and a Home-started close is bounded by the same 5 s as a Child-started one; - every tunnel ownership check is raced against the 8 s setup budget; - close codes 1012-1014 are valid on the wire and relayed both ways.
… the same chunk Review round 2: the framer now appends events to the caller's array as they complete, so when a later frame in the same TCP chunk is refused, the relay still delivers the messages before it (a response.completed included) in wire order, and only then closes both legs.
…ade, and never leaves an early error unhandled
Final-review notes on the previous slice and review round 3:
- openLinkWebsocket refuses with 'disabled' before any I/O while the
Child's release gate is closed, whatever the caller does;
- the upgrade after a verified preflight has its own 8 s bound
('timeout'), so a Home that never answers it cannot hold the
connection;
- the socket handed off after a 101 gets an error listener until its
owner adds one;
- tests: a 64-bit length with a non-zero high word is 1009, and the
delivered-before-refused case is also fed to the relay in one piece
through the bytes coalesced with the 101.
…call Review round 4: the socket test can split the frames across reads, so a unit test now builds a HomeLeg whose head holds both frames and checks that attach() delivers the completed message before closing with 1011.
…ild-t6-1b # Conflicts: # scripts/test-layout/layout-clients.json
|
Caution Review failedThe pull request is closed.
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
|
✅ Deterministic PR hygiene checks passed. |
…k-websocket-child-t6-2 # Conflicts: # scripts/test-layout/layout-clients.json # structure/remote-link.md
…d-t6-2 Brings in dev 20fb0d3 and the squash of the lower slice; no file of this slice is edited (git merge-tree, no conflicts).
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
…d-t6-3 Brings in dev 6ee1b91 and the squash of the lower slice; no file of this slice is edited (git merge-tree, no conflicts).
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8c42897609
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| // Complete when a close ended it, from either side; a drop, an overload or a refused message is incomplete. | ||
| this.flow.end(reason === "home" || reason === "client" || reason === "stopped"); |
There was a problem hiding this comment.
Account for pending uplink writes before marking a socket complete
When Codex disconnects or the listener stops while a message is still queued toward a stalled Home, this marks the traffic flow complete immediately. If the close-handshake timer subsequently destroys the Home socket, the pending write fails and its callback never adds those payload bytes, even though a prefix may have reached the Home. The traffic snapshot therefore reports incomplete: 0 alongside an undercounted toHomeBytes, violating the counter contract in src/link/traffic.ts that completed requests have their uploads counted in full. Track pending write settlement and mark the flow incomplete if shutdown discards an upload, as the HTTP relay already does.
Useful? React with 👍 / 👎.
Stacked on #8614 (base: its head 7934512). Review this PR as the commits after that head.
Summary
A Remote Link Child answers Codex's Responses WebSocket upgrade with 426. Codex then sends every model request over HTTP through the link, and each request re-sends the whole conversation. #8593 added the Home side and #8614 the Child's pieces: the advertisement state, the Home-leg transport and the framer. This PR wires them in. When the Child's release gate is open and the Home advertised the feature on the last relay answer the Child applied, the Child accepts Codex's upgrade and relays whole text messages over the link's authenticated connection. Both release gates stay closed, so nothing changes for anyone yet.
When the Child tries the upgrade (
src/client/link-websocket.ts,src/client/link-ingress.ts). Only whenlinkWebsocketChildReady()is true and the link's advertised state is on. In every other case the ingress answers today's 426, byte for byte, and opens no connection. A tried upgrade passes these checks in order:Originheader at all (a non-local one still gets today's 403 first);503with codelink_websocket_unavailableand noRetry-After. This is the only transient answer, and never one of the three 503 codes codex-rs treats as terminal. A failed tunnel gets 426, and a Home-initiated link goes straight on. An ownership proof that hit its deadline gets one fresh proof, as an HTTP request does, and every proof is raced against the setup budget;Steps 3 to 5 share an 8 s budget, below Codex's 15 s connect timeout. Every other failure, the budget included, is the same 426, so that Codex session uses HTTP. The local 101 carries
x-codex-websocket-max-message-bytes: 8388608, so Codex sends a larger request over HTTP instead.Relay (
src/client/machine-listener.tsgives the link-mode listener a websocket handler: 8 MiB messages, an 8 MiB backpressure limit that never closes the socket, no idle timeout, no compression). The Child never parses a message or writes one of its own:A turn in flight when the tunnel reconnects. The Home leg ends without a close frame, so the Child closes Codex's socket with 1011. The Home cancels the cut turn and records its activity hold (#8593). The Child never re-sends a frame or a request; Codex alone retries. While the tunnel reconnects, each retry gets the 503 above, at a cost of one retry from Codex's budget. If the tunnel is back within the budget, the next attempt runs on the WebSocket and starts with a full request. If not, Codex switches the session to HTTP and resends the same request once, and the HTTP relay holds it for the tunnel as today.
Child activity. A turn running on a link socket is busy in the Home's activity book, and a socket lost mid-turn leaves a durable hold (#8593). Activity-gated syncs and restarts therefore wait for it. The Child's part is to close the Home leg as soon as Codex's socket goes. A test drives both through a real Home.
Byte accounting (#8584). A link socket counts as one request in the Child's traffic book. Message payload bytes count toward the Home once the socket write completed, and from the Home per complete message. Framing, the handshake and control frames are not counted, as HTTP headers are not. The socket is complete when a close ended it. HTTP requests are counted exactly as before. Per-body zstd (#8594) stays HTTP-only: WebSocket messages go as they are, and permessage-deflate is refused.
Diagnostics. Only fixed words go to the existing allowlisted sink:
link_ws_open,link_ws_close(client,home,home_dropped,binary,protocol,overload,stopped) andlink_ws_fallback(origin,credential,cap,memory,tunnel_failed,tunnel_connecting_timeout,preflight,not_advertised,home_refused,handshake,timeout,aborted). No key, content or address is written. The dashboard's diagnostics table filters unknown events, so it does not show these yet.Version mixes.
Also here.
forwardLinkUpgradeHeaders: Codex's headers without its handshake, through the same credential and hop-by-hop filter an HTTP request gets, plus the link key.What keeps this inert.
linkWebsocketChildReady()is false, and Homes advertise nothing while their own gate is closed (#8593). With either closed, the upgrade gets today's 426 with no network I/O; a characterization test checks the bytes and the connection count. The listener's new websocket handler is only reachable throughserver.upgrade, which only an admitted upgrade calls. The stop wrapper'scloseAll()has nothing to close. Not in this PR: the Child's?transport=1counters and the Child-local opt-out (D4), which come next; the lightweight Rustocx-child(it keeps its 426); the feature idlink-responses-ws/1, which comes with the change that opens the gates.Verification
Tests that failed first (on the #8614 head for the slice, and on the commit before each review fix; output kept outside the repository):
tests/clients/link-ws-relay.test.ts(28 cases, against a raw-TCP stand-in Home):HomeLegfed in one call), uplink overload, downlink pause and resume with nothing dropped, pings;tests/clients/link-ws-fallback.test.ts, with a client that follows codex-rs's retry and fallback policy:tests/e2e-style/link-ws-child-home.test.ts(a real scratch Home with its gate opened for the test): a Child-relayed turn is the link's activity while it runs and not after; a Codex socket lost mid-turn leaves the Home's hold.tests/clients/link-ws-transport.test.ts: the closed Child gate refuses before any I/O; an unanswered upgrade ends at the budget; an error on the handed-off socket is recorded.Characterization (passes before and after): a closed Child gate or a never-advertising Home answers today's 426 byte for byte with no connection to the tunnel port; a non-local Origin keeps its 403.
Release gate:
tests/e2e-style/link-websocket-release-gate.test.tsreplaces its "belongs to the Child lane" skip with two cases that drive the pinned Codex binary through the real Child listener and a scratch Home, with a tunnel gate the test drives. Without the pinned binary they are skipped with the U13 label. As a smoke check only (not release evidence), I ran both with the codex-cli 0.167.2 binary on the build machine: two 503s and then the turn on the WebSocket; and, separately, every upgrade within Codex's budget answered 503, then the request once over HTTP. Both completed.Commands (Bun 1.4.4,
TMPDIR=/tmp):bun run typecheck: exit 0.bun run privacy:scan: exit 0.bun run structure:check: exit 0.bun scripts/test.ts --parallel=2 tests/clients/ tests/e2e-style/link-ws-child-home.test.ts tests/e2e-style/link-websocket-release-gate.test.ts tests/test-layout.test.ts tests/test-layout-tooling.test.ts tests/ci-workflows/structure-ssot.test.ts tests/ci-workflows/file-size-ratchet.test.ts tests/lab/core-lab-boundary.test.ts(includingtests/clients/link-boundary.test.ts): 3506 pass, 74 skip, 3 fail, exit 1. The three failures are environment-only: theocx-childRust conformance and end-to-end tests needcargo build, and the build machine has no default Rust toolchain. This PR changes no Rust code.NOT RUN: the full suite (resource limits on the build machine; CI covers it); the Autobahn client conformance run and the Child's transport-only RSS acceptance, both of which the Child gate waits for; the release-gate cases with the pinned binary (U13); the two
ocx-childRust tests above.Checklist
structure/remote-link.mdcovers the Child side. Nothing user-visible changes while the gates are closed, sodocs-site/waits for the change that opens them.)Implemented by Claude Opus 5.5 (anthropic/claude-opus-5-5) in GOAT through the Codex harness; in-lane review by GPT-6.1 Terra (xhigh). Received as a git bundle from the VM that built it and pushed by the coordinator.