Skip to content

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

Merged
lidge-jun merged 33 commits into
devfrom
fix/link-websocket-create-memory
Nov 13, 2026
Merged

lidge-jun merged 33 commits into
devfrom
fix/link-websocket-create-memory

Conversation

@lidge-jun

Copy link
Copy Markdown
Owner

Summary

This PR builds on #8622: it is stacked on that branch, and its acceptance runs depend on that PR's paced reads.

The opt-in link WebSocket memory acceptance (design 6.3, tests/e2e-style/link-websocket-rss.test.ts, OCX_LINK_WS_RSS_ACCEPTANCE=1) compares two runs of the same stalled load: 24 link WebSocket creates of nearly 8 MiB each, and the same load sent through the HTTP link relay. The WebSocket run's peak RSS must exceed the HTTP run's by at most 24 × 32 MiB. On dev it did not: the WebSocket run was 1,123 MiB over the HTTP run. It also could not pass by construction, because the HTTP run had no stall the Home reported (#8600).

Where a near-8 MiB create was held, from heap snapshots at the stall and from the code path:

  • Both transports keep the pipeline's parsed body, which the continuation store needs, and the serialized outbound body, which a retry needs. Before 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, both also kept a re-parse of the outbound body and read up to 32 MiB ahead.
  • The WebSocket path added three copies of its own:
    • The shared handler parsed the frame, then serialized it again into a synthetic Request (a transient copy).
    • Bun kept that request's body for the whole turn, about 8 MiB per socket.
    • The pipeline parsed the body back into a second parsed body, another 8 MiB per socket plus the decoded string while parsing.
  • Still WebSocket-only: the design's transport buffers (one event of at most 4 MiB waiting for the drain, plus the socket's own send buffer), a parse of the first create when the handshake carried no thread id, and the HMAC over the canonical input for the hold fingerprint. The last two are transient.

The fix:

  • A link socket hands the pipeline the create it parsed. websocket-handler.ts builds the synthetic request without a body. It binds the parsed object to that request (attachParsedRequestBody in src/server/request-decompress.ts, a WeakMap). Preparation takes it once and admits it with admitParsedJsonRequestBody, which applies the same resolved inbound limit (413 inbound_body_too_large) and the same translator-budget observation as the bounded reader. Every request the pipeline builds from it, whether a combo child, a recovery or a retry, is another Request and reads its own body. A local socket still sends a request body.
  • The HTTP link relay reports its stall. A relayed response reports to a test-only observer (setLinkRelayWaitObserverForTests in link-websocket-limits.ts) from each chunk it hands over until its reader asks again. The RSS fixture counts these waits with the link pump waits, so each run synchronizes on a stall its own Home reports. Without an observer, nothing is called.
  • Docs. structure/remote-link.md carries the attribution and the numbers once, and says what the announcements mark: the first moment every load reader waits at once, which can come before the load's sustained stall. A paused reader's kernel buffer still takes bytes in flight, and a relay also waits in the gap between chunks. Bun exposes no sustained-backpressure signal, and the acceptance uses no quiet period, so runs vary.

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

What stays unchanged by default: the link WebSocket is off unless both switches are set, and the build's release gate (linkWebsocketTransportReady) stays closed, so no link socket exists in any install. Local WebSocket and HTTP requests keep their request bodies. The relay's stall signal runs only while a test installed its observer. Nothing here opens the gate.

Refs #8600

Verification

Red first:

  • tests/server/link-websocket-upgrade.test.ts, "the pipeline takes the frame the socket parsed": on the base, readJsonRequestBody was called once for a link create (expected 0). The local-socket control is still read.
  • Same file, combo case: a link create through a combo reaches the upstream with the combo child's model. An intermediate version that passed the parsed body as a pipeline option failed this test (combo/free). The test passes on the base and now.
  • The 413 case (a create past the configured inbound limit) is a characterization: it passes before and after.
  • tests/server/link-websocket-pump.test.ts (Link WebSocket: find which allocations hold a large create on the Home, then cut the copies or justify a reservation from named buffers #8600 describe): the relay's waiting transitions across reads, the end of the body and cancel. Before the change the file could not load: the seam did not exist.

Canonical acceptance, 24 sockets, 4-core Linux VM, kernel VmHWM, peak over idle per socket:

Run Code WebSocket HTTP Difference Budget Result
dev before #8622 (structure page) 117.0 70.2 1,123 MiB 768 MiB fail
1 relay signal only 87.7 45.5 1,013 MiB 768 MiB fail
2 + parsed create 62.2 47.3 356 MiB 768 MiB pass
3 same 53.0 46.6 154 MiB 768 MiB pass
5 final synchronization 52.4 51.0 33 MiB 768 MiB pass
6 head merged with #8622's fixes 56.9 49.5 179 MiB 768 MiB pass

Run 4 tried a three-event-loop-turn confirmation that was later removed (it passed at 276 MiB).

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 over 98 files (link server tests, the Responses relay, rewrite, snapshot repair, combo, WebSocket endpoint and steering suites, the request-decompress and body-size suites, the core module boundaries, layout, structure, file-size ratchet, and the client and lab boundaries) on dd5f74a: exit 0, 3218 pass, 4 skip, 0 fail. After the comment and whitespace commit (9d46df1), 14 of those files were rerun: 640 pass, 2 skip, 0 fail.
  • OCX_LINK_WS_RSS_ACCEPTANCE=1 bun test tests/e2e-style/link-websocket-rss.test.ts: the runs in the table, one at a time.

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.

Review

A read-only reviewer (gpt-6.1-terra, xhigh) ran three rounds:

  • Round 1:
    • P1, accepted: the parsed body, passed as a pipeline option, was inherited by combo children, recoveries and retries. It is now bound to the turn's own request, with a regression test.
    • P2, accepted after a first rebuttal: the HTTP stall announcement can fire while bodies still flow.
  • Round 2: P2: a three-turn confirmation I had added does not prove a stall. I removed the confirmation.
  • Round 3: P2: a paused reader does not make a pump's wait permanent, because kernel buffers still take bytes in flight. The reviewer measured this. The early-cut argument is also not a strict proof. I accepted the finding and removed both claims from the test and the structure page, which now say what the announcements mark.

Open: synchronizing on a sustained stall would need either a quiet period (a timer, which this lane's rules forbid in tests) or socket state that Bun does not expose for HTTP responses. The acceptance therefore compares the loads at their first all-waiting moment. All recorded runs passed with room to spare, but they do not prove a sustained-stall comparison. Whether to add a quiet period to this opt-in acceptance is left to the maintainer.

Checklist

  • Scope stays focused and avoids unrelated cleanup.
  • Docs or release notes were updated when needed (structure/remote-link.md).
  • Security-sensitive changes were reviewed for secrets, auth, and unsafe defaults (no auth or credential path changes; the link create keeps the inbound limit and budget accounting).

…rts for the load, not the warm-up or the upstream hold
… so both RSS acceptance runs sync on a stall the Home reports (#8600)
…ead of serializing it into a request and parsing it back (#8600)
…mbo children, recoveries and retries read their own bodies (#8600)
…real under paused readers and an early HTTP cut only makes passing harder
… slicer, and the relay as the read-ahead source
…ocket-create-memory

# Conflicts:
#	structure/remote-link.md
@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
Base automatically changed from fix/responses-stalled-reader-memory to dev November 13, 2026 03:31
… (#8622)

The squash's tree equals the merge of eab8bb9 with dev 9532563, so this commit records the squash as an ancestor without changing any file.
…e-memory

Brings in dev 9532563 and the squash of the lower slice; no file of this slice is edited (git merge-tree, no conflicts).
@lidge-jun
lidge-jun marked this pull request as ready for review November 13, 2026 04:29
@lidge-jun
lidge-jun requested a review from Ingwannu as a code owner November 13, 2026 04:29
@lidge-jun
lidge-jun merged commit 430c4bd into dev Nov 13, 2026
32 checks passed
@lidge-jun
lidge-jun deleted the fix/link-websocket-create-memory branch November 13, 2026 04:29
@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-13T04:31:27.744808Z 07de08e 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 added a commit that referenced this pull request Nov 13, 2026
…ance, the Home counts link sockets, and the review nits of #8622 and #8625 (#8647)

* test(responses): pin the combo replay on a paced source, and only the read slots on an unpaced one

* fix(responses): a combo child's required-tool check keeps whether the outbound body denies every tool, not the parsed body

* fix(link): end every relayed request's traffic flow through one guarded helper, so a throwing end never keeps the lease

* fix(link): a throwing stall observer never breaks a relayed body

* test(link): a parsed create stays with its own request when a fallback or recovery builds the next one

* docs(link): note that a link create's parsed body shares its nested input with the frame

* feat(link): the Home counts each link WebSocket in its per-link traffic book with the Child's definition

* test(link): the RSS acceptance announces a stall only after a quiet window, and fails a load that does not settle

* docs(link): only the settled acceptance runs count, and how the quiet window settles them (#8600)

* docs(link): the Home counts link sockets in the Child's units, and says where completeness differs

* docs(link): the traffic counters' comments cover a link socket's message payloads

* docs(responses): the required-tool check keeps its tool declarations as well as whether the body denies every tool

* test(link): a refused or failed link upgrade counts nothing in the Home's traffic book

* style(link): drop the trailing blank line from the gate and the RSS fixture

* docs(link): the quiet window's timers are the only ones that change adds to the RSS fixture

* test(link): the failed-upgrade case proves the gate reached server.upgrade

* test(responses): the workflow ceiling test's hand-made socket carries 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.
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