Skip to content

fix(link): link WebSocket readiness follow-ups: settled memory acceptance, the Home counts link sockets, and the review nits of #8622 and #8625 - #8647

Merged
lidge-jun merged 18 commits into
devfrom
fix/link-websocket-readiness-followups
Nov 13, 2026
Merged

lidge-jun merged 18 commits into
devfrom
fix/link-websocket-readiness-followups

Conversation

@lidge-jun

@lidge-jun lidge-jun commented Nov 13, 2026 •

Copy link
Copy Markdown
Owner

Summary

These are the follow-ups from the final reviews of #8622 and #8625, plus two items required before the PR that opens the link WebSocket release gate (linkWebsocketTransportReady). Nothing here opens the gate. Each item is its own commit.

The branch merges dev at 6f58f62 with a normal merge commit (no conflicts). That dev carries a test from #8415 that hands sendResponseToWebSocket a hand-made socket with no data; once the Home counts link socket traffic, sendTextFrame reads ws.data.link on every send, so that test threw. Every socket the shared Responses server upgrades carries a WsData object, and the bridge already reads ws.data elsewhere, so the fix gives the test's socket a data object and production code gains no guard.

  • The memory acceptance is now settled (Link WebSocket: find which allocations hold a large create on the Home, then cut the copies or justify a reservation from named buffers #8600). The opt-in RSS acceptance (tests/e2e-style/link-websocket-rss.test.ts, OCX_LINK_WS_RSS_ACCEPTANCE=1) cut each run at the first moment every reader was waiting. That moment can come before the load's sustained stall. Because the peak (VmHWM) is read after the cut, a WebSocket run cut early reported a lower peak and passed more easily.
    • The fixture (tests/fixtures/link-ws-rss-home.ts) now announces the stall only after a 2.5 s quiet window in which every reader stays waiting and VmHWM does not rise; either break restarts the window.
    • A load that has not settled 180 s after the idle reading fails the run. A timeout never produces a pass.
    • Each run prints the window and its settle time.
    • These are the only timers this change adds (the fixture already sampled RSS every 2 ms where the kernel peak is unavailable), and they exist only in this opt-in fixture, which is a physical measurement that already runs on wall-clock time.
    • The test's fake upstream sets idleTimeout: 0, so a held stream is not cancelled during the window.
    • structure/remote-link.md now states that the four earlier runs recorded under fix(link): the link WebSocket's memory acceptance passes: a link socket no longer re-serializes its create, and the HTTP relay reports its own stall #8625 are not release evidence, and records three settled runs on 2e8b3f3.
  • The Home counts link sockets in its traffic book. Until now, a link WebSocket's traffic went uncounted on the Home, while the Child already counted it. Each link socket is now one request in the Home's per-link book, in the Child's units:
    • The flow starts when the gate opens an admitted socket; a refused or failed upgrade counts nothing.
    • Toward the Home: the payload bytes of every message received, fenced or not.
    • From the Home: the payload bytes of every message Bun took for the socket, written or queued (sendTextFrame). A send Bun dropped is not counted.
    • Framing, the handshake and control frames are not counted.
    • The flow is complete when a close frame ended it, from either side. A socket dropped without one (close code 1006 or 1015) is incomplete.
    • Completeness is decided differently on the two sides: the Home counts any close frame as complete, while the Child also counts its own overload (1001 to the Home), binary (1003) and protocol (1002, 1009 and the like) closes as incomplete. The structure pages and the header and field comments of src/link/traffic.ts say so.
    • Link sockets exist only while the switch and the release gate are on. A local socket has no flow.
  • fix(responses): while the link WebSocket feature is on, a stalled Remote Link reader no longer makes the Home read 32 MiB ahead, and no turn keeps a second parsed copy of its request #8622 review:
    • (A) The combo replay test runs on a paced source and asserts exact slots after an extra event-loop turn. On an unpaced source it asserts only the slots already read.
    • (B) A streaming combo child's required-tool check keeps whether the outbound body denies every tool and its tool declarations (shallow copies, which can share nested schema objects), never the parsed body.
    • (C) Every traffic flow in the relay ends through one guarded helper, so an end that throws never keeps the lease.
    • (D) The files that review named (src/lib/paced-stream.ts, src/server/responses/bare-namespace-aliases.ts, tests/responses/stalled-reader-memory.test.ts, tests/server/link-websocket-holds.test.ts, tests/routing/combo-stream-preflight.test.ts) already end cleanly on dev. The two files this PR touches that ended with a blank line (src/server/index/link-websocket.ts, tests/fixtures/link-ws-rss-home.ts) no longer do.
  • fix(link): the link WebSocket's memory acceptance passes: a link socket no longer re-serializes its create, and the HTTP relay reports its own stall #8625 review:
    • (1) The structure page describes the settled measurement. It also says the earlier runs leaned toward passing.
    • (2) A comment notes that a link create's parsed body shares its nested input with the frame.
    • (3) The relay's test-only stall observer is called through a guard.
    • (4) A binding test shows that a parsed create stays with its own request when a policy fallback or compaction recovery builds the next one, and the docs name the tests.
    • (5) The earlier runs are described as single runs on successive commits.

Settled canonical acceptance, 24 sockets, single runs on commit 2e8b3f3, 4-core Linux VM, kernel VmHWM, peak over idle per socket:

Run WebSocket HTTP Difference Budget Settled after (WS, HTTP) Result
1 54.4 MiB 46.4 MiB 193 MiB 768 MiB 6.6 s, 7.9 s pass
2 58.6 MiB 46.7 MiB 287 MiB 768 MiB 5.9 s, 8.1 s pass
3 52.1 MiB 46.7 MiB 129 MiB 768 MiB 5.9 s, 8.1 s pass

The reservation (32 MiB), the budget (768 MiB) and the cap (24 sockets) are unchanged.

What stays unchanged by default:

  • The traffic counting runs only on link sockets, which exist only once the gate opens.
  • The quiet window lives only in the opt-in acceptance fixture.
  • The relay and combo changes only guard paths that cannot throw today, or drop a reference that nothing reads after the check is built.
  • Local sockets, HTTP relays and requests with the feature off behave as before.

Refs #8600

Verification

Red first. Each test in this list failed before its commit for the stated reason:

  • tests/routing/combo-stream-preflight.test.ts: with one event-loop turn after each read, the old test saw the replay take the next slot ahead of the client (expected 2, received 0).
  • tests/responses/stalled-reader-memory.test.ts: changing the parsed outbound body after the required-tool check was built flipped its answer (expected true, received false), because the check still read the body.
  • tests/server/link-websocket-holds.test.ts: a flow end that throws on the body paths ("end failed"), so the lease was kept.
  • tests/server/link-websocket-pump.test.ts: a test observer that throws broke the relayed body ("observer failed").
  • tests/server/link-websocket-traffic.test.ts (new): a link socket counted nothing, with zero requests and zero bytes.
  • tests/server/link-websocket-transport-status.test.ts now asserts exact counts through a real Home, and failed on the base, which counted zero.

These tests pass before and after their commits; they pin behaviour that was already right:

  • tests/usage/request-decompress.test.ts: the binding test for review item 4 (a parsed create stays with its own request).
  • tests/server/link-websocket-traffic.test.ts, "a refused or failed upgrade counts nothing": an unauthorized upgrade (401, server.upgrade never reached) and a failed one (426, server.upgrade reached once and returning false) leave zero requests and zero bytes. A temporary mutation that begins the flow before the gate's checks turned it red, together with the first two traffic tests; the mutation was reverted.

The settle deadline was exercised by temporarily setting it to 200 ms: the run failed with "the load did not settle".

Commands (Bun 1.4.4, TMPDIR=/tmp):

  • On a083956 (this head, after the dev merge): bun run typecheck, bun run privacy:scan, bun run structure:check and git diff --check origin/dev exit 0; bun scripts/test.ts --parallel=2 over responses-websocket-workflow-ceiling.test.ts, all tests/server/link-websocket-*.test.ts (traffic and transport-status included), the two layout tests, link boundary, structure and file-size ratchet: 14 files, exit 0, 245 pass, 0 fail; and over the 25 test files that build a socket with as unknown as ServerWebSocket: exit 0, 1019 pass, 0 fail. Without the test fix the merged head fails the workflow ceiling test with TypeError: undefined is not an object (evaluating 'ws.data.link').
  • On cc9f3b9: bun run typecheck, bun run privacy:scan, bun run structure:check and git diff --check origin/dev exit 0, and bun scripts/test.ts --parallel=2 over 21 files (the link server tests, link-traffic.test.ts and link-traffic-child-status.test.ts, stalled-reader-memory.test.ts, the combo required-tool suites, the RSS test skipped without opt-in, the lab, link and core-link boundaries, layout, structure and file-size ratchet) exit 0, 452 pass, 2 skip, 0 fail. The commits after b7c8018 change comments, structure pages, one test file and two trailing blank lines.
  • On b7c8018: bun scripts/test.ts --parallel=2 over 52 files, exit 0, 1408 pass, 2 skip, 0 fail: the link server tests, stalled-reader-memory.test.ts, the combo preflight and required-tool suites, request-decompress.test.ts, the core module boundaries, the WebSocket endpoint tests, link-traffic.test.ts, the RSS test (skipped without opt-in), the lab and link boundaries, layout, structure and file-size ratchet.
  • OCX_LINK_WS_RSS_ACCEPTANCE=1 bun test tests/e2e-style/link-websocket-rss.test.ts: three times on 2e8b3f3, one at a time, all exit 0 (table above).

NOT RUN:

  • The full bun run test suite: this VM is limited to focused files with parallelism 2.
  • Cross-platform CI: left to the batched dev run.

Checklist

  • Scope stays focused and avoids unrelated cleanup.
  • Docs or release notes were updated when needed (structure/remote-link.md, structure/transports/byte-accounting.md, the header of src/link/traffic.ts).
  • Security-sensitive changes were reviewed for secrets, auth, and unsafe defaults (no auth or credential path changes; counting adds no logging of content).

@coderabbitai

coderabbitai Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Caution

Review failed

The pull request is closed.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Share

@github-actions

github-actions Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

✅ Deterministic PR hygiene checks passed.

@github-actions github-actions Bot added the bug Something isn't working label Nov 13, 2026
…as well as whether the body denies every tool
… its WsData, as every upgraded socket does

#8415 added a test that hands sendResponseToWebSocket a socket with no data. Every socket the shared Responses server upgrades carries a WsData object (the Responses socket, the live sideband, the Remote Workspace agent and the link gate all pass data to server.upgrade), and the bridge already reads ws.data on its other paths, so the socket in the test is what was wrong; since the Home counts link socket traffic, sendTextFrame reads ws.data.link on every send and the test threw.
@lidge-jun lidge-jun closed this Nov 13, 2026
@lidge-jun lidge-jun reopened this Nov 13, 2026
@lidge-jun lidge-jun closed this Nov 13, 2026
@lidge-jun lidge-jun reopened this Nov 13, 2026
@lidge-jun
lidge-jun marked this pull request as ready for review November 13, 2026 08:11
@lidge-jun
lidge-jun requested a review from Ingwannu as a code owner November 13, 2026 08:11
@lidge-jun
lidge-jun merged commit bc36d5b into dev Nov 13, 2026
102 of 122 checks passed
@lidge-jun
lidge-jun deleted the fix/link-websocket-readiness-followups branch November 13, 2026 08:11
@lidge-jun

Copy link
Copy Markdown
Owner Author

Maintainer integration record for this squash merge.

  • Head merged: a083956.
  • Review: a fresh reviewer read b7c8018; the commits after it are comment, structure and test changes (W-4-2), one plain merge of dev and a one-line fix to a dev test's hand-made socket (W-4-3), each read as a delta.
  • Checks: hosted run 43381587049 passed on the merge with dev f23910a (after feat(link): sync route intent and materialize clients per device (re-land #8276) #8416); the lane ran its nine test files on that merge and found that W-4's listener tests reach the real route-defaults capture under a temporary home without a warning or a left-over timer.
  • On the final merge tree (dev 3762722, exported to a scratch directory on macOS, Bun 1.4.4): tsc --noEmit clean, the two test-layout files pass (29), and the nine link WebSocket test files pass 155 of 155 in most runs. About 1 run in 15 fails in tests/server/link-websocket-fingerprints.test.ts ("an HTTP resend answered 200 leaves 0 fingerprinted marks"), a test from feat(link): the Home accepts the Responses WebSocket over a Remote Link, behind a closed release gate #8593 this PR does not change. I instrumented a scratch copy: at the timeout the holds file exists and holds exactly the one mark the test expects, so the Home did its work and the test's fs.watch event was missed (the watcher is armed asynchronously on macOS). It did not occur in 40 runs of plain dev, so this PR probably writes the hold earlier; that is not a defect. A deterministic wait for that test follows as its own PR.
  • The Home's gate (linkWebsocketTransportReady) stays closed.
  • NOT RUN on the final merge tree: the full shards; the settled 24-socket memory acceptance (to be rerun at the gate-opening head).

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-13T08:14:13.796033Z a083956 Draft marked ready
ℹ️ 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" or "@codex security review".

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

Copy link
Copy Markdown
Owner Author

Correction to my integration record above. The longer comparison has finished: 30 fresh-copy runs of the nine link WebSocket test files on each tree gave 28 pass and 2 fail on the merge tree, and 28 pass and 2 fail on plain dev 3762722 (before this PR). Every failure is the same case in tests/server/link-websocket-fingerprints.test.ts. So the missed fs.watch event on macOS has the same rate with and without this PR; my sentence that it "did not occur in 40 runs of plain dev, so this PR probably writes the hold earlier" was wrong (the earlier dev runs were simply too few). The conclusion stands: the test from #8593 races its watcher on macOS, the Home writes the hold correctly, and this PR does not change that. The deterministic wait follows as its own PR.

lidge-jun added a commit that referenced this pull request Nov 13, 2026
scripts/test-layout/layout.json: both sides appended to the explicit map; the union keeps link-websocket-traffic.test.ts from #8647 and link-gate-codex-binary.test.ts from this branch. tests/fixtures/test-layout-expected.json auto-merged to the same set.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant