Repository navigation
Conversation
Three unbounded remote-filesystem paths, all reachable by browsing or downloading a large directory over SSH. Directory listing - `readDir` now calls the relay's bounded `fs.readDirBounded` and validates the response against the same ceilings it asked for, so a relay that ignores the limits cannot hand back an arbitrarily large listing. - An older relay without the bounded method is refused with a reconnect prompt rather than falling back, since the fallback is exactly the unbounded enumeration this removes. SFTP enumeration - `readDirViaSftp` materialized an entire directory before returning. `readDirectoryEntriesViaSftp` is an async generator over `opendir`/`readdir` chunks, so a caller that stops early -- at a budget ceiling, or on cancel -- never holds the whole listing. The handle is closed on every exit path. Folder transfer budget - `SshDirectoryTransferBudget` bounds entries, depth, per-path bytes, retained path bytes, per-file bytes, and total file bytes for recursive transfers. - Upload and download get separate limit sets. Uploads build an in-memory package, so 4,096 entries / 32 MiB total is right. Downloads stream each file to disk and hold one directory's entries at a time, so that ceiling would reject an ordinary checkout containing node_modules; downloads get a 1,000,000-entry whole-tree backstop while keeping the depth and per-path guards. Every bound is mutation-tested -- removing any one of the nine fails at least one test, including the download/upload limit-set choice and the streaming generator itself. Co-authored-by: Orca <[email protected]>
The 48 MiB package ceiling and the directory transfer budget were both landed without the code that uses them, so neither bound anything: a Windows folder upload still walked the tree with readdir, buffered every entry, and serialized the whole package with an unbounded JSON.stringify. Charge the budget while collecting entries, stream the directory with opendir instead of materializing one array, and serialize through the bounded stringifier so an oversized package fails before it is built.
The upload package tests exercised the budget class and the bounded serializer
directly, so deleting the wiring in collectWindowsUploadEntries left the suite
green around a ceiling that no longer applied. They now call
uploadDirectoryViaSystemSsh with real on-disk fixtures.
Also reports an oversized package as SshDirectoryTransferCapacityError('package')
instead of leaking the raw JSON limit error, so every capacity rejection carries
the typed reason the failure path advertises.
Co-authored-by: Orca <[email protected]>
6 of 9 tasks
8 of 9 tasks
Collaborator
|
Closing: the relay-backed SSH filesystem provider was removed with the SSH relay (#27214/#27215). Remote directory listings now go through the managed server's |
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 7 of the re-landed OOM work. Base is
oom-slice-6-stream-ingress(#10854) — review only the top commit.ELI5
When you browse a remote folder over SSH, the app used to ask for everything in it and hold the whole answer in memory. On a folder with a million files —
node_modules, a build output directory, a log dump — that answer alone can be hundreds of megabytes, and it arrives before anyone checks how big it is.Same story for downloading a folder: the code walked the whole tree, collected every path first, and only then started transferring.
Now listings are capped and checked, the walk streams entries a chunk at a time instead of collecting them, and folder transfers run against an explicit budget.
What changed
Directory listing (
ssh-filesystem-directory-reader.ts)readDirroutes through the relay's boundedfs.readDirBoundedand then validates the response against the same ceilings it requested. A relay that ignores the limits can't hand back an oversized listing and have it trusted.SFTP enumeration (
ssh-filesystem-provider-sftp.ts)readDirViaSftpmaterialized an entire directory before returning. It's nowreadDirectoryEntriesViaSftp, an async generator overopendir/readdirchunks, so a caller that stops early — at a budget ceiling, or on cancel — never holds the whole listing. The handle closes on every exit path.Folder transfer budget (
ssh-directory-transfer-budget.ts)Windows folder upload (
system-ssh-file-transfer.ts) — see the follow-up section; this is the code that actually applies the budget.Proof the OOM fix works
Every bound was mutation-tested: the bound is removed and the suite re-run. All nine fail at least one test.
maximumDepthmaximumEntriesmaximumPathBytesmaximumRetainedPathBytesmaximumTotalFileBytesWINDOWS_SSH_UPLOAD_PACKAGE_MAX_BYTESA coverage gap this found. The mobile listing path forwards its tighter limits to the relay, and a test asserted the request carried them — but nothing asserted the response was validated. Deleting
assertMobileFileDirectoryWithinLimitleft the suite fully green. That's vacuous coverage: the limit looked enforced because the request looked right. Addedvalidates bounded relay results on the mobile path too, which now fails when the assertion is removed.Follow-up: the budget had no caller
A later sweep for a specific defect class — a bound landed without the code that applies it — found one here, and it is worth stating plainly because it means part of this slice was previously inert.
WINDOWS_SSH_UPLOAD_PACKAGE_MAX_BYTES(48 MiB) andSshDirectoryTransferBudgetwere both defined and unit-tested, but nothing constructed the budget for a Windows folder upload. The constant had zero references outside its own definition. So on the actual upload path,collectWindowsUploadEntriesstill walked the tree withreaddir, base64'd every file into one array, and handed the result to a bareJSON.stringify— the exact unbounded accumulation this slice is meant to remove. The unit tests passed the whole time, because they exercised the budget class directly rather than the code that was supposed to use it.Fixed by wiring the consumer:
recordPathper directory and file,recordFileper file size, so depth/entries/path/total-bytes are enforced during collection instead of after.opendirwithfor awaitinstead ofreaddir, so a huge directory never materializes as one array. The handle closes on every exit path.stringifyJsonWithinByteLimit(entries, WINDOWS_SSH_UPLOAD_PACKAGE_MAX_BYTES)fails at the ceiling rather than building an arbitrarily large string.readFile, so a file growing mid-upload cannot expand an allocation the budget already accounted for. A short read or trailing bytes raise the existing "File changed during upload" error.A second pass found the tests themselves were vacuous at the call site. The added
tests imported
stringifyJsonWithinByteLimitand the budget class and called themdirectly — so they proved the ceiling arithmetic, but not that the upload path used it.
Deleting the wiring above (
new SshDirectoryTransferBudget(), therecordPath/recordFilecharges, the bounded serialize) left the suite fully green. That is the same defect class
this slice exists to close, one level up: a bound split from its call site, with a test
suite that can't tell.
The tests now drive
uploadDirectoryViaSystemSshagainst real on-disk fixtures. Everymutation of the wiring fails at least one test:
recordPath/recordFilechargesrecordPathchargeJSON.stringifyMAX_SAFE_INTEGERMAX_SAFE_INTEGEREach rejection is also asserted to happen before
spawn, so an oversized tree neverreaches an SSH process. The ceilings are asserted as literals
(
expect(SSH_DIRECTORY_TRANSFER_LIMITS.maximumEntries).toBe(4_096)) — sizing a fixturefrom the constant would pass at any value.
One assertion was itself vacuous on the first attempt: the serializer spy accumulated
calls from the direct-call tests earlier in the file, so the call-site assertion passed
even when the upload bypassed it. It now clears between tests, which is what makes the
JSON.stringifymutation fail.Typed failure for oversized packages.
stringifyJsonWithinByteLimitthrowsJsonStringifyByteLimitError, which is not anSshDirectoryTransferCapacityError— sothe one rejection most likely to be hit in practice escaped the typed contract the other
six advertise. It is now translated to
SshDirectoryTransferCapacityError('package').This matters because JSON escaping can outgrow the bytes charged during the walk: a
control character in a filename costs 1 byte against the path budget but 6 once escaped.
Generalized lesson: a slice must not split a bound from its call site. Landing the constant alone yields a test suite that is green and a memory ceiling that does nothing.
Two limit sets, deliberately
Uploads build an in-memory package, so 4,096 entries / 32 MiB total is the right ceiling. Downloads stream each file straight to disk and hold one directory's entries at a time, so their real cost is depth plus that directory's size — the upload ceiling would reject an ordinary checkout containing
node_modules.Downloads therefore get a 1,000,000-entry whole-tree backstop while keeping the depth, per-path, and per-file guards. The choice is asserted: swapping downloads to the tighter set fails 10 tests.
Proof of zero regressions
src/main/sshat the chain tip: 1,007 passed / 0 failed (65 files). Acrosssrc/main/ssh+src/main/providers+src/shared: 4,996 passed, 2 failures insrc/shared/setup-agent-sequencing.test.ts— load-sensitive, pass in isolation, and untouched by this slice.config/tsconfig.node.jsonandconfig/tsconfig.web.json.main.User-facing behavior changes
Three worth naming explicitly:
An SSH host running an older relay can no longer browse directories. It gets "Safe remote directory browsing requires an updated relay. Reconnect the SSH target before retrying." This is intentional — the alternative is retaining the unbounded enumeration this slice removes — but it is a real behavior change for anyone connected to a stale relay, and the fix (reconnect) is stated in the message. The probe happens once per provider, not per listing.
A directory exceeding the listing ceiling now fails with "This folder is too large to list safely" instead of loading. Previously it would load and could exhaust memory.
A Windows folder upload above the budget now fails instead of proceeding. This ceiling existed in the code before but was never applied, so this is the point at which it starts having an effect. The limits are 4,096 entries, depth 64, 16 KiB per path / 4 MiB retained, 16 MiB per file / 32 MiB total, plus a 48 MiB serialized package. The failure is a typed
SshDirectoryTransferCapacityErrornaming which limit was hit, and it is raised before any SSH process is spawned — not a silent truncation, so no file is dropped from a transfer that reports success. Uploading a folder large enough to hit this previously risked exhausting memory mid-transfer.Folder downloads of ordinary repositories are unaffected — that's what the separate download limit set is for.
Made with Orca 🐋