Repository navigation
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
Merged
Conversation
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. |
…ffer instead of garbage collection
…ers, from one parse per build (#8601)
…en traffic flow throws
…tch a relay stage that loses the paced mark
… slicer, and the relay as the read-ahead source
…ith the core module boundaries
3 tasks done
…reader-memory # Conflicts: # tests/fixtures/test-layout-expected.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. |
lidge-jun
added a commit
that referenced
this pull request
Nov 13, 2026
…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
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.
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
When a Remote Link Child stops reading a streamed response that the Home relays, the Home holds far more than the bytes in flight (#8601: 66 to 130 MiB per stalled reader, on the HTTP relay and on the link WebSocket). Measuring the pipeline turned up these causes:
fetchis not the source: in a scratch run it stopped at the socket buffers, a few MiB. The inspection tee lets the inspection branch lead the client by 32 MiB plus one chunk (src/server/inspection-tee.ts), and every relay stage after it keeps one chunk queued. With a fake upstream of 1 MiB events and a client that has read nothing, the pipeline had already pulled 36 MiB.passthrough-dispatch.tsre-parsed the outbound request body for the undeclared-tool guard and kept that parsed object for the whole stream. For a large request, that is a second full copy. A combo preflight's replay also kept its buffered prefix after the client had read it.The fix:
pacedReads. The link listener sets it only when the feature is on; link sockets always set it, and they exist only then. Its upstream body is cut into 256 KiB views and marked paced (src/lib/paced-stream.ts). From a paced source, the inspection tee leads by one chunk and the eager relay queues one chunk. Each stage that reads it (block rewrite, failed-tail relay, translator-budget and account-lease wrappers, combo replay) queues nothing ahead and passes the mark on. The stages before the slicer (terminal repair, the web-search bridge, the encrypted-output preflight) keep their default one-chunk queue, asstructure/transports/byte-accounting.mddocuments.outboundToolScopeinsrc/server/responses/outbound-request-body.ts: tools, tool_choice, parallel_tool_calls, and the input items that declare tools). Snapshot repair and the Grok tool scope read nothing else, so they get the same answers from one parse per build. This applies to every passthrough request and changes no output. A block ofpassthrough-dispatch.tsmoved tobare-namespace-aliases.ts, so that file is no longer at the 2,000-line ratchet.tests/e2e-style/link-websocket-rss.test.ts) now arms its stall announcement at the idle reading, so a warm-up turn's drain wait cannot announce the load's stall. The WebSocket run no longer waits for the upstream's hold point, because a paced pump stops pulling before it gets there. Without this change the WebSocket diagnostic hung.Measured on a 4-core Linux VM, four sockets, near-8 MiB create, 16 MiB upstream chunks, one run each, link WebSocket feature on (peak-over-idle RSS per socket, kernel VmHWM; single runs vary by several MiB):
The later commits only shrink what is kept (the tool scope instead of the outbound text) and were not measured separately. Most of what remains is the request itself: the parsed body kept for the continuation store and the serialized body kept for retries. The rest is allocation peaks while a large create is parsed. The link WebSocket's own extra copies are #8600.
What stays unchanged by default: pacing applies only to a link turn while the link WebSocket feature is on. That needs both switches and the release gate (
linkWebsocketTransportReady, still false in this build), so no build paces anything yet. Local HTTP and WebSocket requests, and link requests with the feature off, keep the 32 MiB inspection allowance, the 8 MiB eager queue and every stage's default queue. Tests pin each of those cases. The tool-scope and combo replay changes only drop data nothing reads afterward. Bytes, order, terminals and errors are the same for every request.Refs #8601
Verification
Red first. Each test failed on the base 2c0a9ef (or on f05e87f, where it pins a regression of that head) for the stated reason, and passes now:
tests/responses/stalled-reader-memory.test.ts:setRelayPlatformForTests("win32")), all with the feature on, pulled 36, 36 and 9 upstream chunks.tests/routing/combo-stream-preflight.test.ts: the replay's buffer slots are empty after each read and after cancel. On the base the slots kept their bytes. These assertions replace an earlier WeakRef andBun.gccheck, which conservative stack scanning could make flaky.tests/server/link-websocket-holds.test.ts:Commands (Bun 1.4.4, TMPDIR=/tmp), on head af3d8ea:
bun run typecheck: exit 0bun run privacy:scan: exit 0bun run structure:check: exit 0bun scripts/test.ts --parallel=2over 88 files: exit 0, 2979 pass, 2 skip, 0 fail. The files: the link server tests; the relay, rewrite, failed-tail, snapshot repair, terminal repair, translator-budget, combo preflight, WebSocket endpoint and steering suites; the passthrough suite;tests/responses/responses-core-modules.test.ts; the inbound-body and lab boundary tests;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.tsandtests/clients/link-boundary.test.ts.OCX_LINK_WS_RSS_ACCEPTANCE=1 OCX_LINK_WS_RSS_SOCKETS=4 OCX_LINK_WS_RSS_TRANSPORT=<websocket|http> OCX_LINK_WS_RSS_UPSTREAM=<hold|free>, one at a time.NOT RUN:
bun run testsuite: this VM is limited to focused files with parallelism 2.The shared pipeline changes touch
src/server/relay.ts,relay-eager.ts,sse-payload-rewrite.ts,inspection-tee.ts,src/lib/translator-budget.ts,core-lifetime.ts,combo-stream-preflight.tsandpassthrough-dispatch.ts, soci:fullis advisable.Review
passthrough-dispatch.tshas headroom.Checklist