Skip to content

fix(ssh): chunk the large-file Windows upload too, and stop presenting a prefix as complete - #17934

Closed
nwparker wants to merge 0 commit into
fix/relay-payload-limitsfrom
fix/windows-upload-correction
Closed

nwparker wants to merge 0 commit into
fix/relay-payload-limitsfrom
fix/windows-upload-correction

Conversation

@nwparker

@nwparker nwparker commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​208 $\color{#cf222e}{\Huge{\mathbf{−}}}$​35 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​173
Prod 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​155 $\color{#cf222e}{\Huge{\mathbf{−}}}$​77 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​78

Stacked on #17870, which it corrects. Retarget to main once that merges.

An adversarial review found #17870's Windows third internally inconsistent: it blamed [Console]::In.ReadToEnd() materializing a giant string, but the construct it chunks — makeWindowsWriteFileCommand — uses OpenStandardInput() + CopyTo, a streaming copy. Meanwhile uploadFileViaSystemSsh, the path that carries the large files, piped whole files into that same command unchunked and untimed.

I expected the answer to be "chunking is pure cost, remove it". That was wrong, and the deciding evidence was already in #16432 — #17870 just read it wrong.

Chunking is right, and the large-file path was still wedged

The reporter's table has three rows. The third is the one that matters:

stdin consumer 9 B 50 KB 1 MB
[Console]::In.ReadToEnd() ok hangs hangs
StreamReader(OpenStandardInput()) — ok hangs

StreamReader(OpenStandardInput()) reads the same object CopyTo reads, the same way: a loop of Stream.Read into a byte buffer. Stream.CopyTo is that identical loop with an 81920-byte buffer, minus the text decode. It hangs at 1 MB. There is no property of CopyTo that escapes a limit an incremental Stream.Read loop on that stream already hits.

The same data also refutes #17870's stated mechanism: both measured constructs materialize, yet they diverge at 50 KB and converge at 1 MB. Materialization explains neither, and a 1.9 MB string does not hang .NET. The limit is in the stdin the Windows sshd hands PowerShell — consistent with the threshold moving when DefaultShell changes, which an inner script's allocation cannot explain.

Stated plainly: this is reasoning, not measurement. No CopyTo-on-Windows-PowerShell-5.1 number exists — mine or the reporter's. pwsh 7.4.2 on Linux confirmed only the structural claim (both expressions are the same stream object) before dying under qemu, and Linux pwsh 7 cannot speak to Windows PowerShell 5.1 + Windows sshd anyway. 32 KB is chosen to sit under the 50 KB the reporter measured a stream reader surviving on the worse DefaultShell. Only a real Windows host settles the actual threshold.

Changes

  • uploadFileViaSystemSsh now chunks on Windows. POSIX keeps its single streaming cat > pipeline, untouched and untimed. The Windows directory upload's separate chunker is deleted and now routes through the same path, which also gains it O_NOFOLLOW + ino/dev identity verification it never had (it only compared size).
  • Hazard: truncated file with no marker — real, fixed. A multi-exec write lands on <path>.orca-partial and is published by File::Move. A mid-file failure can no longer leave a truncated artifact under the real name. Single-chunk writes still go straight to the destination, so the common case costs no extra round trip.
  • Hazard: exclusive leaking into follow-on chunks — the leak was handled, the design around it was not. exclusive was smeared onto chunk 0 as CreateNew, so a retry after a mid-file failure met its own leftovers and failed on a file Orca itself wrote. exclusive is now enforced once, at the rename — File::Move throws on an existing destination, which is exactly the contract. append cannot be staged without reading the remote file back, so it still writes straight through.
  • The mkdir batch still used [Console]::In.ReadToEnd() under a 32 KB cap — unjustified, since that is the construct measured wedging at 50 KB with only 9 B known-good. Switched to the stream reader measured surviving 50 KB.
  • Every comment asserting the materialization mechanism is corrected.

Wire compat: a prefix is no longer presented as complete

New host, old client: the old client omits maxResults, the host truncates at 20,001, and the old renderer hardcodes truncated: false — a partial list shown as complete.

Simply not truncating reinstates #12547 (listFilesWithRg with maxResults: undefined is a genuinely unbounded Set; only a 25 s timeout bounds it). So the scan stays bounded, and a request that named no limit and hits the ceiling now fails with an explicit error rather than returning a prefix. That is the position this codebase already records at fs-list-files-fallback-chain.ts:72 — "the readdir walker rejects on cap/deadline instead of returning a partial list (design doc: silent truncation is worse than an explicit error)". Old clients render it through their existing error path.

Acknowledged trade: an old client on a 20k–200k-file remote workspace now sees an error where it previously got a large, slow, complete list. Above that it already failed as "Message too large". If you would rather old clients keep working to the transport ceiling, the alternative is a byte-budgeted ceiling (limitQuickOpenFilesBySerializedBytes already exists) that errors only where the frame genuinely cannot carry it — more code, non-regressive. Not built; this is a product call.

Verification

BEFORE  × writes files to Windows system SSH targets with PowerShell stdin bytes   30006ms
        × writes binary buffers to Windows system SSH targets with CreateNew mode  30002ms
        AssertionError: expected [] to have a length of 1 but got +0
AFTER   Test Files  4 passed (4)   Tests  76 passed (76)

typecheck:node clean; check:code-quality:changed 0 new findings across 20 files. Wider sweep: src/main/ssh + ipc/filesystem + the bounded-response test → 169 files / 2208 passed; src/relay → 153 files / 1560 passed.

Also repaired three pre-existing tests in ssh-system-fallback.test.ts that emitted close synchronously after the call and raced once the Windows write reads its source asynchronously.

What remains unverified

  1. The Windows measurement. 32 KB is inference from the adjacent StreamReader row. Could be too small (wasted round trips) or, less likely, still too large.
  2. Round-trip cost: ~32 execs/MB over a ControlMaster-multiplexed connection — ~46 chunk writes + 6 renames for the 1.44 MB relay bundle. Unmeasured against a real host; this is the price of the chunking being necessary. The reporter's own preferred fix — bsdtar, shipped in Windows since 10 1803 — would reuse the POSIX transport and cut the payload 4.8x, and remains the better answer. Untouched here.
  3. .orca-partial leftovers are deliberately not swept: they are the failure evidence, a retry truncates them via FileMode::Create, and the relay install probe is an allow-list plus a completion sentinel, so a stray partial cannot make an incomplete install read complete. Windows MAX_PATH headroom for the 13-char suffix on a deeply nested tree is unchecked.
  4. No CI coverage for the listFiles skew — tests/e2e/cross-version-wire/ does not cover file RPCs, so the new unit tests are the only record.

Refs #16432, #12547

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

Important

The uncapped-fs.listFiles guard does more than stop old clients: it also breaks current in-tree SSH callers that intentionally omit maxResults. The markdown document panel and the mobile file browser both request full listings over the relay and would now fail with "more than 20000 files" on large remote workspaces. See the inline comment for the specific call sites.

Reviewed changes

  • Windows uploads now chunk and stage — writeBufferViaSystemSsh and uploadFileViaSystemSsh route Windows writes through writeWindowsBytesViaSystemSsh, splitting every stdin into ≤32 KB chunks and landing multi-chunk creates on a .orca-partial path published by File::Move, which is where exclusive is now enforced exactly once.
  • Directory upload reuses the single-file uploader — uploadDirectoryViaSystemSshWindows drops its private chunker and calls uploadFileViaSystemSsh per file, gaining O_NOFOLLOW + ino/dev identity checks it previously lacked.
  • fs.listFiles refuses a prefix for uncapped callers — a request that names no maxResults and hits the 20,001 ceiling throws instead of returning a partial list that older renderers show as complete; the scan stays bounded either way.
  • Renderer reports truncation from page length — quick-open-file-list.ts now sets truncated: files.length >= QUICK_OPEN_LISTING_MAX_RESULTS instead of hardcoding false.

ℹ️ Nitpicks

  • The files.length >= maxResults boundary over-rejects a workspace with exactly QUICK_OPEN_LISTING_MAX_RESULTS (20,001) files: the listing is actually complete, yet the request throws and the renderer would report truncated: true. This is inherent to cap-based truncation detection, but worth being aware of.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

Comment thread src/relay/fs-handler.ts Outdated
// compatibility, rule 3). The verdict each caller gets is its own, so coalescing is unaffected.
// Failing here is the same choice the readdir walker already makes: silent truncation is worse
// than an explicit error.
if (requestedMaxResults === undefined && files.length >= maxResults) {

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.

This throw also hits current in-tree SSH callers that intentionally omit maxResults and apply their own limits client-side: the markdown document panel (listRuntimeMarkdownDocuments → provider.listFiles(rootPath)) and the mobile file browser (listMobileFiles → listRemoteMobileFiles(..., undefined)), plus fs:listMarkdownDocuments. On a remote workspace with more than 20,000 files those features now fail with this error instead of returning a list, and the markdown panel swallows it into an empty document list. The PR body only accounts for old clients, not these current ones.

Technical details
# Uncapped `fs.listFiles` throw reaches current in-tree SSH callers

## Affected sites
- src/main/runtime/runtime-file-commands-search-runtime-files.ts:81 — `listRuntimeMarkdownDocuments` calls `provider.listFiles(target.worktree.path)` with no `maxResults`
- src/main/ipc/filesystem/filesystem-read-handlers.ts:125 — `fs:listMarkdownDocuments` SSH path calls `provider.listFiles(args.rootPath)` with no `maxResults`
- src/main/runtime/runtime-file-commands-constructor.ts:41 — `listMobileFiles` → `listRemoteMobileFiles(..., undefined)` forwards `maxResults: undefined`

## Required outcome
- These current features must not hard-fail on >20,000-file remote workspaces: pass an explicit cap, or scope the throw to callers that genuinely cannot render truncation.

## Suggested approach (optional)
- Markdown: give `listRuntimeMarkdownDocuments` / `fs:listMarkdownDocuments` an explicit high `maxResults` with graceful degradation, or a dedicated bounded listing.
- Mobile: pass `maxResults: MOBILE_FILE_LIST_LIMIT + 1` from `listMobileFiles` and slice as it already does.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This throw also hits current in-tree SSH callers that intentionally omit maxResults … runtime-file-commands-search-runtime-files.ts:81, filesystem-read-handlers.ts:125, runtime-file-commands-constructor.ts:41

Confirmed and fixed by removing the throw entirely — not by giving those three callers a budget. Your finding is right, and #17954 (merged today, f737f3499f3) removed the premise underneath it.

What changed on main. The throw existed because the host had to choose between handing a caller an unannounced 20,001-row prefix and refusing. #17954 removed that fork: an oversized fs.listFiles reply is now streamed on the bulk lane via maybeStreamRpcResponse, and its own commit message says the quiet part out loud — "picking a ceiling to refuse at does not fix that, it just moves where it shows up and refuses listings that would have been delivered." So the host no longer needs a default cap at all.

What this branch does now. The rebased, squashed commit:

Your three call sites therefore keep main's behaviour — a full listing, streamed — rather than either a prefix or a hard failure. src/relay/fs-handler-list-files-bounded-response.test.ts is renamed to fs-handler-list-files-result-limit.test.ts and inverted: it now asserts an uncapped request is answered in full and that a named cap is honoured and clamped, so nothing can quietly re-add a host-side default.

Thanks — the call-site list is what made it obvious the throw had no honest caller behind it.

@nwparker

nwparker commented Sep 1, 2026

Copy link
Copy Markdown
Contributor Author

Measured on a real Windows host — the chunking is correctly placed, but the stated mechanism needs correcting

This PR reasoned from the .NET stream contract because no CopyTo-on-Windows measurement existed. I took one.

Host: Windows, PowerShell 5.1.26100.9168 — the exact version #16432 concerns.

$in = [Console]::OpenStandardInput()
$o  = [System.IO.File]::Open("C:/Users/neil/cpout.bin", 1, 2, 0)
try { $in.CopyTo($o) } finally { $o.Dispose() }

$ cat cpin.bin | powershell -NoProfile -ExecutionPolicy Bypass -File cp.ps1
COPIED=2097152
EXIT=0 SECS=0

2 MB streamed through [Console]::OpenStandardInput().CopyTo() in under a second, over a pipe.

What this changes

This PR argued that because StreamReader(OpenStandardInput()) reads the same object the same way and hangs at 1 MB, "there is no property of CopyTo that lets it out of a limit an incremental Stream.Read loop on that stream already hits."

That inference is wrong. CopyTo handles 2 MB fine on this host. The limit the reporter measured is therefore not in PowerShell or .NET — it is in Windows OpenSSH's exec-channel stdin plumbing specifically, which is the one layer my pipe test does not include and their test did.

What this does not change

The fix is still correctly placed and should land. Chunking is applied to the ssh upload path, which is exactly where the constraint actually lives. And this measurement independently supports the PR's other correction — that uploadFileViaSystemSsh piping whole files into that command unchunked and untimed was a real gap, since the constraint is the transport rather than the payload size.

What should change is the narrative: the mechanism is the sshd stdin channel, not CopyTo materialization or a .NET stream limit. Two of us have now attributed this to the wrong layer — #17870 blamed ReadToEnd materialization, and this PR blamed the Stream.Read loop. It is neither.

Still unmeasured

The actual ssh-path threshold. awin has no sshd, so I could not run the payload over a real Windows OpenSSH exec channel. 32 KB remains a conservative choice below the reporter's measured 50 KB StreamReader survival — safe, possibly smaller than necessary. The reporter's own preferred fix (bsdtar, shipped in Windows since 10 1803, reusing the POSIX transport and cutting the payload ~4.8x) remains the better long-term answer.

@nwparker

nwparker commented Sep 1, 2026

Copy link
Copy Markdown
Contributor Author

Blocker: the throw is reachable from two in-tree, same-version callers

Independent audit flagged this, and I verified the call sites. This PR's repair — throwing instead of silently returning a 20,001-entry prefix — is correct in principle, but two current in-tree callers omit maxResults entirely and would take the throw:

src/main/runtime/runtime-file-commands-search-runtime-files.ts:81
  const relativePaths = await provider.listFiles(target.worktree.path)

src/main/ipc/filesystem.ts:826
  const relativePaths = await provider.listFiles(args.rootPath)

Neither passes an options object at all. On any workspace at or over the scan limit, both now fail where they previously received a (silently truncated) list. That is not an old-client compatibility question — it is this build calling itself.

So the Rule 3 repair is right and the ergonomics are wrong: the honest error has no honest caller behind it yet. Either give those two call sites an explicit budget, or give listFiles a truncation signal so a bounded answer can be returned truthfully rather than thrown away.

That second option is the one worth taking, and it connects to the design discussion on #17954: the reply is a bare string[] with no truncation field, and clients infer truncation only from files.length >= maxResults. That missing signal is what forces the throw in the first place. Adding it makes clamping honest and removes the need to fail.

What this PR gets right, for the record

The audit confirmed the Rule 3 analysis in this PR's favour: #17870 alone silently returns a 20,001-entry prefix when the client asked for no cap, and clients predating maxResults hardcode truncated: false, so nothing old can notice. The frame shape is unchanged. This PR repairs that and cites the rule by name — which is why #17870 must not land without it.

Also cleared in the same audit, all safe: workspace.stale is a JSON-RPC notification rather than an opcode, so Rule 2 is not engaged and an old client drops it exactly as it dropped the oversized frame before; the workspace.changed broadcast → per-client loop is verified equivalent (notify() iterates the same set as activeClientIds(), same lane, same drop semantics); and withholding workspace.changed over producer capacity in favour of workspace.stale is an improvement over the previous silent drop.

nwparker added a commit that referenced this pull request Sep 2, 2026
…ncating

Three failures with one shape: a payload past a fixed capacity was met with
silence, with a wait that never ends, or with a prefix presented as a whole.

**The workspace snapshot was silently dropped.** `workspace.changed` carries the
tab/session list, and a snapshot past the producer frame capacity (12288 B on a
Node <=21 remote) was dropped with only a relay stderr line, so the client kept a
stale list forever. The relay now publishes per client and, for a client whose
sink refused the frame, sends a compact `workspace.stale` marker on the control
lane; the client re-reads through `workspace.get`, whose lane is budgeted in
megabytes rather than in one producer frame. A new JSON-RPC notification rather
than a new field on `workspace.changed`: `normalizeSnapshot(undefined, ns)` yields
revision 0 and an empty session, so a Rule-1 field would make an old client
replace its tab list with nothing — worse than the drop. An old client ignores the
unknown method and is exactly where it is today. The marker retention/retry
machinery is extracted from the `fs.changed` overflow path and shared by both.

**The Windows upload hung, and the fix for it could truncate.** `#16432` was
attributed to `[Console]::In.ReadToEnd()` materializing the base64 bundle. That is
not what the reporter measured: he also measured
`new IO.StreamReader([Console]::OpenStandardInput())` — an incremental reader —
hanging at 1 MB. The limit is in the stdin the host hands PowerShell over a
non-pty ssh exec, not in the string the script builds.

- `uploadFileViaSystemSsh` — the user file-import path — was piping a whole file
  into one Windows stdin, unchunked and untimed. That is the path large files
  take; it now chunks into 32 KB writes and bounds each wait.
- The Windows directory upload reuses that single-file path rather than repeating
  a weaker copy of chunk-read + write-buffer; the `ino`/`dev` TOCTOU verification
  comes with it.
- A Windows write needing more than one exec lands on a `.orca-partial` staging
  path and is published by rename, so a failed chunk cannot leave a truncated
  artifact under the real name. `exclusive` is enforced once at the rename, not on
  the first chunk, where a retry met its own leftovers.
- The mkdir batch reads stdin through the stream reader the reporter measured
  surviving 50 KB, not `[Console]::In`, which he measured wedging at that size.
- `waitForChannelClose` takes an optional bound. A wedged PowerShell stays alive
  at idle CPU and never closes, so without one the promise is simply never
  settled and the caller waits forever with no error to show.

**Quick Open showed a prefix as the whole workspace.** The mechanism "a full page
means there is more" only works if the caller named the cap, and the failing UI
named none — it hardcoded `truncated: false`. Quick Open now names
`QUICK_OPEN_LISTING_MAX_RESULTS` on both the Electron IPC hop and the runtime-RPC
hop (the field #17954 added to `files.listAll`), and reads a full page as
truncation. The local hop honours the cap too, which it previously ignored.

Rebase note on `fs.listFiles`: an earlier revision of this work also clamped the
host unconditionally, and #17934 escalated an uncapped request to an explicit
error. #17954 has since landed and made an oversized reply streamable, which
removes the premise — the host no longer has to choose between a prefix and a
refusal, so it returns the whole listing when no limit is named and only clamps a
limit it was given. Keeping either would have regressed #17954 and hard-failed
three in-tree callers that deliberately pass no options
(`runtime-file-commands-search-runtime-files.ts:81`,
`filesystem-read-handlers.ts:125`, `runtime-file-commands-constructor.ts:41`).
@nwparker
nwparker force-pushed the fix/relay-payload-limits branch from 48a097f to 6c93e03 Compare September 2, 2026 22:28
@nwparker nwparker closed this Sep 2, 2026
@nwparker
nwparker force-pushed the fix/windows-upload-correction branch from 5358082 to 6c93e03 Compare September 2, 2026 22:28
@nwparker

nwparker commented Sep 2, 2026

Copy link
Copy Markdown
Contributor Author

Folded into #17870 — this PR can be closed

The two were never separable: #17870 alone arms a 60 s write timeout on an unstaged chunked Windows upload, which converts a hang into a mid-file failure that leaves a truncated artifact under the real remote name. Reproduced by injecting a chunk failure into a 262144 B upload:

#17870 alone      remote: relay.js               size=98304 B   (no partial marker)
#17870 + this PR  remote: relay.js.orca-partial  size=98304 B   (no real-named file)

So both are now one squashed commit on fix/relay-payload-limits, rebased onto current main. This branch has been fast-forwarded to the same commit, so its diff against its base is empty.

One thing did not survive the rebase, deliberately: the uncapped-fs.listFiles throw. #17954 merged today and made an oversized reply streamable, which removes the fork the throw existed to resolve — the host no longer has to choose between a prefix and a refusal. Keeping the throw would have hard-failed three current in-tree callers that pass no options (runtime-file-commands-search-runtime-files.ts:81, filesystem-read-handlers.ts:125, runtime-file-commands-constructor.ts:41), which is the blocker pullfrog filed. Details in that thread.

Everything else from this PR — the corrected mechanism narrative, uploadFileViaSystemSsh chunking, .orca-partial staging with publish-by-rename, exclusive at the rename, the stream-reader mkdir batch, and the restored ino/dev TOCTOU check — is in the combined commit unchanged.

nwparker added a commit that referenced this pull request Sep 2, 2026
…ncating (#17870)

Three failures with one shape: a payload past a fixed capacity was met with
silence, with a wait that never ends, or with a prefix presented as a whole.

**The workspace snapshot was silently dropped.** `workspace.changed` carries the
tab/session list, and a snapshot past the producer frame capacity (12288 B on a
Node <=21 remote) was dropped with only a relay stderr line, so the client kept a
stale list forever. The relay now publishes per client and, for a client whose
sink refused the frame, sends a compact `workspace.stale` marker on the control
lane; the client re-reads through `workspace.get`, whose lane is budgeted in
megabytes rather than in one producer frame. A new JSON-RPC notification rather
than a new field on `workspace.changed`: `normalizeSnapshot(undefined, ns)` yields
revision 0 and an empty session, so a Rule-1 field would make an old client
replace its tab list with nothing — worse than the drop. An old client ignores the
unknown method and is exactly where it is today. The marker retention/retry
machinery is extracted from the `fs.changed` overflow path and shared by both.

**The Windows upload hung, and the fix for it could truncate.** `#16432` was
attributed to `[Console]::In.ReadToEnd()` materializing the base64 bundle. That is
not what the reporter measured: he also measured
`new IO.StreamReader([Console]::OpenStandardInput())` — an incremental reader —
hanging at 1 MB. The limit is in the stdin the host hands PowerShell over a
non-pty ssh exec, not in the string the script builds.

- `uploadFileViaSystemSsh` — the user file-import path — was piping a whole file
  into one Windows stdin, unchunked and untimed. That is the path large files
  take; it now chunks into 32 KB writes and bounds each wait.
- The Windows directory upload reuses that single-file path rather than repeating
  a weaker copy of chunk-read + write-buffer; the `ino`/`dev` TOCTOU verification
  comes with it.
- A Windows write needing more than one exec lands on a `.orca-partial` staging
  path and is published by rename, so a failed chunk cannot leave a truncated
  artifact under the real name. `exclusive` is enforced once at the rename, not on
  the first chunk, where a retry met its own leftovers.
- The mkdir batch reads stdin through the stream reader the reporter measured
  surviving 50 KB, not `[Console]::In`, which he measured wedging at that size.
- `waitForChannelClose` takes an optional bound. A wedged PowerShell stays alive
  at idle CPU and never closes, so without one the promise is simply never
  settled and the caller waits forever with no error to show.

**Quick Open showed a prefix as the whole workspace.** The mechanism "a full page
means there is more" only works if the caller named the cap, and the failing UI
named none — it hardcoded `truncated: false`. Quick Open now names
`QUICK_OPEN_LISTING_MAX_RESULTS` on both the Electron IPC hop and the runtime-RPC
hop (the field #17954 added to `files.listAll`), and reads a full page as
truncation. The local hop honours the cap too, which it previously ignored.

Rebase note on `fs.listFiles`: an earlier revision of this work also clamped the
host unconditionally, and #17934 escalated an uncapped request to an explicit
error. #17954 has since landed and made an oversized reply streamable, which
removes the premise — the host no longer has to choose between a prefix and a
refusal, so it returns the whole listing when no limit is named and only clamps a
limit it was given. Keeping either would have regressed #17954 and hard-failed
three in-tree callers that deliberately pass no options
(`runtime-file-commands-search-runtime-files.ts:81`,
`filesystem-read-handlers.ts:125`, `runtime-file-commands-constructor.ts:41`).
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…ncating (stablyai#17870)

Three failures with one shape: a payload past a fixed capacity was met with
silence, with a wait that never ends, or with a prefix presented as a whole.

**The workspace snapshot was silently dropped.** `workspace.changed` carries the
tab/session list, and a snapshot past the producer frame capacity (12288 B on a
Node <=21 remote) was dropped with only a relay stderr line, so the client kept a
stale list forever. The relay now publishes per client and, for a client whose
sink refused the frame, sends a compact `workspace.stale` marker on the control
lane; the client re-reads through `workspace.get`, whose lane is budgeted in
megabytes rather than in one producer frame. A new JSON-RPC notification rather
than a new field on `workspace.changed`: `normalizeSnapshot(undefined, ns)` yields
revision 0 and an empty session, so a Rule-1 field would make an old client
replace its tab list with nothing — worse than the drop. An old client ignores the
unknown method and is exactly where it is today. The marker retention/retry
machinery is extracted from the `fs.changed` overflow path and shared by both.

**The Windows upload hung, and the fix for it could truncate.** `stablyai#16432` was
attributed to `[Console]::In.ReadToEnd()` materializing the base64 bundle. That is
not what the reporter measured: he also measured
`new IO.StreamReader([Console]::OpenStandardInput())` — an incremental reader —
hanging at 1 MB. The limit is in the stdin the host hands PowerShell over a
non-pty ssh exec, not in the string the script builds.

- `uploadFileViaSystemSsh` — the user file-import path — was piping a whole file
  into one Windows stdin, unchunked and untimed. That is the path large files
  take; it now chunks into 32 KB writes and bounds each wait.
- The Windows directory upload reuses that single-file path rather than repeating
  a weaker copy of chunk-read + write-buffer; the `ino`/`dev` TOCTOU verification
  comes with it.
- A Windows write needing more than one exec lands on a `.orca-partial` staging
  path and is published by rename, so a failed chunk cannot leave a truncated
  artifact under the real name. `exclusive` is enforced once at the rename, not on
  the first chunk, where a retry met its own leftovers.
- The mkdir batch reads stdin through the stream reader the reporter measured
  surviving 50 KB, not `[Console]::In`, which he measured wedging at that size.
- `waitForChannelClose` takes an optional bound. A wedged PowerShell stays alive
  at idle CPU and never closes, so without one the promise is simply never
  settled and the caller waits forever with no error to show.

**Quick Open showed a prefix as the whole workspace.** The mechanism "a full page
means there is more" only works if the caller named the cap, and the failing UI
named none — it hardcoded `truncated: false`. Quick Open now names
`QUICK_OPEN_LISTING_MAX_RESULTS` on both the Electron IPC hop and the runtime-RPC
hop (the field stablyai#17954 added to `files.listAll`), and reads a full page as
truncation. The local hop honours the cap too, which it previously ignored.

Rebase note on `fs.listFiles`: an earlier revision of this work also clamped the
host unconditionally, and stablyai#17934 escalated an uncapped request to an explicit
error. stablyai#17954 has since landed and made an oversized reply streamable, which
removes the premise — the host no longer has to choose between a prefix and a
refusal, so it returns the whole listing when no limit is named and only clamps a
limit it was given. Keeping either would have regressed stablyai#17954 and hard-failed
three in-tree callers that deliberately pass no options
(`runtime-file-commands-search-runtime-files.ts:81`,
`filesystem-read-handlers.ts:125`, `runtime-file-commands-constructor.ts:41`).
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