Repository navigation
Conversation
Retained state on the SSH stream path was unbounded in three places. Stream assembly and pre-metadata buffering - `ssh-stream-reader-memory.ts` adds two shared budgets: an aggregate assembly ceiling (128 MiB across all in-flight streams) and a pre-metadata frame budget (256 frames / 32 MiB). Every reader sees all stream frames and cannot filter by streamId until its own sentinel resolves, so a foreign flood previously grew unbounded while a reader waited. - The per-frame oversize check is load-bearing beyond memory: without it the eviction loop can never satisfy its exit condition on an empty buffer and spins forever. Covered by test. - Assembly is split into `ssh-file-stream-assembler.ts` and `ssh-git-response-stream-assembler.ts`, both reserving from the shared budget and releasing on every terminal path. - Git response stream markers are validated against client-side byte and chunk ceilings before allocation, so a relay-advertised size cannot force the allocation directly. Frame decoder - An oversized frame header is now answered by retaining only the 13-byte header and stream-discarding the advertised payload, so a malicious length field cannot pin up to 4 GiB waiting for bytes that never arrive. - Adversarially tiny transport fragments are coalesced pairwise, bounding the chunk-wrapper array without copying ordinary chunks. - Frame encode/decode route through the bounded stringify and parse helpers. Multiplexer dispose - Dispose handlers unsubscribe themselves while running, so iterating the live array skipped every other handler and stranded the assembly budget of half the in-flight streams. Detach before dispatch. WSL hook fs bridge - The bridge and its host adapter now pass and enforce the directory-entry and read-byte ceilings the shared contract already declared, so a listing of an arbitrarily large guest directory is refused at the source rather than serialized into a multi-megabyte frame. All new bounds are mutation-tested: reverting each one fails at least one test. Co-authored-by: Orca <[email protected]>
nwparker
force-pushed
the
oom-slice-5-ssh-pty
branch
from
July 27, 2026 06:20
4f7d675 to
2d70a4a
Compare
nwparker
force-pushed
the
oom-slice-6-stream-ingress
branch
from
July 27, 2026 06:20
cd04b1d to
ab04617
Compare
Collaborator
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.
Slice 6 of the re-landed OOM work. Base is
oom-slice-5-ssh-pty(#10839) — review only the top commit.ELI5
Two computers talk over a single SSH pipe. A file transfer arrives as a stream of numbered chunks, and the receiver has to hold them until the last one lands. Nothing capped how much it would hold, and nothing capped how many other people's chunks it would hold while waiting for its own. A slow or hostile peer could make the receiver hold everything until it ran out of memory.
What changed
Stream assembly (
ssh-stream-reader-memory.ts)streamIduntil its own sentinel resolves, so a foreign flood previously grew unbounded while a reader waited.ssh-file-stream-assembler.tsandssh-git-response-stream-assembler.ts.Frame decoder (
relay-protocol.ts)Multiplexer dispose (
ssh-channel-multiplexer.ts)WSL hook fs bridge
Proof the OOM fix works
Every new bound was mutation-tested — the bound was removed and the suite re-run. All six fail at least one test:
The per-frame oversize check turned out to be load-bearing beyond memory: without it the eviction loop can never satisfy its exit condition on an empty buffer and spins forever. That's now covered.
Note on the JSON structure scan
An earlier revision of this PR also carried a fix for a quadratic escape-dense
scan in
assertJsonTextStructureWithinLimits. That scan was introduced by thechar-code rewrite in slice 3 (#10874), so the fix has been folded into that
commit instead — the regression now never exists at any point in the stack, and
this slice is the first code to feed the scanner multi-megabyte frames rather
than the place the bug originated. See #10874 for the benchmark and the
505,720-case differential evidence.
Proof of zero regressions
src/main+src/relay+src/shared— 19,699 passed. Re-verified after the rebase:src/main/ssh+src/main/providers+src/main/agent-hooks+src/shared/memory-safety— 2,144 passed, 0 failed.agent-exec-handler(2) fails identically on the base branch;omp-shell-wrapperandrun-electron-vite-devpass in isolation on this branch across repeated runs and are flaky only under full-suite parallelism.tsconfig.node); the 6tsconfig.weberrors reproduce identically on cleanorigin/main. Lint at the repo baseline of 27 warnings / 0 errors.User-facing behavior changes
None expected. Two deliberate changes worth naming:
One error message changed: an incomplete file stream now reports
File stream N incomplete: chunks x/y, bytes a/b(wasChunk count mismatch), which names both the chunk and byte shortfall. The assertion was updated accordingly.Made with Orca 🐋