Repository navigation
feat(link): teach a Child its Home's link WebSocket state and open the Home leg (not wired yet) - #8614
Merged
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.
…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.
Contributor
|
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. |
Contributor
|
✅ Deterministic PR hygiene checks passed. |
…ild-t6-1b # Conflicts: # scripts/test-layout/layout-clients.json
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A Remote Link Child answers Codex's Responses WebSocket upgrade with 426, so Codex sends every model request over HTTP through the link and re-sends the whole conversation each time. The Home side merged in #8593 behind a closed release gate. This is the first Child-side piece (lane T6 of the link WebSocket design). It adds three parts that nothing calls yet; a Child behaves exactly as before.
Learning the Home's state (
src/client/link-ws-advertisement.ts, hook insrc/client/link-relay-transport.ts). A Home with the feature on addsx-opencodex-link-ws-state: onand an HMAC proof bound to the nonce and both identities to every verified relay-auth 204 (#8593). Every preflight the Child starts (data requests, catalog reads, the parity report, the readiness probe) now takes a number from one process counter, andnoteHomeConnectionapplies the answer's state only when its number is higher than the last one applied for that link. A late reply to an earlier preflight therefore never overwrites a newer answer, whichever Home or Home process sent it. An evicted link keeps its own watermark (at most 1,024), so an answer still in flight when its link was evicted cannot land as the newest, and other links' traffic never voids an answer for a link it did not evict. An answer without the pair, or whose proof does not verify, applies as off. The state is in memory only, so a restart starts from off; a relink is a new link id; at most 256 links are kept.Opening the Home leg (
src/client/link-ws-transport.ts).openLinkWebsocketruns one relay-auth preflight and the upgrade on oneSingleConnectionAgentconnection, never a second. It proceeds only when that preflight's own answer is a verified on. The upgrade carries the session nonce, the link key as a Bearer and a freshSec-WebSocket-Key, and dropsOrigin,Sec-WebSocket-ExtensionsandSec-WebSocket-Protocol. A 101 counts only on the authenticated socket, withUpgrade: websocket, aConnectionnaming upgrade, the right accept value, and no extension or subprotocol. A 101 that the HTTP parser does not treat as an upgrade (noUpgradeheader) is a broken handshake too. Every failure is one closed word (credential,preflight,not_advertised,home_refused,handshake,aborted) and destroys the connection. Nothing retries.A client framer (
src/client/link-ws-framer.ts). The Home leg runs on the socket the preflight authenticated, so a WebSocket client that opens its own connection cannot be used. Under Bun,wsresolves to Bun's built-in shim, and itsReceiverandSenderthrow "Not supported yet in Bun" (checked on Bun 1.4.4). The framer therefore implements the client state machine the design lists:Each violation maps to the close code to send (1002, 1007 or 1009).
Limits and a Child release gate (
src/client/link-websocket-limits.ts). The Child's caps, budgets and timeouts from the design are named in one place.linkWebsocketChildReady()is false and stays false until the framer's client conformance run (Autobahn fuzzingserver) and the Child's memory acceptance have passed, so a Home that opens its own gate cannot switch on an untested Child framer.Why this is inert. Nothing in the listener or the ingress calls
openLinkWebsocket; Codex's upgrade still gets the same 426. The only change on the existing path is inlink-relay-transport.ts: each preflight takes a number, and a verified answer's state pair is checked and recorded in memory. The relay's requests, headers, bodies and outcomes are unchanged. Homes send the pair only while their feature is on, which their own closed gate prevents today.Not in this PR: the ingress and listener wiring, the 503 sequence while the Child's tunnel reconnects, and byte accounting for sockets (next PR). The feature id
link-responses-ws/1will be added with the change that opens the release gates; adding it now would change every Child's peer report and the compatibility verdict Homes show.Verification
Tests that failed first (the three files fail on origin/dev because the modules do not exist; output kept outside the repository):
tests/clients/link-ws-advertisement.test.ts: a verified on only with a proof bound to this nonce, key and link; an earlier preflight's late answer never applied; more than four toggles in scrambled order ending on the last one sent; a relink and a restart; no convergence without traffic; with real preflights against a stand-in Home, the readiness probe and a data request both teach the state, a 204 without the pair or with a bad proof is off, a data request answered 404 (an older Home without the parity route) still teaches it, and Home A's answer delayed past Home B's is ignored.tests/clients/link-ws-transport.test.ts: the upgrade on the authenticated connection with the key, the nonce and a clean header set; frames both ways, with bytes coalesced into the 101 read first; no upgrade when this answer is off, has no pair or has a bad proof; refused or unreachable preflights; a Home refusal; six invalid 101 shapes each destroy the connection; an abort while the Home holds the upgrade, and before anything is sent; a target without its identity sends nothing.tests/clients/link-ws-framer.test.ts: every rule above, chunked and coalesced input, fragments with an interleaved ping, a character split across fragments, a leading U+FEFF kept in text and close reasons, the held-bytes bound across a fragmented message followed by a near-limit one, and writing at each length form.Added in review (each failed first on the code before its fix): an advertisement answer still in flight when its link was evicted is ignored; other links' evictions never void an answer; a leading U+FEFF is kept; the held-bytes bound.
The stand-in Home (
tests/fixtures/link-ws-standin-home.ts) is a raw TCP server, so a test controls every byte of the relay-auth answer, the 101 and the frames; a session nonce is valid only on the connection that made it, as on a real Home.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/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(206 files, includingtests/clients/link-boundary.test.ts), run on this head alone: 3467 pass, 67 skip, 3 fail, exit 1. The three failures are environment-only:link-ocx-child-conformance(one case) andlink-ocx-child-e2e(two cases) needcargo buildofnative/ocx-child, and this machine has no default Rust toolchain ("rustup could not choose a version of cargo to run"). This PR changes no Rust code and nothing those tests exercise.NOT RUN: the full suite (resource limits on the build machine; CI covers it); the Autobahn client conformance run (no Docker here; it is the release gate the Child-side gate waits for); the two
ocx-childRust tests above.Checklist
structure/remote-link.mdhas the Child-side paragraph. Nothing user-visible changes, sodocs-site/is unchanged.)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.