Repository navigation
fix(runtime): cap remote git.diff and file previews at the transport budget - #14160
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (29)
🚧 Files skipped from review as they are similar to previous changes (28)
📝 WalkthroughWalkthroughThe changes add JSON-aware transport budgets for Git diffs and file previews. Runtime Git commands and remote RPC handlers enforce these budgets while local callers remain uncapped without a limit. File preview reads apply binary and text limits across local and SSH paths, including base64 and serialized-result sizing. Structured 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/main/runtime/rpc/e2ee-channel-text-backpressure.test.ts (1)
123-126: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd a size-path telemetry assertion.
The new assertion covers only
emitter: 'queue'. Add an oversized legacy or V2 reply case and assertemitter: 'size'. This verifies the channel wiring insrc/main/runtime/rpc/e2ee-channel.ts; the schema test only verifies that the value is accepted.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 7becc225-9b27-4781-9aeb-7f37f6834212
📒 Files selected for processing (16)
mobile/src/files/mobile-file-tab-doc.test.tssrc/main/runtime/orca-runtime-files.test.tssrc/main/runtime/orca-runtime-files.tssrc/main/runtime/orca-runtime-git-diff-budget.test.tssrc/main/runtime/orca-runtime-git.tssrc/main/runtime/rpc/e2ee-channel-text-backpressure.test.tssrc/main/runtime/rpc/e2ee-channel.tssrc/main/runtime/rpc/errors.tssrc/main/runtime/rpc/methods/git-diff-transport-budget.test.tssrc/main/runtime/rpc/methods/git.test.tssrc/main/runtime/rpc/methods/git.tssrc/main/runtime/runtime-rpc.test.tssrc/shared/git-diff-transport-budget.test.tssrc/shared/git-diff-transport-budget.tssrc/shared/telemetry-events.test.tssrc/shared/telemetry-events.ts
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/main/runtime/rpc/methods/files-preview-transport-budget.test.ts (1)
13-61: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winCover the
runtimeclient kind.This test only dispatches with
clientKind: 'mobile'. Parameterize it formobileandruntimeso a regression that caps only mobile previews fails.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 5c6d4115-9819-499a-a828-6fcbce389f2f
📒 Files selected for processing (23)
mobile/src/session/mobile-diff-review-loaders.test.tsmobile/src/session/mobile-diff-review-loaders.tssrc/main/providers/filesystem-provider-contract.tssrc/main/providers/ssh-filesystem-provider-stream.test.tssrc/main/providers/ssh-filesystem-provider.tssrc/main/providers/types.tssrc/main/runtime/orca-runtime-files.test.tssrc/main/runtime/orca-runtime-files.tssrc/main/runtime/orca-runtime-git-diff-budget.test.tssrc/main/runtime/orca-runtime.test.tssrc/main/runtime/rpc/e2ee-channel-text-backpressure.test.tssrc/main/runtime/rpc/e2ee-channel.tssrc/main/runtime/rpc/methods/files-preview-transport-budget.test.tssrc/main/runtime/rpc/methods/files.tssrc/main/runtime/rpc/methods/git-diff-transport-budget.test.tssrc/main/runtime/rpc/methods/git.tssrc/main/runtime/runtime-rpc.test.tssrc/main/ssh/ssh-file-stream-read-cap.tssrc/main/ssh/ssh-filesystem-stream-reader.tssrc/shared/git-diff-transport-budget.test.tssrc/shared/git-diff-transport-budget.tssrc/shared/remote-rpc-content-budget.test.tssrc/shared/remote-rpc-content-budget.ts
🚧 Files skipped from review as they are similar to previous changes (6)
- src/main/runtime/orca-runtime-git-diff-budget.test.ts
- src/shared/git-diff-transport-budget.test.ts
- src/main/runtime/rpc/methods/git-diff-transport-budget.test.ts
- src/main/runtime/rpc/methods/git.ts
- src/main/runtime/rpc/e2ee-channel.ts
- src/main/runtime/runtime-rpc.test.ts
|
@coderabbitai review |
|
…budget A remote or mobile user who opens the diff of a large image loses their whole WebSocket, not just that request: the E2EE channel closes with 1013 when a reply exceeds the 4 MiB outbound envelope. Two producers can exceed it unaided. git.diff/branchDiff/commitDiff cap text with MAX_RENDERED_DIFF_COMBINED_CHARACTERS (6M chars) -- a *renderer* budget that sits above the transport limit -- and return base64 for previewable binaries bounded only by MAX_GIT_SHOW_BYTES, so a 10 MiB PNG changed in place is ~26.7 MiB in one envelope. files.readPreview inlines base64 up to 10 MiB, and mobile calls it for every image tab. Both now measure against a budget derived from the outbound limit. The check sits in orca-runtime-git.ts, downstream of the dedupe and of both the SSH-provider and local branches, so a payload forwarded verbatim by an old relay is covered by the same code and src/relay needs no change. Local and in-process callers pass no budget and keep full fidelity. Measuring raw bytes would not work, which is the whole reason this needs a module. JSON escaping turns one control byte into six (\u00XX), and binary-buffer.ts sniffs only for NUL in the first 8 KiB -- so a NUL-free file of 0x01-0x1f bytes is classified as *text*, would pass a raw-byte cap, and would then blow the envelope. The budget is escape-aware, with a three-branch fast path that keeps normal diffs at two native byteLength calls and scans only the ambiguous band. The SSH branch of readFileExplorerPreview had the same raw-vs-escaped gap: its stat gate sizes base64 binaries, but text crossed unbounded. It now honours the same decoded-text limit the local branch already enforced. No wire change: GitDiffResult is untouched -- no third kind, no new field. Old clients see an error for one request instead of a dropped connection. diff_too_large joins the structured passthrough codes and lands on an existing error arm in both mobile consumers and the desktop remote path; file_too_large was already handled on both. Instruments the 1013 close, which nothing measured before, so the incidence this cap is meant to drive to zero is finally observable. `emitter` separates a producer size bug from a wedged link. Known regression: remote image previews between ~3.096 and ~3.146 MB now return file_too_large. They only intermittently worked before -- above ~3.0 MB they killed the socket -- so this trades intermittent connection loss for a consistent error. Test: 10281 passed in src/main/runtime + src/shared + src/main/git; mobile 3427 passed. Each of the six budget-enforcement sites is independently mutation-killed. Escaping fixtures cover newline-dense, control-char, CJK, lone-surrogate and base64 content against native JSON.stringify. tsc clean for node, web and cli; oxlint clean. Co-authored-by: Orca <[email protected]>
…emoval Upstream #14447 dropped the shared/types barrel; GitDiffResult now lives in git-diff-compare-types and GlobalSettings in global-settings-types. Co-authored-by: Orca <[email protected]>
c620ddc to
55e7922
Compare
|
Note GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer. |
The stream reader aborts an over-cap read with StreamProtocolError, whose numeric code falls through mapRuntimeError to a generic runtime_error carrying the raw "Reported totalSize N exceeds client cap M" string. Neither preview client recognizes that: runtime-file-client.ts and mobile-file-preview-response.ts both key on file_too_large. It also made the two file_too_large guards directly below the read unreachable on the streaming path. Gives the cap its own error type so the caller can translate it, keeping the bandwidth saving the cap exists for. A genuine protocol fault still propagates unmasked. Found by the readiness review. Mutation-verified: removing the translation fails exactly the new test. Co-authored-by: Orca <[email protected]>
requestGitStreamable trusted the relay's declared size: every chunk was pushed into `parts`, then Buffer.concat'd and JSON.parse'd with no ceiling. A buggy or hostile relay could name any totalBytes and the host would allocate it. The file path already had this gate — ssh-filesystem-stream-reader checks the declared totalSize against a cap before accepting a stream. #14160 added a read cap for files only; this closes the same hole for git. Rejects at the marker, before a single chunk transfers, and cancels the stream so the relay stops sending instead of us draining a payload we already refused. The cap is 32 MiB, above anything a legitimate diff can produce: the relay caps each git exec at MAX_GIT_BUFFER (10 MiB), so two blobs base64-inflated top out near 27 MiB. So no diff that works today starts failing. Test: mutation-verified — disabling the gate hangs the over-cap case until the inactivity timeout instead of rejecting. 7471 tests pass across ssh, providers, runtime and relay; node and cli typechecks clean. Co-authored-by: Orca <[email protected]>
When a diff RPC fails, useEditorPanelContentState fabricates a result whose
modifiedContent is \`Error loading diff: \${err}\` so the pane has something to
show. For an unstaged diff that pane is editable, so Cmd+S calls onSave with the
editor body — and attemptEditorFileSave falls back to that body when no draft
exists (editor-autosave-controller). The error sentence gets written over the
user's file.
Reachable from any diff-load failure: SSH drop, git error, permission denied, or
the diff_too_large introduced in #14160.
The existing largeDiffSaveContentAvailable guard does not cover this. It only
gates the LargeDiffFallback button, which renders when largeDiffRenderLimit is
limited; on the error path that field is absent, so the full editable DiffEditor
mounts and installs the save shortcut instead.
Marks the fabricated result and holds the pane read-only, which blocks the save
shortcut and prevents a draft being minted — a draft would otherwise be saveable
even with onSave gated. loadError mirrors the field FileContent already carries
for the plain-file path, and lives on the renderer-local DiffContent, so nothing
on the wire changes.
Test: mutation-verified — dropping the guard fails exactly the new read-only
case. 23094 renderer tests pass; web and node typechecks clean.
Co-authored-by: Orca <[email protected]>
…budget (stablyai#14160) * fix(runtime): cap remote git.diff and file previews at the transport budget A remote or mobile user who opens the diff of a large image loses their whole WebSocket, not just that request: the E2EE channel closes with 1013 when a reply exceeds the 4 MiB outbound envelope. Two producers can exceed it unaided. git.diff/branchDiff/commitDiff cap text with MAX_RENDERED_DIFF_COMBINED_CHARACTERS (6M chars) -- a *renderer* budget that sits above the transport limit -- and return base64 for previewable binaries bounded only by MAX_GIT_SHOW_BYTES, so a 10 MiB PNG changed in place is ~26.7 MiB in one envelope. files.readPreview inlines base64 up to 10 MiB, and mobile calls it for every image tab. Both now measure against a budget derived from the outbound limit. The check sits in orca-runtime-git.ts, downstream of the dedupe and of both the SSH-provider and local branches, so a payload forwarded verbatim by an old relay is covered by the same code and src/relay needs no change. Local and in-process callers pass no budget and keep full fidelity. Measuring raw bytes would not work, which is the whole reason this needs a module. JSON escaping turns one control byte into six (\u00XX), and binary-buffer.ts sniffs only for NUL in the first 8 KiB -- so a NUL-free file of 0x01-0x1f bytes is classified as *text*, would pass a raw-byte cap, and would then blow the envelope. The budget is escape-aware, with a three-branch fast path that keeps normal diffs at two native byteLength calls and scans only the ambiguous band. The SSH branch of readFileExplorerPreview had the same raw-vs-escaped gap: its stat gate sizes base64 binaries, but text crossed unbounded. It now honours the same decoded-text limit the local branch already enforced. No wire change: GitDiffResult is untouched -- no third kind, no new field. Old clients see an error for one request instead of a dropped connection. diff_too_large joins the structured passthrough codes and lands on an existing error arm in both mobile consumers and the desktop remote path; file_too_large was already handled on both. Instruments the 1013 close, which nothing measured before, so the incidence this cap is meant to drive to zero is finally observable. `emitter` separates a producer size bug from a wedged link. Known regression: remote image previews between ~3.096 and ~3.146 MB now return file_too_large. They only intermittently worked before -- above ~3.0 MB they killed the socket -- so this trades intermittent connection loss for a consistent error. Test: 10281 passed in src/main/runtime + src/shared + src/main/git; mobile 3427 passed. Each of the six budget-enforcement sites is independently mutation-killed. Escaping fixtures cover newline-dense, control-char, CJK, lone-surrogate and base64 content against native JSON.stringify. tsc clean for node, web and cli; oxlint clean. Co-authored-by: Orca <[email protected]> * fix(runtime): harden remote reply transport budgets * test(runtime): cover desktop remote preview budgets * test(runtime): close telemetry review gaps * chore(shared): repoint budget imports after the shared/types barrel removal Upstream stablyai#14447 dropped the shared/types barrel; GitDiffResult now lives in git-diff-compare-types and GlobalSettings in global-settings-types. Co-authored-by: Orca <[email protected]> * fix(ssh): surface an over-cap preview read as file_too_large The stream reader aborts an over-cap read with StreamProtocolError, whose numeric code falls through mapRuntimeError to a generic runtime_error carrying the raw "Reported totalSize N exceeds client cap M" string. Neither preview client recognizes that: runtime-file-client.ts and mobile-file-preview-response.ts both key on file_too_large. It also made the two file_too_large guards directly below the read unreachable on the streaming path. Gives the cap its own error type so the caller can translate it, keeping the bandwidth saving the cap exists for. A genuine protocol fault still propagates unmasked. Found by the readiness review. Mutation-verified: removing the translation fails exactly the new test. Co-authored-by: Orca <[email protected]> --------- Co-authored-by: Orca <[email protected]>
The bug
A remote or mobile user who opens the diff of a large image loses their whole WebSocket, not just that request. The E2EE channel closes with
1013when a reply exceeds the 4 MiB outbound envelope, and two producers can exceed it unaided — no adversary required.git.difftextMAX_RENDERED_DIFF_COMBINED_CHARACTERS= 6M charsgit.diffpreviewable binaryMAX_GIT_SHOW_BYTES= 10 MiB per sidefiles.readPreviewRUNTIME_PREVIEWABLE_BINARY_MAX_BYTES= 10 MiBThe text cap is a renderer budget picked for render cost, and it sits above the transport limit. Contrast
files.read, which caps at 512 KiB and returns{content, truncated, byteLength}—git.diffhad no equivalent and no mobile payload diet.The fix
Cap the producers. The check lives in
orca-runtime-git.ts, downstream of the dedupe and of both the SSH-provider and local branches — so a payload forwarded verbatim by an old relay is covered by the same code andsrc/relay/needs no change. Local and in-process callers pass no budget and keep full fidelity; desktop-local diffs are untouched.Measuring raw bytes would not work, which is the whole reason this needs a module rather than a constant:
\u00XX), so worst-case expansion is 6x, not 2x.binary-buffer.tssniffs only for NUL in the first 8 KiB — so a NUL-free file of0x01–0x1fbytes is classified as text, sails through a raw-byte cap, and then blows the envelope. That is the exact1013this PR exists to prevent.The budget is escape-aware, with a three-branch fast path:
raw * 6 <= budget→ admit,raw > budget→ reject, otherwise run the exact scan. Normal diffs cost two nativebyteLengthcalls.Measurements are cached by result identity. This matters for SSH: up to 256 waiters can share one deduped result, and each now reuses its raw or exact measurement rather than synchronously rescanning a multi-megabyte string. The cache revalidates the serialized non-content skeleton and content values, and only stores a complete exact length.
The SSH branch of
readFileExplorerPreviewhad the same raw-vs-escaped gap — its stat gate sizes base64 binaries, but text crossed unbounded. It now honours the same decoded-text limit the local branch already enforced. Local and SSH preview reads are bounded through file growth, and SSH stream allocation honours the caller-specific binary/text cap.Wire compatibility
No wire change.
GitDiffResultis untouched — no thirdkind, no new optional field, nothing changed about what the host publishes on success.diff_too_largejoinsSTRUCTURED_RUNTIME_PASSTHROUGH_CODESand arrives on the existing failure envelope:mobile-diff-review-loaders.tsdiff_too_largeto the existing too-large review state, including deleted filesmobile-file-tab-doc.tsresponse.error.message→ existing error docA blanked success payload was considered and rejected:
mobile-diff-review-rpc.tsreconstructs from{kind, originalContent, modifiedContent}and dropslargeDiffRenderLimit, so it would render a silently empty diff; a blankedkind:'binary'would render "Text diff is unavailable for this file" — a false statement about a PNG.Telemetry
The 1013 close was never instrumented, so its incidence has been unmeasurable — this cap had no acceptance signal. One
.strict()schema, one helper over the six emitters.emitterissize(a producer emitted something too big; should fall to zero once producers cap themselves) orqueue(a backed-up link). No paths, no user content.Known regression
Remote image previews between ~3.096 MB and ~3.146 MB now return
file_too_large. They only intermittently worked before — above ~3.0 MB they killed the socket — so this trades intermittent connection loss for a consistent, explained error.file_too_largeis already a handled outcome on both clients.Testing
src/main/runtime+src/shared+src/main/git; mobile 3,429 passed / 3 skipped across 437 files.0x01control chars, CJK, lone surrogates, surrogate pairs, quotes/backslashes, base64) checked against nativeJSON.stringifyat the boundary and one byte past it. The envelope-ceiling invariant is asserted on text fixtures, not just base64 — a base64-only version passes trivially and proves nothing.JSON.stringify; all matched. A 256-waiter deduped SSH repro improved from 62.9–108 ms to 0.58–1.81 ms warmed.tsc,oxlint, changed-code quality, max-lines, reliability, and PR-fileoxfmtgates are clean.Scope
The final reviewed diff is 29 files, +1,556/−117, including the focused regression tests and extracted budget/read-cap modules. It does not change the RPC wire schema, add an opcode, alter persisted state, add dependencies, or touch UI. Two earlier drafts added a per-request overflow envelope; that machinery was dropped in favor of producer-side caps.
Out of scope, with reasons:
git.diffBinaryChunkRPC is the right shape if this is ever wanted, and needs no negotiation — this PR is a prerequisite either way.MAX_RENDERED_DIFF_COMBINED_CHARACTERS. Tempting one-liner, but it counts UTF-16 units, so a CJK diff at the cap is still ~18 MiB of UTF-8, and it does nothing for the base64 path.injectDeviceScopere-serializingstatus.get. All narrow; the new telemetry will show whether any fire.Made with Orca 🐋