Skip to content

fix(ssh): refuse a migration request too large for the host's sealed frame before sending it - #30249

Merged
nwparker merged 1 commit into
mainfrom
nwparker/r2-s10-wire-byte-budgets
Oct 18, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/r2-s10-wire-byte-budgets

Conversation

@nwparker

@nwparker nwparker commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​133 $\color{#cf222e}{\Huge{\mathbf{−}}}$​4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​129
Prod 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​31 $\color{#cf222e}{\Huge{\mathbf{−}}}$​4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​27

ELI5

When Orca moves an SSH host's saved projects onto its Orca server, it sends one big description of everything (the "manifest"). The server only accepts messages up to 1 MiB, and encryption makes a message about a third bigger. So a manifest that passed Orca's own size check could still be too big once encrypted. The server would then hang up mid-move and the user got an unclear failure. Orca now measures the encrypted size first and, if it won't fit, shows the existing "too large to move" message without sending anything.

What Changed

  • Which direction, which cap. The manifest travels client to host, as the params of orcad.migration.stageCatalog, commitCatalog, catalogState and abortCatalog, sent from the desktop's orcad-migration-catalog-client. The cap that applies is the host's inbound WebSocket frame cap, REMOTE_RUNTIME_MAX_INBOUND_FRAME_BYTES (1 MiB, ws-transport.ts maxPayload). It has been the same in every released host. Paired requests are sealed:
    • legacy: base64 of nonce + MAC + JSON;
    • v2: base64 of nonce + MAC + 42-byte header + JSON.
  • Why it overflowed. The manifest's own validation cap is 768 KiB (MAX_ORCAD_MIGRATION_MANIFEST_BYTES). 768 KiB × 4/3 is exactly 1 MiB before the envelope, so a manifest near its cap overflowed the frame. A commitCatalog that also carries expectedBlobs (one descriptor per shell history and agent session moved) overflowed sooner.
  • The fix.
    • src/shared/remote-runtime-memory-limits.ts (the existing shared cap module, next to the frame cap it derives from) adds REMOTE_RUNTIME_MAX_INBOUND_REQUEST_JSON_BYTES: the largest request JSON that still fits the frame once sealed, ⌊1 MiB / 4⌋ × 3 − 128.
    • orcad-migration-catalog-client.ts measures the exact params it is about to send against that budget, less a 1 KiB envelope reserve. It refuses before any request, including the status preflight, using the existing describeOversizedOrcadMigrationPayload message, which ends in (orcad_migration_manifest_too_large). That function now takes the limit to name.
  • Tests. The quick-commands test that computed the same budget by hand now uses the constant.

Why

  • Exact check instead of a fixed target. The proposal suggested a fixed 720 KiB producer target for the manifest. Refusing manifests at a fixed 720 KiB would newly fail moves between 720 and 768 KiB that work today, because there is no shedding yet. Measuring the actual request refuses only what the host would definitely reject, and it also catches the blob-list case that a fixed target misses.
  • Consumer caps unchanged. The 768 KiB validation cap and the 1 MiB frame cap stay as they are (never lowered), so mixed-version peers see no wire change: an oversized request simply isn't sent.
  • No new budget module. I didn't add a separate wire-byte-budgets.ts, because remote-runtime-memory-limits.ts already owns these caps and a second module would duplicate it.

Linked Issue

N/A. SSH hardening round 2, slice S10 (C4: a producer doesn't know the consumer's cap). Follows #30126.

Visual Proof

N/A: no UI change. The refusal reuses the existing "too large to move" message.

Testing

  • New orcad-migration-catalog-client-frame-budget.test.ts covers three cases:

    • a 760 KiB manifest stages;
    • a manifest at the 768 KiB validation cap is refused unsent;
    • a 760 KiB manifest plus a 200-blob commit is refused unsent.

    With the guard disabled, the two refusal tests fail.

  • remote-runtime-memory-limits.test.ts seals a request at the new budget with the real legacy and v2 framings, and asserts both fit 1 MiB.

  • src/main/ssh/orcad-migration*, orcad-runtime-conversion*, ssh-target-orcad-preflight*, src/shared/remote-runtime* and src/shared/orcad-migration* pass single-worker: 60 files, 502 tests.

  • Ran the full local "static analysis and typecheck" job: clean.

  • Codex review (gpt-6.1-sol, high): clean, two rounds (the second on the head after a test typing fix).

  • Not verified live: reaching the band needs a host with about 760 KiB of saved state. The unit test drives the client with the real sizes.

…frame before sending it

A manifest under the 768 KiB validation cap can still overflow the host's 1 MiB inbound
frame once sealed (base64 adds a third), more so when a commit carries its blob list. The
host answers such a frame by closing the socket, so the move failed with a lost answer.
The catalog client now measures the request against REMOTE_RUNTIME_MAX_INBOUND_REQUEST_JSON_BYTES
and refuses it with the existing 'too large' guidance, unsent.
@coderabbitai

coderabbitai Bot commented Oct 18, 2026

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: d8b08b4b-dbbc-457b-b1e5-41693f9cb596
📥 Commits

Reviewing files that changed from the base of the PR and between 9c726af and d147852.

📒 Files selected for processing: 6
  • src/main/persistence/applying-settings/settings-update-terminal-quick-commands.test.ts
  • src/main/ssh/orcad-migration-catalog-client-frame-budget.test.ts
  • src/main/ssh/orcad-migration-catalog-client.ts
  • src/main/ssh/orcad-migration-manifest-export.ts
  • src/shared/remote-runtime-memory-limits.test.ts
  • src/shared/remote-runtime-memory-limits.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.

📝 Walkthrough

The changes add a shared maximum inbound request JSON size derived from the inbound frame limit. Orcad migration requests are measured against that limit with a framing reserve and rejected when they exceed it. The oversized-payload description now accepts a byte limit. Tests check frame sizing for both encryption framings, Orcad staging and commit request sizes, and quick-command sizing.

Priority: ➖ Normal

Merge Risk: ⚪ Minimal · up to d1478

No confirmed issue blocks merging. The request-envelope size remains unverified, so the frame-limit check should be monitored when live host behavior is tested.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 6 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly identifies the main change: refusing oversized SSH migration requests before sending them. It is concise and specific.
Description check Passed The description is detailed and covers the user impact, implementation, rationale, testing, and lack of UI changes. It does not provide an actual linked issue and omits the template checklist and revi…
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.
Full details: Description check

Explanation

The description is detailed and covers the user impact, implementation, rationale, testing, and lack of UI changes. It does not provide an actual linked issue and omits the template checklist and review sections, but the core description is complete.

  • Fix all pre-merge checks with AI
✨ Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
  • 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

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

@nwparker
nwparker merged commit 8f86ccf into main Oct 18, 2026
59 checks passed
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