Repository navigation
fix(relay): fail an oversized response instead of closing the client - #17968
Conversation
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Over-budget RPC response now fails its own request.
sendResponsepasses'reject'to bothenqueuePreparedFramecalls, so a control-lane overflow substitutes aResponseOverCapacityerror instead of the fatalclose-clientdefault that dropped the whole connection before the substitute could run. - New degradation tests with negative controls.
makeUnsettledWriteClient(a sink that accepts but never settles writes) pins the substitute path, and the new suites confirmpty.replay/protocol-critical control overflow still closes, and a fully-saturated queue drops without closing (client timeout is the backstop). - Comment corrections.
file-range-read.tsandfs-handler-file-range.test.tsnow describe refusal rather than fatal close.
I traced the 'reject' flag through enqueuePreparedFrame → enqueue → admitControl: non-fatal overflow returns { accepted: false } with no error, so the writer neither closes nor settles onSettled, leaving exactly one settlement (the substitute, or handleRequest's manual settle when even it won't fit). The substitute settlement correctly wraps a successful write into { ok: false } so the fence never claims delivery. Wire content is unchanged — the <code>-33008</code> substitute predates this PR on the legacy-response lane — so no capability/opcode negotiation is required. Everything checks out.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
The relay's control lane is a shared 1 MiB budget, and `sendResponse` admitted responses onto it with the fatal default: once the lane was full, admission closed the client. A ~900 KB `fs.listFiles` reply from a large remote workspace therefore took down the whole remote session -- every terminal on it -- rather than failing the one Quick Open request. The substitute `ResponseOverCapacity` frame already there only covered the `legacy-response` lane, because the fatal close beat it to the client. A JSON-RPC response is the droppable class of control frame: it carries an id, so one caller can be told and can retry. `pty.replay` and `notifyControl` keep the fatal default -- they are never re-sent, and a silent drop there desyncs the client with nothing to retry. Both response enqueues now pass `controlOverflow: 'reject'`, so the substitute error is what the caller sees; in the corner where even ~150 bytes will not fit, the caller's own 30s request timeout settles it and the session survives. Old clients are unaffected: they already decode this error code and message generically (`ssh-channel-multiplexer.handleResponse` rejects the pending promise with both), and the frame shape is unchanged. What changes is that a listing which used to drop the connection now returns an error on it.
df99819 to
e8e1c00
Compare
|
Retargeted to Reason: review established this PR does not depend on #17954. It fixes a bug that is live on Proof the bug is on Identical failures on the #17954 intermediate — so #17954 makes the bug far more reachable (by sizing responses at 99.6% of the shared control lane) but does not create it. Mechanism: This is the OSS-standard shape, not merely a bug fixThe organizing rule across implementations: a length field nested inside an already-delimited frame is safe to reject locally; a length field that IS the delimiter is fatal.
Our framing layer already handles the genuinely fatal case more gracefully than OpenSSH: The first-violation fatal close is correctly retained for Wire compatibilityRule 3 exposure is benign: a listing that used to drop the connection now returns Merging once CI is green against the new base. The remaining three PRs in the original chain (#17870, #17934, #17954) stay held on their own findings. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Team Run ID: 📒 Files selected for processing (4)
Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review. 📝 WalkthroughWalkthrough
Merge Risk: 🔵 Low · up to Oversized RPC responses now fail the individual request instead of disconnecting the shared remote session. The change is mergeable with owner awareness of a bounded cleanup risk if cancellation overlaps a stalled response write, where per-connection state may remain until the write settles or the connection closes. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Description checkExplanation The description is detailed and covers the problem, implementation, compatibility, testing, and known caveat. The required Linked Issue field remains incomplete, and the Visual Proof section is missing even though this changes runtime behavior.
✨ Finishing Touches 💡 2📝 Generate docstrings 💡
🛠️ Fix failing CI checks 💡
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. Comment |
…blyai#17968) The relay's control lane is a shared 1 MiB budget, and `sendResponse` admitted responses onto it with the fatal default: once the lane was full, admission closed the client. A ~900 KB `fs.listFiles` reply from a large remote workspace therefore took down the whole remote session -- every terminal on it -- rather than failing the one Quick Open request. The substitute `ResponseOverCapacity` frame already there only covered the `legacy-response` lane, because the fatal close beat it to the client. A JSON-RPC response is the droppable class of control frame: it carries an id, so one caller can be told and can retry. `pty.replay` and `notifyControl` keep the fatal default -- they are never re-sent, and a silent drop there desyncs the client with nothing to retry. Both response enqueues now pass `controlOverflow: 'reject'`, so the substitute error is what the caller sees; in the corner where even ~150 bytes will not fit, the caller's own 30s request timeout settles it and the session survives. Old clients are unaffected: they already decode this error code and message generically (`ssh-channel-multiplexer.handleResponse` rejects the pending promise with both), and the frame shape is unchanged. What changes is that a listing which used to drop the connection now returns an error on it.

Stacked on #17954 — review that first. Fixes the latent hazard #17954 found and deliberately left alone.
ELI5
An oversized RPC response closed the whole connection instead of failing the one request. On a large remote workspace a single Quick Open listing could drop the user's entire remote session — every terminal on that host going with it. This is live today, not introduced by the stacked PRs.
Now an oversized response returns an error on the connection and everything else keeps running.
This was a bug, not a design choice — the intent was already written down
sendResponsealready carried the comment:The control-lane branch just never reached it. Fatal admission closes the client before the substitute error is attempted, and
enqueuePreparedFramethen short-circuits onclient.closed. So the substitute only ever worked for thelegacy-responselane (frames >1 MiB), never for the shared-budget overflow #17954 flagged.The fatal close is deliberate for other control traffic — and stays
Every control-lane producer was read. Two classes, and the codebase already distinguishes them:
Un-droppable — keeps the fatal default:
notify('pty.replay')(dispatcher-notification-publication.ts:33), with a standing comment: "replay is never re-sent, so it takes the control lane where overflow is fatal — the writer closes the client and reconnect reloads history rather than stranding a short buffer."notifyControl(:131) — callscloseClientitself on rejection.notifyClient/tryNotifyClient(:110) — caller-selectable, defaults fatal.Droppable:
dispatcher-rpc-routing.ts:254) — already passed'reject'. That is the author's own precedent: a frame with an id and one waiting caller is droppable.ResponseOverCapacitysubstitute path written for exactly this purpose.The client always settles; only the close costs terminals
From
ssh-channel-multiplexer.ts:handleResponse(:510) rejects the pending promise with the message andcode. Usable error, no hang.dispose()(:374) rejects every pending request and tears down the session.REQUEST_TIMEOUT_MSrejects and sendsrpc.cancel. Bounded.All three settle. Only one costs the user their panes.
User-facing regressions
None. The only behavior change is that a case which previously killed the session now returns an error.
Corner case covered: when even the ~150-byte substitute cannot be admitted, that is also
'reject'rather than fatal — no frame, no close, the host-side fence settles, and the client's timeout is the backstop. Killing every pane to report one failed listing is the outcome this path exists to avoid.No budget was changed.
QUICK_OPEN_LISTING_MAX_RESPONSE_BYTESandMAX_FILE_RANGE_READ_BYTESare untouched — the ~11k-file cap question #17954 raised is a product decision and stays open.Wire compatibility (Rule 3)
Changes published content, not frame shape: a listing that used to drop the connection now returns
{"error":{"code":-33008,"message":"Relay response exceeded the bounded transport capacity"}}.Old-client impact is benign — that decode path is version-independent,
ResponseOverCapacity(-33008) has shipped since 2026-08-01, and nothing switches on the code. No opcode, no capability, no new field.cross-version-terminal-wire.unit.test.ts10/10.Testing
Before:
After:
Tests 21 passed (21).Negative control —
still closes the client when a protocol-critical control frame overflows— passed before and after, sopty.replayoverflow still closes as designed.pnpm test src/relay src/main/ssh: 3373 passed | 18 skipped.tc:nodeclean.check:code-quality:changed: 0 new findings across 25 files.The new
makeUnsettledWriteClientharness models a peer whose socket is behind — writes accepted but never settled, so control bytes stay retained while other lanes keep pumping. The existingmakeSaturatingClientcannot express that shape because it blocks every lane.Comment-only corrections in
file-range-read.tsandfs-handler-file-range.test.ts, which both asserted "overflowing it closes the client" — now false. The two-deep-headroom rationale survives (it keeps the refusal rare) and its pinning test is unchanged.Caveat
This fixes the failure mode, not the frequency. Because the control lane is a shared budget, a near-1 MiB listing still fails under unrelated concurrent load. That is the product decision #17954 raised, deliberately left open.