Repository navigation
feat(link): compress Child request bodies with zstd for a Home that accepts it - #8594
Merged
Merged
Conversation
…its SSH path ocx link status --json now asks for ?traffic=1 and shows, per link, the request and response body bytes since this process started counting, how many requests ended early, and whether the link's SSH alias goes through a ProxyCommand, a ProxyJump host or directly. Without the query the status document is unchanged, so older CLIs keep validating it. A Child counts in its relay, exactly. A Home counts response bytes exactly in its hub-link listener and request bytes by declared Content-Length, because it must keep Bun's native request. Refs goat-si/goat#3023.
Request-log and usage.jsonl rows gain requestBody {wireBytes, encoding,
decodedBytes}, filled by the shared JSON body reader for every admitted
data route, so ocx logs --json shows what a client actually sent. Older
readers rebuild rows from known fields and drop it. Refs goat-si/goat#3023.
…solution Review round 1 for the traffic counters: - count in fetchBoundLinkRelay from the data-request boundary, so a refused challenge or connection counts nothing, response bytes are counted before decoding, and the Child's own hub-state, usage and management reads count; - a connected Child's machine listener answers ?traffic=1 with its own link row, counters and SSH path; - a Home request aborted before its headers stays incomplete; - at most four ssh -G run at once and at most 32 aliases wait.
… mark a bad sidecar row failed Review round 2: response bytes are counted by a pass-through on the socket's stream, so bytes read before a cancel count, and the Child's traffic row reads failed with an unknown alias when its sidecar is unreadable or names another link, instead of passing as an idle Home-initiated link.
…s on each relay-auth answer
…failed row Review round 3: when the sidecar is missing but the durable marker names this link (or cannot be read), the Child's traffic row is failed with reason sidecar_missing and an unknown alias, instead of a Home-initiated idle link.
…ome's named features
…me that accepts it
…coded and prepared bodies Review round 1 for per-body zstd: - the Child sends a body as it is when its zstd form would exceed the Home decoder's ratio bound, so compression never turns an accepted request into a 413; - an encoded body on a JSON data route now joins the shared inbound budget at every limit, reserving its decode bound before it is read and shrinking to the measured size, so decoded bodies held at once stay bounded; - bodies a Child prepares share a 128 MiB allowance, and one that does not fit streams unchanged.
…lushed Review round 2: a Home may answer before it reads an upload, so response headers do not prove the prepared body left the Child. The transport now reports when that body's write flushed or its request was torn down, and the relay frees the allowance then.
Final review: a status read ran ssh -G, which evaluates Match exec, could leave processes behind and could slow ocx link status. The path kind is now read from the user's and the system ssh_config with OpenSSH's first-value-wins rule, Host patterns and Includes; anything only ssh could settle reads unknown. A status read starts no process.
…link its own since Final review: evicting the oldest entry could drop a link whose request was still counting while its since claimed continuity. Eviction now skips links with requests in flight, a link counted after an eviction reports since its entry began, and an absent link reads zero since the last eviction.
Final review: a string or byte body was counted before its write completed, unlike streamed chunks.
…hild row; test and doc updates
# Conflicts: # src/client/link-relay-transport.ts # tests/fixtures/test-layout-expected.json
…d trim the traffic book Review round 5: - ProxyJump none blocks only a later ProxyJump, so a later ProxyCommand still decides, as ssh -G shows; - a config file over the limit is refused by its size without being read, an Include glob stops listing past the file budget, and one status read reads each file once and at most 1 MiB in all; - as requests end, the traffic book trims its oldest idle links back to the bound after a burst of links in flight took it past.
…ig without blocking Review round 6: a Host pattern full of wildcards could stall the event loop in a backtracking regex, an Include glob could walk a large tree, and a named pipe in place of a config file blocked the open. Patterns now match in linear-by-length time, an Include wildcard lists only one directory and at most 1,024 entries, and only regular files are opened, without blocking.
# Conflicts: # src/client/link-relay-transport.ts
The traffic row named a Home-initiated link from a second sidecar read, which could see a different file than the first. The Home name now comes from the published settings only when the first read found no sidecar.
A Child counts a request-body write once it completes, so a read taken mid-upload can show incomplete 0 while the Home already holds a prefix. The contract now says deltas measure completed writes, and a test reads status in that window.
… the upload settled The Child released a prepared body charge once its socket write completed, while the relay still kept the raw and compressed buffers for a possible resend until response headers arrived, and the transport kept them reachable through listeners until the connection closed. The charge now lasts until both the answer and the upload settled, the relay drops its references at that point, and the transport no longer retains the request init.
…e stays compatible A Home that predates per-body zstd counts every Child-only feature as used and told the owner to upgrade it, although the Child falls back to identity bodies. The Child now leaves optional features out of its peer report, and a Home never counts one against itself.
Compression lets an observer who can put chosen text beside a secret in repeated requests, and see their sizes, test guesses at the secret. On a link that is a relay operator or anyone on the path, since the tunnel hides content but not sizes. linkRequestCompression: false in the Home config stops naming the capability, and its Children send identity bodies exactly as before. It stays on by default; the guide and structure say why. OcxLinkTransportConfig moves to src/types/link.ts beside the new Home setting, which keeps src/types/config.ts under its line threshold.
…e-window zstd frames, and log a Child-compressed body A truncated frame yields only its complete blocks and the data plane answers 400; concatenated frames decode in full under one ratio bound; a window above 128 MiB is refused before any output. A body a Child compressed through a hub-link session reaches the data plane and its log row carries the wire size, zstd and the decoded size.
The reference page sits one line below the file-size threshold, so the linkRequestCompression row moves out; the Remote Link guide and structure/remote-link.md document the key.
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. |
lidge-jun
added a commit
that referenced
this pull request
Nov 12, 2026
Conflicts resolved by keeping both features: - the hub-link listener passes homeFeatures (the zstd offer) to the relay sessions beside the WebSocket upgrade, advertisement and holds hooks, and its start context carries both homeFeatures and responsesWebsocket; - the relay-auth 204 carries the Home's features header and, only while the WebSocket feature is on, the WebSocket state proof pair; - the optional listeners pass linkHomeFeatures(activeConfig) beside the WebSocket context; - the structure page keeps the traffic section, then per-body request compression, then the Responses WebSocket section.
lidge-jun
added a commit
that referenced
this pull request
Nov 12, 2026
…td-coded With #8594 a Child may send a relayed POST /v1/responses body zstd-coded. The hold observation parsed its copy of the body as plain JSON, so a coded body never parsed and a pending result returned over HTTP left its hold in place until the operator cleared it. The copy is now decoded through decodeRequestBody, the handlers' bounded reader with its ratio limit, before it is parsed. A body that does not decode still releases nothing, and the release still applies only after the handler answered below 400.
lidge-jun
added a commit
that referenced
this pull request
Nov 12, 2026
…-auth answer Since #8594 every relay-auth 204 names the Home features. The switched-off characterization still requires that the answer carries no WebSocket state pair.
lidge-jun
added a commit
that referenced
this pull request
Nov 12, 2026
…nk, behind a closed release gate (#8593) * feat(link): count the body bytes each Remote Link carries and report its SSH path ocx link status --json now asks for ?traffic=1 and shows, per link, the request and response body bytes since this process started counting, how many requests ended early, and whether the link's SSH alias goes through a ProxyCommand, a ProxyJump host or directly. Without the query the status document is unchanged, so older CLIs keep validating it. A Child counts in its relay, exactly. A Home counts response bytes exactly in its hub-link listener and request bytes by declared Content-Length, because it must keep Bun's native request. Refs goat-si/goat#3023. * feat(logs): record each request body's size and encoding on log rows Request-log and usage.jsonl rows gain requestBody {wireBytes, encoding, decodedBytes}, filled by the shared JSON body reader for every admitted data route, so ocx logs --json shows what a client actually sent. Older readers rebuild rows from known fields and drop it. Refs goat-si/goat#3023. * test(link): expect ocx link status to ask for traffic=1 * fix(link): count link bodies in the bound transport and bound path resolution Review round 1 for the traffic counters: - count in fetchBoundLinkRelay from the data-request boundary, so a refused challenge or connection counts nothing, response bytes are counted before decoding, and the Child's own hub-state, usage and management reads count; - a connected Child's machine listener answers ?traffic=1 with its own link row, counters and SSH path; - a Home request aborted before its headers stays incomplete; - at most four ssh -G run at once and at most 32 aliases wait. * docs(link): describe transport-level counting and the Child status row * feat(link): add per-body zstd helpers for Child request bodies (not wired yet) * fix(link): count identity response bytes before the adapter queue and mark a bad sidecar row failed Review round 2: response bytes are counted by a pass-through on the socket's stream, so bytes read before a cancel count, and the Child's traffic row reads failed with an unknown alias when its sidecar is unreadable or names another link, instead of passing as an idle Home-initiated link. * feat(link): advertise link-request-zstd/1 and name the Home's features on each relay-auth answer * fix(link): read a lost sidecar under the Child-initiated marker as a failed row Review round 3: when the sidecar is missing but the durable marker names this link (or cannot be read), the Child's traffic row is failed with reason sidecar_missing and an unknown alias, instead of a Home-initiated idle link. * feat(link): let the bound transport choose a prepared body from the Home's named features * feat(link): compress eligible Child request bodies with zstd for a Home that accepts it * fix(server): bound an encoded request body's decoded size by its compression ratio * test(link): cover per-body zstd over the link and the Home's ratio bound * docs(link): describe per-body zstd over the link and the decoder ratio bound * test(server): use incompressible bytes for the image-heavy decode regression body * fix(link): keep Child zstd within the Home's ratio bound and bound decoded and prepared bodies Review round 1 for per-body zstd: - the Child sends a body as it is when its zstd form would exceed the Home decoder's ratio bound, so compression never turns an accepted request into a 413; - an encoded body on a JSON data route now joins the shared inbound budget at every limit, reserving its decode bound before it is read and shrinking to the measured size, so decoded bodies held at once stay bounded; - bodies a Child prepares share a 128 MiB allowance, and one that does not fit streams unchanged. * fix(link): hold the Child's preparation allowance until the body is flushed Review round 2: a Home may answer before it reads an upload, so response headers do not prove the prepared body left the Child. The transport now reports when that body's write flushed or its request was torn down, and the relay frees the allowance then. * docs(link): say when the Child's preparation allowance is freed * fix(link): type prepared link bodies as ArrayBuffer-backed bytes * feat(link): admit the Responses WebSocket on the Home's link listener, switched off A Child can only relay HTTP to its Home today, so Codex re-sends the whole conversation on every model request. This adds the Home side of carrying the Responses WebSocket over a Remote Link, behind a new linkResponsesWebsocket setting that is off by default and also needs websockets. While off nothing changes: a link upgrade gets the route table's existing 404 and the relay-auth 204 is byte-identical. While on, an upgrade is admitted only on a relay session just verified on the same connection, with the exact Codex shape and the proof's own key. Every frame re-checks links.json and the key's fingerprint before the shared handler sees it; revoke, last-link close and a 30 s sweep close link sockets with 4401. Link sockets have per-link and overall caps and a transport memory budget, never evict a local socket, and carry no native steering or injection. * fix(link): close link sockets revoked before they open, and gate the switch until the bounded pump lands Review round 1 of the link WebSocket admission: - A revoke or last-link close() that runs after server.upgrade() succeeds but before Bun calls open() now still closes that socket when it opens. Before, close() could wait forever on its session lease. - linkResponsesWebsocket cannot admit or advertise anything yet. Its memory reservation assumes the link-only bounded pump, which a later slice adds and which lifts this gate. - Tests: a proof made on one connection never upgrades another, the off-state relay-auth answer equals a relay book without any WebSocket option, and the revoke case waits for the Home to end the connection before reading counters. * docs(structure): describe the link WebSocket release gate and the pre-open fence * test(link): prove a link response.create never reaches native mode selection * fix(link): read a link's SSH path from ssh_config instead of running ssh Final review: a status read ran ssh -G, which evaluates Match exec, could leave processes behind and could slow ocx link status. The path kind is now read from the user's and the system ssh_config with OpenSSH's first-value-wins rule, Host patterns and Includes; anything only ssh could settle reads unknown. A status read starts no process. * fix(link): never evict a link with a request in flight and give each link its own since Final review: evicting the oldest entry could drop a link whose request was still counting while its since claimed continuity. Eviction now skips links with requests in flight, a link counted after an eviction reports since its entry began, and an absent link reads zero since the last eviction. * fix(link): count a buffered link body only once the socket took it Final review: a string or byte body was counted before its write completed, unlike streamed chunks. * fix(link): name the Home, not the loopback URL, on a Home-initiated Child row; test and doc updates * fix(link): match OpenSSH on ProxyJump none, bound the config reads and trim the traffic book Review round 5: - ProxyJump none blocks only a later ProxyJump, so a later ProxyCommand still decides, as ssh -G shows; - a config file over the limit is refused by its size without being read, an Include glob stops listing past the file budget, and one status read reads each file once and at most 1 MiB in all; - as requests end, the traffic book trims its oldest idle links back to the bound after a burst of links in flight took it past. * feat(link): drain link WebSockets on switch-off, close idle and aged ones, count them as Child activity Still behind the closed release gate. When the link WebSocket setting goes off, each open link socket drains instead of closing: a running turn is never cancelled, a create during it is dropped and the socket closes after the turn, and with no turn running only a create that returns a pending tool or approval result is admitted, for at most 60 minutes. Outside a drain, an idle link socket closes after 10 minutes and one older than 60 minutes closes at its next idle moment. A full shared socket gate lets a link upgrade reclaim only an idle link socket. A busy link socket now counts in the per-link activity book, so activity-gated Child restarts wait for a running turn or a pending tool. * test(link): a create dropped during a turn closes the socket after it even with a tool pending * fix(link): count link WebSockets in the listener's own activity book * fix(link): match Host patterns without backtracking and read ssh_config without blocking Review round 6: a Host pattern full of wildcards could stall the event loop in a backtracking regex, an Include glob could walk a large tree, and a named pipe in place of a config file blocked the open. Patterns now match in linear-by-length time, an Include wildcard lists only one directory and at most 1,024 entries, and only regular files are opened, without blocking. * feat(link): pace the Responses pump on link WebSockets so a stalled reader stays bounded Still behind the closed release gate. Today the WebSocket pump sends every complete event of an upstream chunk in one synchronous loop, so one coalesced chunk to a slow reader can queue tens of MiB in Bun's send buffer. On a Remote Link socket the pump now waits for Bun's drain after any send that leaves more than 1 MiB buffered, before the next event of the same chunk, and feeds the SSE framer at most 256 KiB of a chunk at a time. A cancel or close ends the wait; a socket that does not drain for 300 s is closed with 1011. Local sockets keep the existing loop. * test(link): add the opt-in transport memory acceptance for link WebSockets tests/e2e-style/link-websocket-rss.test.ts runs a Home in its own process, opens n link sockets that each send a near-maximum message and then stop reading, and compares the Home's peak RSS minus idle RSS with n link socket reservations. It is a release gate, skipped unless OCX_LINK_WS_RSS_ACCEPTANCE=1. Diagnostic knobs shrink the input or the upstream chunks, or send the same load through the HTTP link relay, to separate turn memory from transport memory. * fix(link): keep a link pump waiting until the send buffer is below the threshold, not just until Bun drains * test(link): measure link WebSocket memory as a high-water mark once every pump is stalled * test(link): take the memory acceptance peak from the kernel's high-water mark * test(link): the memory acceptance passes only on a readable kernel peak of a load that stalled * feat(link): keep durable activity holds for link WebSockets cut while busy, with a crash fence Still behind the closed release gate. When a link WebSocket closes while a turn runs or a client tool or approval result is pending, for any reason other than revocation, the Home now records a durable hold: the HMAC of the socket's own thread id, the hashed result keys it was waiting for, a mark per running turn, and whether its results were untracked. Holds count as link activity, so automatic and activity-gated Child restarts keep waiting. A later request from the same link and thread that returns the pending results, over the WebSocket or HTTP, releases them; running marks, unkeyed and untracked holds stay until an operator clears them, and link removal deletes them. A crash fence (ws-run-state.json) is written durably before the first link upgrade of a process; if it cannot be written, link upgrades are refused. A start that finds the fence still "running", or any damaged state, marks every link unknown. No file is touched while the feature has never run. * test(link): a crash-recovering start that cannot persist its evidence keeps the fence running * fix(link): make activity holds fail closed on directory sync, unreadable links, key loss and refused requests Review round 1 of the durable link WebSocket holds: - The fence, the holds file and the reference key now use a strict durable write whose directory fsync failure is reported, so arming and a clean stop never succeed on a write that is not durable. - Crash recovery that cannot list the links marks every link unknown and keeps the fence running for the next start. - A reference key that cannot be loaded or replaced no longer fails startup; the links stay unknown and nothing is cleaned. - A relayed HTTP request releases holds only after the handler answered below 400, so a request refused before or after reading its body releases nothing. * docs(structure): describe the strict durable writes and fail-closed recovery of link activity holds * fix(link): release link WebSocket holds only for admitted turns, and never clean the fence over unwritten unknowns Review round 2 of the durable link WebSocket holds: - Over the WebSocket, a hold is now released when the shared handler admits a turn with the returned results (CodexWebSocketActivity.onAccepted), so a generate:false warmup or a refused create releases nothing. - A graceful stop writes an all-links unknown state that existed only in memory per link once the links can be listed, and otherwise leaves the fence running. * fix(link): release link WebSocket holds only after every admission accepted the turn Review round 3: the hold release moved from beginTurn, which runs before workflow admission, to an explicit notifyAccepted call the shared handler makes once the turn pipeline answered ok. A workflow refusal or any other refused turn no longer releases a hold; a regression drives the real shared handler. * fix(link): a refused or failed turn on a link socket leaves its returned results owed Review round 4: the activity tracker settles a socket's own pending results when a turn begins, before workflow admission and the pipeline answer. On a Remote Link socket (opt-in restoreRefusedResults) a turn the shared handler never reports as accepted now puts the results it settled back to pending when it finishes, so a later busy close still leaves a hold. Local sockets keep settling at admission. Regression through the real shared handler. * fix(link): an older link turn never restores a result a newer turn returned successfully Review round 5: when a turn is reported accepted, the result keys it returned are struck from every other in-flight turn's restore list, and settled again if an older turn already put them back. Only sockets that restore refused results (Remote Link) are affected. Controlled late-settlement tests for both orders. * fix(link): scope result reconciliation on link sockets to turns older than the accepted one Review round 6: an acceptance now prunes the restore lists only of turns that began before the accepted turn, and settles again only keys that an older turn put back; a call observed afterwards under the same id is new work and loses that marker. A late acceptance of a superseded turn can no longer settle a newer call that reuses the key or cancel a newer refused turn's restore. * test(link): an older acceptance never prunes a newer turn still in flight * fix(link): an older refused turn never tags newer pending work on a link socket Review round 7: restoring a refused turn's results skips a key that is already pending, since that key is newer work under the same call id and keeps its own generation. A later acceptance can then never settle it on the strength of the older turn's marker. Controlled A/B/C interleaving test. * fix(link): a result settled again on acceptance never suppresses a new call reusing its id Review round 8: re-settling a key that an older turn put back no longer adds it to the echo-suppression set. Like beginTurn, a settled wait cannot hide a later call under the same id, even when the upstream omits response.created. * fix(link): a call id reused while an older link turn may restore it makes the socket untracked Review round 9: a result key cannot tell two generations of the same call id apart. On a Remote Link socket, a newly observed call whose id is still in an in-flight turn's restore list now makes the socket's results untracked, so a later close leaves an operator-only hold instead of possibly forgetting owed work. The earlier reuse regressions now assert the work stays owed (not idle). * docs(structure): a reused call id on an overlapping link turn makes the socket untracked * fix(link): on a link socket an upstream output never settles a pending client call Review round 10: the tracker settled a pending result when the upstream emitted an output item with the same call id. Provider-executed calls never become pending, so on a Remote Link socket only an accepted client turn may return a client result now; local sockets keep the existing behaviour. * docs(structure): upstream outputs never settle a link socket pending client call * refactor(link): drop the SSH path kind from link status Two independent reviews found real defects in each way of resolving it: running ssh -G (Match exec can run commands, stall and leave processes) and re-reading ssh_config (it must match OpenSSH's reader exactly, including token expansion, or it reports a wrong kind). The measurement this change exists for, bytes per link and body size per request, does not need it, and the link's alias already names a relay route. Removes src/link/ssh-route.ts, the path block, its CLI validation, tests and documentation. * fix(link): pass hold limits into the activity-hold store instead of importing them from src/server src/link may not import from src/server (tests/clients/link-boundary.test.ts). The store now takes holdsPerLink and holdsTotal as a required dependency; the link listener passes them from link-websocket-limits.ts, which stays the one place every link WebSocket cap lives. * fix(link): hard-bound the traffic book, give each reset a generation, and state the lower bound Second final review: - the book never holds more than 256 links; a new link takes the place of the link idle longest (O(1), no scan), and a request with no place is not measured but counted in the book-level untrackedRequests; - every reset of a link's counters takes a new generation from one monotonic counter, so a consumer can tell a reset even when the clock repeats or goes backward; since stays for people; - a pending write is not counted, so toHomeBytes on a Child is a lower bound while incomplete > 0; the word exact is gone where it was not true; - the plain status document is asserted byte for byte. * fix(link): give each traffic book a random epoch and count a cut upload as incomplete Generations restarted at 1 in every process, so two reads across a restart could compare equal. Each book now reports a random epoch beside generation, and consumers compare reads only when both match. A Child request now ends only once its response and its upload both settled, so a Home that answered in full before reading the whole body leaves the request incomplete, which is the signal that toHomeBytes is a lower bound. * feat(link): fingerprint a running link turn and release its mark only when it is re-sent and completed A busy link socket that closes leaves a running mark per turn. The pipeline now reports a link turn's expanded input right after continuation expansion, so the mark carries an HMAC of the cut request's input, its length and its turn reference. A later request from the same link, own thread and turn that re-sends or extends that input and completes upstream releases it. Anything else, or a turn that could not be fingerprinted, stays an operator-only unknown mark. Inert while the link WebSocket switch and its release gate are off. * test(link): name the one traffic block the status test checks * fix(link): release only the marks a resend matched, and settle an aborted relay request's observation Stored running marks now carry their own random id, and a completed resend releases only the marks it matched at its expansion, so an identical mark cut after it stays held. An abort before the relay's handler answers now decides the request's observation as not accepted and drops its unclaimed turn token, even while dispatch is still pending. * fix(link): read the Child sidecar once per traffic status read The traffic row named a Home-initiated link from a second sidecar read, which could see a different file than the first. The Home name now comes from the published settings only when the first read found no sidecar. * docs(link): say that a status read can lag a write still in progress A Child counts a request-body write once it completes, so a read taken mid-upload can show incomplete 0 while the Home already holds a prefix. The contract now says deltas measure completed writes, and a test reads status in that window. * feat(link): show link WebSocket activity holds in status and let the operator clear one link's holds The Child-operations status rows now carry child.holds, with each hold's reasons and counts, but only while something holds that link, so unheld status documents do not change. ocx link activity clear --link-id (POST /api/link/children/activity/clear) forgets one link's holds, including the unknown state left by a crash. The holds file is written before memory forgets anything, so a failed write clears nothing. A clear is refused while the links still cannot be listed. Nothing clears holds automatically (owner decision D8, recommended form). * fix(link): keep a link held across restarts when its activity clear fails or follows an unreadable recovery In a process that has not armed the crash fence, an operator clear now sets the fence running before it writes the holds, and clean only once that write succeeded. A holds write that fails after its rename therefore leaves the fence running, and the next start keeps every link unknown. A successful clear after a recovery that could not list the links now cleans the fence, so the cleared link stays clear after a restart. * fix(link): commit an operator activity clear at its durable holds write Once the holds file without the link is durable, the clear is committed and answers ok. A failure while setting the fence back to clean now leaves the fence running, which marks every link unknown at the next start, or clean, which matches the committed clear. Neither can show a clean fence next to a clear that answered write-failed. * feat(link): let the operator restart one Child past its activity with --ignore-activity A manual Child operation that restarts exactly one link may carry ignoreActivity: true (ocx link sync --link-id <id> --restart-* --ignore-activity, ocx link restart-codex ... --ignore-activity). The engine keeps it only on a manual job, and the runners then skip the activity gate for that item (relayed requests and link WebSocket holds), logging the link id and its in-flight count. Platform, Child-kind and sync refusals still apply. The scheduler and the ocx sync fan-out never set it, and a job without it is unchanged (owner decision D8, recommended form). * fix(link): accept --ignore-activity only on sync and restart-codex operations The Child-operations route accepted ignoreActivity on an update that carried an explicit restart. The update runner keeps the activity gate for its own restart, so the job would have recorded an override that never applied. The route now refuses the flag on anything but sync and restart-codex. * feat(link): record transport, continuation and hashed thread and turn refs on link request rows While the link WebSocket feature is on, a link request's final request-log row (in memory and usage.jsonl) carries an optional link object: - transport: websocket or http; - continuation: chained, full (first or client) or miss (the replay failure's reason, or missing when preparation refuses an unexpanded continuation); - threadRef and turnRef: HMAC refs under the activity reference key, never the raw ids. The relay sets its turn token on relayed POST /v1/responses requests while the feature is on. With the switch unset, every row is unchanged (design T4 section 9.1). * fix(link): read previous_response_id only from an object when classifying a request's continuation The chain-outcome expression added for the link request-log fields ran for every request and read previous_response_id from a body that can be JSON null. Such a request then threw in preparation instead of taking the invalid-request path, even with the feature off. It now checks for a non-null object first. * feat(link): count link WebSocket upgrades, refusals and closes per link behind ?transport=1 The link WebSocket gate now keeps per-link counters in memory: admitted upgrades, refusals by reason, and closes by reason (its own fences, else the peer's close code). GET /api/link/status?transport=1, which ocx link status now requests, adds them to every current link row with the open socket count and the hold count. The counters are display only, reset at restart and dropped with the link. Without the query, and with the feature off, the status documents are unchanged (design T4 section 9.3). * fix(link): forward activity holds, their clear and the WebSocket counters through the listener facade The production management routes reach the link listener through the optional-listener facade, which did not forward linkHolds, clearLinkHolds or linkTransport. On a real Home, status therefore showed no holds and zero counters, and an activity clear answered 'nothing held' without clearing anything. The facade now forwards all three. The clear route answers 503 activity_holds_unavailable when it has no clear hook, instead of an empty success. * test(link): add the link WebSocket release gate, run with the pinned Codex binary The gate tests of design T4 11.1 item 13 drive the pinned Codex binary (OCX_LINK_GATE_CODEX: codex-rs built at openai/codex 88c5856) against a scratch Home. Codex goes through a test-only stand-in for the Child's relay, which runs the challenge, upgrades with the key, sends its own 101 with the 8 MiB limit, and answers a Home refusal with 426. The scenarios are: the switch going off mid-session ending on HTTP, a request over 8 MiB going over HTTP, and a Home restart mid-turn completing. Without the binary each case is skipped with that reason. The Child's tunnel 503 sequence belongs to the Child lane and is skipped with that reason. * test(link): bind the release gate to a recorded Codex digest and prove which transport each scenario used The gate counts as release evidence only when OCX_LINK_GATE_CODEX_SHA256 matches the binary's digest; any other executable runs as a smoke check and every test title says so. The relay stand-in now records each create forwarded on a link socket, with its size, apart from HTTP requests. The oversize case asserts an admitted upgrade, then HTTP, with no message over the limit ever sent on the socket; a control run without the advertised limit shows the oversized request on the socket. The restart case asserts the stalled request was the one forwarded on the socket before any HTTP. * test(link): take the release gate's Codex digest from a reviewed pin file, not the environment The digest a binary must match to count as release evidence now lives in tests/fixtures/link-gate-codex.json, beside the pinned openai/codex revision, and changes only through review. It records none until a build is attested, so every run today is labelled a smoke check. The environment variable for the digest is gone. * fix(link): settle only activity holds that existed when the returning request began A request that returned a result for call id X cleared X from every hold of its thread, including a hold another socket created later while waiting for a new call reusing X. Holds now carry a creation sequence. A link socket records it when a turn begins, and the HTTP relay when a request arrives; acceptance settles only holds at or below it. A newer hold keeps its key. * fix(link): never fingerprint or match a continuation left unexpanded for the upstream When previous_response_id is left for an upstream that owns the history, the body is only a delta. It was fingerprinted as the full input, and a later completed request with the same delta but another history could release the cut request's mark. The chain outcome now reaches the link observers: such a turn's capture is unknown, and its resend matches nothing. * fix(link): observe a combo-routed link turn at the combo's own continuation expansion A combo expands previous_response_id itself and its children replay a snapshot that skips the pipeline's hook. A combo-routed link turn therefore had no fingerprint, no release and no link request-log fields. The combo now reports its own expansion (with the chain outcome), its replay failure, and its refusal of an unresolved continuation to the parent's observer, once. * fix(link): hold the preparation allowance until the Home answered and the upload settled The Child released a prepared body charge once its socket write completed, while the relay still kept the raw and compressed buffers for a possible resend until response headers arrived, and the transport kept them reachable through listeners until the connection closed. The charge now lasts until both the answer and the upload settled, the relay drops its references at that point, and the transport no longer retains the request init. * fix(link): keep per-body zstd out of the Child report so an older Home stays compatible A Home that predates per-body zstd counts every Child-only feature as used and told the owner to upgrade it, although the Child falls back to identity bodies. The Child now leaves optional features out of its peer report, and a Home never counts one against itself. * fix(link): pace synthesized JSON response events on a link socket like SSE events A bounded JSON upstream answer was turned into Responses events and sent in one synchronous loop, without the link pump's drain wait. Several MiB of output to a stalled link reader could overflow Bun's send buffer, and the terminal, which repeats the output, could be dropped. On a link socket each synthesized event now waits for send room under the same stall deadline, and a stall closes the socket with 1011. Local sockets keep the synchronous delivery. * feat(link): let a Home stop offering per-body zstd to its Children Compression lets an observer who can put chosen text beside a secret in repeated requests, and see their sizes, test guesses at the secret. On a link that is a relay operator or anyone on the path, since the tunnel hides content but not sizes. linkRequestCompression: false in the Home config stops naming the capability, and its Children send identity bodies exactly as before. It stays on by default; the guide and structure say why. OcxLinkTransportConfig moves to src/types/link.ts beside the new Home setting, which keeps src/types/config.ts under its line threshold. * test(link): pin how the Home decodes truncated, concatenated and large-window zstd frames, and log a Child-compressed body A truncated frame yields only its complete blocks and the data plane answers 400; concatenated frames decode in full under one ratio bound; a window above 128 MiB is refused before any output. A body a Child compressed through a hub-link session reaches the data plane and its log row carries the wire size, zstd and the decoded size. * docs(link): keep the configuration reference under its line threshold The reference page sits one line below the file-size threshold, so the linkRequestCompression row moves out; the Remote Link guide and structure/remote-link.md document the key. * fix(link): fence a revoked link's sockets before fallible cleanup, and remove failed temporary hold files The link removal route cleared the compensation record before closing the link's WebSockets, so a failed cleanup returned 503 without fencing a socket in the same task. It now closes them right after the store commit. A holds or fence write whose content write or fsync failed left its temporary file behind; it is now removed. The structure page no longer says link admission reclaims no socket. * fix(link): key request-log thread and turn refs to their link threadRef and turnRef were the same for one Codex id on every link of a Home, so rows of different links could be correlated. Nothing needs that: the design's metrics join rows of one link only. The HMAC now covers the link id as its own field, so one id gives unrelated refs on two links. * test(link): make the release gate's drain case run under a live turn, and bound it by file The drain case switched the Home off before any request ran on the socket, so it could pass without exercising the drain. The switch now goes off while the first request runs on the socket. That turn ends by calling a read-only tool Codex declares, and the case asserts four things: - the turn was not cancelled, and its tool result was admitted on the draining socket; - the idle socket was then fenced with 1000; - the next session's upgrade was refused; - that session completed over HTTP. The relay stand-in records the Home's closes. The Codex process bound is now the file's default timeout instead of a per-test timeout. * test(link): let only the canonical RSS load report an acceptance, and add diagnostic levers Every RSS variant (socket count, input size, chunk size, transport) ran under the one acceptance test and could report a pass. Now only the canonical load, all sockets with no diagnostic setting, runs the acceptance assertion. Any setting runs a separate diagnostic case that never asserts the budget, and each title says which. Two diagnostic levers are added: a held upstream (each stream stops after 16 MiB, bounding the Home's fetch read-ahead) and a heap breakdown of the Home at the stall. The child-process bound is now the file's default timeout. * test(link): measure the WebSocket's memory against the HTTP relay's under the same held load Design 6.3's reservation bounds what the link WebSocket transport itself adds, but the acceptance compared the WebSocket's peak RSS with idle, so it also counted upstream read-ahead and request copies that the HTTP link relay holds the same way. The acceptance now runs the canonical stalled load twice, over the WebSocket and over the HTTP relay, each against an upstream held after 16 MiB, and compares their peaks with the socket reservations. A diagnostic with no single-transport setting prints the same pair. The structure page states the definition and the measurements: at 24 sockets the WebSocket adds about 47 MiB per socket over HTTP on a near-8 MiB create, above the 32 MiB reservation, so the acceptance fails and the release gate stays closed. * test(link): name why the RSS acceptance is skipped in the ordinary suite * fix(link): end a superseded JSON delivery's drain wait, and never send a synthesized event over the frame limit On a link socket a JSON upstream answer is sent as Responses events, each waiting for send room. That wait had no cancel: when a new create superseded the turn, the old wait stayed until its stall deadline and could then close the socket under the new turn with 1011. The delivery now registers the turn's cancel, which ends the wait at once, and only a current, uncancelled turn's stall closes the socket. Separately, the terminal event repeats the whole output, so a valid JSON answer could produce an event above the Child's 4 MiB frame limit. Such an event is no longer sent: the turn ends incomplete with the same 502 error frame the SSE pump sends for an oversized upstream frame. Local sockets are unchanged. * test(link): exercise a create fenced on a draining socket within one Codex session The release gate's drain case only showed a new session falling back to HTTP. Design 2.5 requires the pinned-Codex gate to show a refused frame costing one retry. A new case sets the drain deadline to zero through a test-only limits override, so the session's tool-result create is fenced on the draining socket. It asserts that the frame never reached the upstream and that the same request completed over HTTP after Codex's reconnect was refused. Production reads the same limits as before. * test(link): let the RSS acceptance pass only when both Homes report their own stall The WebSocket run waits until the Home reports every link pump waiting for a drain, but the HTTP link relay has no such signal and its run waits only for the upstream's hold. The two peaks can therefore come from different stages, and subtracting them could understate the transport's cost. Each run now reports how it was synchronized, and the acceptance requires a Home-observed stall on both before its difference counts. Until the HTTP relay can report one, the pair is a measurement and the acceptance cannot pass. The structure page also records the JSON pacing and the new gate case. * docs(structure): record the second 24-socket memory measurement * docs(structure): say which link upgrades the traffic book counts * fix(link): release a hold over HTTP when the Child sent the result zstd-coded With #8594 a Child may send a relayed POST /v1/responses body zstd-coded. The hold observation parsed its copy of the body as plain JSON, so a coded body never parsed and a pending result returned over HTTP left its hold in place until the operator cleared it. The copy is now decoded through decodeRequestBody, the handlers' bounded reader with its ratio limit, before it is parsed. A body that does not decode still releases nothing, and the release still applies only after the handler answered below 400. * fix(link): normalize stored holds kept while the activity reference key is unavailable Closes #8607. When the reference key could not be loaded or replaced, startup kept the stored no-thread holds without copying their marks into an array, as the normal path does. A holds file whose entry had no marks field then made summary(), hasMarks() and the hold-completion check read .length of undefined, so the ?children=1 and ?transport=1 status reads threw. That path now copies pendingKeys and marks the same way. * test(link): expect the Home features header on the switched-off relay-auth answer Since #8594 every relay-auth 204 names the Home features. The switched-off characterization still requires that the answer carries no WebSocket state pair. --------- Co-authored-by: Cursor Agent <[email protected]>
This was referenced Nov 12, 2026
Merged
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.
Stacked on #8584 (base: its head 31c2159). Review this PR as the commits after that head; the merges of #8584's later commits into this branch carry only that PR's own changes plus conflict resolution, the latest in
src/client/link-relay-transport.ts.Summary
Every model request a Remote Link Child makes crosses the link uncompressed, and an agent re-sends its whole conversation each time. The Home already decodes zstd request bodies, but nothing on the Child compresses them. With this change, a Child compresses large request bodies with zstd, one body at a time, for a Home that says it accepts them. The Home bounds how far any compressed body may expand, and how much decoded body data it holds at once.
Capability.
link-request-zstd/1is a new peer feature (src/link/request-compression.ts), listed inGET /readyzfeatures and inLINK_PROTOCOL_RELEASES. A Home names its served features on every relay-auth answer inx-opencodex-link-home-features. The Child records them per link after each verified answer, and checks them again on the connection that carries the body. An older Home never names the feature and receives identity bodies exactly as today. A newer Home keeps accepting identity bodies from older Children. The Child leaves this optional feature out of the version-and-feature report it sends its Home (LINK_OPTIONAL_CHILD_FEATURESinsrc/link/compatibility.ts), and a Home never counts it against itself. Otherwise a Home that predates it would show a compatible Child as degraded and tell the owner to upgrade.Home switch.
"linkRequestCompression": falsein a Home'sconfig.json(read at start) stops it naming the capability, and its Children send identity bodies exactly as before this change. The Home still decodes zstd from any client, andGET /readyzis unchanged. The setting is on by default. Compression leaves one residual risk. Someone who can influence repeated requests and see their sizes can test guesses at a secret that shares a body with their text, because a right guess compresses better. On a link that is a relay operator or anyone on the network path, since the tunnel hides content but not sizes. It stays on because the attack needs both chosen text inside the conversation and each request's size, while compression roughly halves the bytes toward the Home. An operator whose threat model includes such an observer turns it off. The guide andstructure/remote-link.mdsay this.Child (
src/client/link-relay.ts,src/client/link-request-compression.ts,src/client/link-relay-transport.ts). The Child prepares a body only when all of these hold:/v1/responses,/v1/responses/compact,/v1/messagesor/v1/chat/completions(the routes whose Home handler decodes Content-Encoding);When those hold:
ssh -Cis never used.Two follow-ups to #8584's final review (its P3 notes, kept here so #8584 stays at its approved head):
?traffic=1status read now reads its link sidecar once. Before, the Home-initiated row took the Home's name from a second read, which could see a different file than the first.incomplete0 while the Home already holds a prefix, and a delta between two reads measures completed writes (src/link/traffic.ts,structure/remote-link.md, the docs guide).Home (
src/server/request-decompress.ts,src/server/inbound-body-admission.ts). Before this change, a 2,067-byte zstd frame decoded to 64 MiB, and nothing bounded decoded bodies across concurrent requests at the default limit.maxOutputLengthenforces it, so inflation stops at that size. A body past the bound gets 413 with its own message (CompressionRatioExceededError).server_busywithout its body being read.Behaviour changes to note:
maxConcurrentInboundBodyBytes).Measurement after merge (acceptance: for a cloud VM Child, bytes toward the Home per input token fall from 3.7–4.2 to 1.7 or less, with no rise in failed requests):
apiKeyIdfromlinks.json.requestBody.wireBytesandusage.inputTokensover that key's rows inocx logs --json(fields from feat(link): measure the bytes each Remote Link carries and record request body size on log rows #8584). Numerator and denominator come from the same rows;requestBody.encodingshould readzstdfor most Child requests after the update.inbound_body_too_largeand 503server_busyin particular.traffic.toHomeBytesdeltas between two readings with the sameepochandgeneration, fromocx link status --jsonon the Home (declared length) or the Child's dashboard status read (bytes the Child's socket took; a lower bound whileincomplete> 0).Verification
Tests that failed first, against the code before each fix:
tests/clients/link-request-zstd.test.ts: real hub-link sessions and the real bound transport. Covers:With the T3a-head relay the compressed-body test failed (no encoding). The review-round cases also failed on the commit before their fix (503; reservation 0; the switch's function did not exist).
tests/clients/link-peer-compatibility.test.ts: the Child's report leaves the optional feature out, and a Home reads a Child reporting it as compatible. Both failed before the fix (the report carried the feature; the verdict was degraded).tests/usage/request-body-log.test.ts: a body a Child compressed, relayed through a hub-link session to the real data plane, is logged as{wireBytes: <compressed>, encoding: zstd, decodedBytes: <original>}after an identity first request.tests/clients/link-traffic-child-status.test.ts: a traffic status read whose sidecar appears between two reads. On the code before the fix it read the sidecar twice (expected 1 read, got 2).tests/clients/link-traffic.test.ts: a status read while a 48 MiB write is pending and the Home has read a 1 MiB prefix showsincomplete0 andtoHomeBytes0. This test pins the documented behaviour and passes on the code before it too.tests/usage/request-decompress-ratio.test.ts: zstd and gzip bombs stop at the ratio bound; the floor; an ordinary body above it; the absolute limit is unchanged; the data plane answers 413. The old decoder accepted the 2,067-byte frame and returned 64 MiB. Truncated, concatenated and large-window frames are pinned to the behaviour above, including the data plane's 400.tests/server/inbound-encoded-body-budget.test.ts: an encoded body's reservation, shrink and release, and a refusal while identity bodies pass. Both failed on the code before the fix.Commands, with exit codes:
bun run typecheck: exit 0 (0.88 s; peak 1-minute load 0.34), run before the last commit, which changes only a docs pagebun run privacy:scan: exit 0bun run structure:check: exit 0bun run lint:gui:if-changed: exit 0 (no GUI changes)bun scripts/test.ts --parallel=2over the gate tests (file-size ratchet, structure-ssot, repo-hygiene, skill-ocx, test-layout, test-layout-tooling, core-lab-boundary, docs-link-targets): exit 0, 153 passbun scripts/test.ts --parallel=2over 17 zstd, decode, ratio, admission, body-size, readyz, request-id, peer-compatibility, request-log and config test files: exit 0, 463 passbun scripts/test.ts --parallel=2over 25 link, relay, listener, traffic, status, CLI and control-socket test files: exit 0, 427 pass, 1 skipThe control-socket tests need a short temporary directory (a Unix socket path has a length limit), so these runs set
TMPDIRto a short path.NOT RUN:
Checklist
structure/remote-link.md,structure/transports/byte-accounting.md,structure/config.md,docs-site/.../guides/remote-link.md. The configuration reference page sits one line below its file-size threshold, solinkRequestCompressionis documented in the guide rather than there.linkRequestCompression: false.One open item for the release:
LINK_PROTOCOL_RELEASESrecordslink-request-zstd/1assince: "2.100.0", the current dev package version, because a test holdssinceat or below the package version. v2.100.x already shipped without it, so the release that ships it should move the number.