Skip to content

fix(relay): fail an oversized response instead of closing the client - #17968

Merged
nwparker merged 1 commit into
mainfrom
fix/control-overflow-reject
Sep 2, 2026
Merged

nwparker merged 1 commit into
mainfrom
fix/control-overflow-reject

Conversation

@nwparker

@nwparker nwparker commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​100 $\color{#cf222e}{\Huge{\mathbf{−}}}$​4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​96
Prod 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​16 $\color{#cf222e}{\Huge{\mathbf{−}}}$​7 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​9

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

sendResponse already carried the comment:

"an oversized response must fail its own request; closing would kill every pane on the host"

The control-lane branch just never reached it. Fatal admission closes the client before the substitute error is attempted, and enqueuePreparedFrame then short-circuits on client.closed. So the substitute only ever worked for the legacy-response lane (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) — calls closeClient itself on rejection.
  • notifyClient/tryNotifyClient (:110) — caller-selectable, defaults fatal.

Droppable:

  • Relay→client requests (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.
  • RPC responses — same property, plus a ResponseOverCapacity substitute path written for exactly this purpose.

The client always settles; only the close costs terminals

From ssh-channel-multiplexer.ts:

  • Errored response → handleResponse (:510) rejects the pending promise with the message and code. Usable error, no hang.
  • Closed connection → dispose() (:374) rejects every pending request and tears down the session.
  • Silent drop → the 30s REQUEST_TIMEOUT_MS rejects and sends rpc.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_BYTES and MAX_FILE_RANGE_READ_BYTES are 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.ts 10/10.

Testing

Before:

 FAIL  src/relay/dispatcher-capacity-degradation.test.ts > answers an over-budget response with a capacity error instead of closing the connection
AssertionError: expected 1 to be +0
 FAIL  src/relay/dispatcher-capacity-degradation.test.ts > drops an unsendable response without closing when even the capacity error will not fit
AssertionError: expected 1 to be +0
 Test Files  1 failed (1)
      Tests  2 failed | 19 passed (21)

After: Tests 21 passed (21).

Negative control — still closes the client when a protocol-critical control frame overflows — passed before and after, so pty.replay overflow still closes as designed.

pnpm test src/relay src/main/ssh: 3373 passed | 18 skipped. tc:node clean. check:code-quality:changed: 0 new findings across 25 files.

The new makeUnsettledWriteClient harness models a peer whose socket is behind — writes accepted but never settled, so control bytes stay retained while other lanes keep pumping. The existing makeSaturatingClient cannot express that shape because it blocks every lane.

Comment-only corrections in file-range-read.ts and fs-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.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes

  • Over-budget RPC response now fails its own request. sendResponse passes 'reject' to both enqueuePreparedFrame calls, so a control-lane overflow substitutes a ResponseOverCapacity error instead of the fatal close-client default 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 confirm pty.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.ts and fs-handler-file-range.test.ts now 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.

Pullfrog  | View workflow run | Using 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.
@nwparker
nwparker force-pushed the fix/control-overflow-reject branch from df99819 to e8e1c00 Compare September 2, 2026 08:00
@nwparker
nwparker changed the base branch from fix/quick-open-byte-budget to main September 2, 2026 08:01
@nwparker

nwparker commented Sep 2, 2026

Copy link
Copy Markdown
Contributor Author

Retargeted to main and rebased (df99819565e -> e8e1c007bb3, cherry-picked cleanly, 4 files / +116 -11 unchanged).

Reason: review established this PR does not depend on #17954. It fixes a bug that is live on main today, so stacking it behind the byte-budget change would delay a production fix and drag an unrelated regression along with it.

Proof the bug is on main, not introduced by the parent — this PR's own tests, run against origin/main:

FAIL > answers an over-budget response with a capacity error instead of closing the connection
  AssertionError: expected 1 to be +0     (primary.closes === 1)
FAIL > drops an unsendable response without closing when even the capacity error will not fit
  AssertionError: expected 1 to be +0

2 failed | 19 passed

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: sendResponse (dispatcher-rpc-routing.ts:191-231) calls enqueuePreparedFrame(...) without controlOverflow, which defaults to 'close-client' (dispatcher-frame-codec.ts:85). admitControl returns {accepted:false, error} (dispatcher-writer-admission.ts:224-236) and the writer closes the client before the substitute error is attempted, and enqueuePreparedFrame short-circuits on client.closed. The existing comment — "an oversized response must fail its own request; closing would kill every pane on the host" — was never reachable on the control lane.

This is the OSS-standard shape, not merely a bug fix

The 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.

  • OpenSSH shows both in one file — channels.c:3527-3531 discards an over-maxpacket payload with logit() and return 0, not even failing the channel; packet.c:1658-1666 disconnects on PACKET_MAX_SIZE, because packlen is the boundary and is unauthenticated at that moment.
  • libssh2 packet.c:988 carries the comment "Spec says we MAY ignore bytes sent beyond packet_size" and never disconnects on any of its three oversize checks.
  • gRPC returns RESOURCE_EXHAUSTED on the one RPC; HTTP/2 reserves connection errors for SETTINGS_MAX_FRAME_SIZE violations (RFC 9113 §4.2/§6.5.2).

DISPATCHER_CONTROL_QUEUE_MAX_BYTES is a sender-side queue budget enforced at admission, nested entirely inside framing that MAX_MESSAGE_SIZE already delimits. So the pre-existing fatal close was the transport-level remedy misapplied at the application level — a design error, not an oversight.

Our framing layer already handles the genuinely fatal case more gracefully than OpenSSH: relay-frame-decoder.ts:126-135 discards the header, drains exactly length bytes, publishes an error and continues — the delimiter is never lost, so no disconnect is needed.

The first-violation fatal close is correctly retained for pty.replay/notifyControl, which is the integrity-shaped case (a silently dropped replay desyncs scrollback with nothing to retry). The negative-control test pins that.

Wire compatibility

Rule 3 exposure is benign: a listing that used to drop the connection now returns {"error":{"code":-33008,...}}. ResponseOverCapacity has shipped since 2026-08-01 and nothing switches on the code. No new opcode — src/shared/terminal-stream-protocol.ts is untouched — so Rule 2 is not engaged.

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.

@coderabbitai

coderabbitai Bot commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Team

Run ID: 85f24d87-92bd-4838-aa77-163e4a2ae701

📥 Commits

Reviewing files that changed from the base of the PR and between e02347a and e8e1c00.

📒 Files selected for processing (4)
  • src/relay/dispatcher-capacity-degradation.test.ts
  • src/relay/dispatcher-rpc-routing.ts
  • src/relay/fs-handler-file-range.test.ts
  • src/shared/file-range-read.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review.


📝 Walkthrough

Walkthrough

sendResponse now rejects both primary and substitute response frames when the control lane lacks capacity. Tests cover continued client operation, fatal protocol-critical overflow, and failed settlement when neither frame can be admitted. Comments document the shared transport budget and the updated ResponseOverCapacity behavior.

Merge Risk: 🔵 Low · up to e8e1c

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)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 4 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly and concisely describes the main change: oversized responses now fail without closing the client.
Description check ✅ Passed 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 missin…
Full details: Description check

Explanation

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.

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 2
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch

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

Comment @coderabbitai help to get the list of available commands.

@nwparker
nwparker merged commit 99d9111 into main Sep 2, 2026
44 of 61 checks passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant