Skip to content

fix(space): stream workspace space scans - #7840

Closed
bbingz wants to merge 3 commits into
stablyai:mainfrom
bbingz:fix/space-stream-scans
Closed

bbingz wants to merge 3 commits into
stablyai:mainfrom
bbingz:fix/space-stream-scans

Conversation

@bbingz

@bbingz bbingz commented Jul 8, 2026 •

Copy link
Copy Markdown
Contributor

Review follow-up (e9da2f56)

Observe request staleness on every du stdout chunk and use the existing abort cleanup. The new signal-free relay regression proves one child kill and cancellation; 14 tests across 5 files, allCLI/Node/Web non-composite TypeScript and changed-file hygiene passed. No prior assertions were weakened. Silent children retain the existing abort-signal/deadline behavior. Full suite/build and live SSH/native-host smoke were not repeated. Independent Cursor review passed for this exact commit.

Previously verified rebase

Summary

Workspace Space scans now parse native du stdout as it arrives, replacing the fixed 16 MiB execFile buffer. Retained entries use the existing 100,000-entry / 64 MiB budget; stderr is capped separately. The scan lists top-level entries before starting du, cancels when its owning renderer is destroyed, and stops without a second traversal when du reaches its deadline or the retained-entry budget.

The 120-second du deadline and 130-second SSH scan request deadline remain. SSH multiplex requests can optionally disable their local timer with timeoutMs: null while retaining explicit abort cancellation; Space scans themselves still use 130 seconds. Missing du retains the portable walker fallback, and Windows continues using that walker. Main and relay share the streamed parser; folder workspaces use the same scan path.

Existing timeout tests intentionally stop expecting a second portable traversal after a wedged du: timeout and capacity overflow now make the worktree unavailable. Tests also cover UTF-8 chunk boundaries, cancellation, retained-row overflow, owner destruction and portable fallback concurrency. No RPC method or binary stream opcode is added.

Testing and review

At de5c17159fe6bae69460dd6bbab25b2a044508f5, independent verification passed 145 tests across 14 files, with no failures or skips. CLI, Node and Web TypeScript (--composite false), changed-file lint/format, diff whitespace and native preflight/postflight passed. Independent Cursor review passed on this exact commit.

Full repository tests, packaging and live Electron/SSH/mixed-version or Windows/Linux smoke were not run. Automated checks ran on macOS.

AI disclosure

Cursor ported and independently reviewed the change; Codex checked the original requirements, source and verification results.

@coderabbitai

coderabbitai Bot commented Jul 8, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

📝 Walkthrough

Walkthrough

The change adds shared streaming du execution for main and relay workspace scans. It supports incremental UTF-8 parsing, entry budgets, cancellation, process termination, and 120-second timeout errors. Main and relay scans classify timeout and capacity failures as unavailable and retain portable fallback scans. SSH requests can disable per-request timeouts. Renderer destruction now cancels its active scan. Tests cover streaming, fallback concurrency, cancellation, capacity limits, and lifecycle cleanup.

Priority: ➖ Normal

Merge Risk: 🟡 Moderate · up to 19b80

Windows test runs can time out, and stale workspace scans can continue consuming process and RPC resources for up to two minutes. These issues should be fixed before merging.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the implementation and testing results, but it does not follow the required template. It omits the ELI5, What Changed, Why, Linked Issue, Visual Proof, Review, Agent skill ups… Update the description to include all required template sections. Add the linked issue after “Fixes #”, provide “N/A” with a reason for Visual Proof if there is no UI change, document testing and platforms, complete the required checkboxes,…
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 31 functions across 17 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately describes the main change: streaming workspace space scans.
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 explains the implementation and testing results, but it does not follow the required template. It omits the ELI5, What Changed, Why, Linked Issue, Visual Proof, Review, Agent skill upstream boundary, Notes, and Checklist sections.

Resolution

Update the description to include all required template sections. Add the linked issue after “Fixes #”, provide “N/A” with a reason for Visual Proof if there is no UI change, document testing and platforms, complete the required checkboxes, and address security, cross-platform, SSH, mobile, compatibility, and performance considerations.

  • Fix all pre-merge checks with AI

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.

@bbingz

bbingz commented Jul 11, 2026

Copy link
Copy Markdown
Contributor Author

@Jinwoo-H When you have capacity, could you review this focused workspace scan streaming PR? Its current head is mergeable and CodeRabbit is green.

@bbingz
bbingz force-pushed the fix/space-stream-scans branch from fba27cb to 53772a9 Compare July 12, 2026 10:04
@bbingz

bbingz commented Jul 12, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto latest origin/main to clear merge conflict in src/main/providers/ssh-filesystem-provider.ts (kept main's SftpFactory/upload imports + WORKSPACE_SPACE_SCAN_TIMEOUT_MS, preserved PR streaming space-scan path).

@bbingz

bbingz commented Jul 13, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 13, 2026 •

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@bbingz

bbingz commented Jul 13, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai review\n\nPlease review the current head after the clean current-main merge.

@bbingz

bbingz commented Jul 13, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

Please review current head f2b75e9 after the clean current-main merge.

@coderabbitai

coderabbitai Bot commented Jul 13, 2026 •

Copy link
Copy Markdown
Contributor

@bbingz Got it — I'll review the current head now that the merge with main is clean.

✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai

coderabbitai Bot commented Jul 13, 2026 •

Copy link
Copy Markdown
Contributor

@bbingz Got it — I'll review the current head (f2b75e9) now that the merge with main is clean.

✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@bbingz
bbingz force-pushed the fix/space-stream-scans branch from f2b75e9 to 38b7903 Compare July 19, 2026 13:40
@bbingz

bbingz commented Jul 19, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto latest main (clean, 3 commits). Kept main's isWindowsRemoteHost import while dropping the obsolete WORKSPACE_SPACE_SCAN_TIMEOUT_MS constant as this PR intends.

@AmethystLiang AmethystLiang assigned OrcaWin and unassigned Jinwoo-H Jul 20, 2026
@AmethystLiang
AmethystLiang requested a review from OrcaWin July 20, 2026 18:32
@nwparker nwparker added the bug Something isn't working label Jul 27, 2026
@bbingz
bbingz force-pushed the fix/space-stream-scans branch 2 times, most recently from 60badd2 to a56f058 Compare July 30, 2026 02:01
Comment thread src/main/workspace-space-analysis.ts Resolved
Comment thread src/main/workspace-space-analysis.ts Resolved
Comment thread src/relay/workspace-space-scan.ts Resolved
@greptile-apps

greptile-apps Bot commented Jul 30, 2026 •

Copy link
Copy Markdown

Greptile Summary

This PR replaces buffered execFile-based du -k -d 1 calls with streaming spawn-based calls on both the main process and relay, adds a WorkspaceSpaceScanBudget guard on streamed du rows to bound memory, restores the 120 s du timeout as a stream-level deadline, and wires up renderer-destruction as an abort trigger for in-flight scans.

  • Streaming du: execFile (fixed buffer) is replaced by spawn with a StringDecoder to safely handle multibyte paths split across chunks; consumeDuOutputChunk processes lines incrementally and calls retainWorkspaceSpaceScanEntry on each new entry so the budget cap applies mid-stream.
  • SSH multiplexer timeoutMs: null: Allows callers to opt out of the default per-request timeout while preserving AbortSignal cancellation and relay-side rpc.cancel, which the SSH space-scan provider will use to avoid a fixed deadline on arbitrarily large remote worktrees.
  • Renderer-destruction abort: workspace-space.ts now listens for the 'destroyed' event on the IPC sender and aborts the global in-flight scan, preventing a later renderer from inheriting an unreachable pending request.

Confidence Score: 5/5

Safe to merge; the streaming conversion, budget guard, and renderer-abort hook are all exercised by new tests and the 120 s du deadline is preserved.

The most significant behavioural change is serialising directory listing before spawning du, where they previously ran concurrently. This is a non-blocking performance trade-off rather than a correctness issue. All error paths (ENOENT fallback, timeout, capacity exceeded, cancellation) are covered by new tests. The multiplexer timeout-disable change is well-guarded and tested. No data-loss or auth-boundary concerns are introduced.

Files Needing Attention: src/main/workspace-space-analysis.ts and src/relay/workspace-space-scan.ts both dropped the concurrent Promise.all([opendir, du]) in favour of sequential awaits; worth confirming the latency trade-off is acceptable for wide directories.

Important Files Changed

Filename Overview
src/main/workspace-space-analysis.ts Replaces execFile with spawn for streaming du output; adds WorkspaceSpaceDuTimeoutError and per-entry budget tracking; serialises directory listing and du where they previously ran concurrently
src/relay/workspace-space-scan.ts Mirrors main-side streaming du change with relay-specific error types; same sequential listing to du ordering change and same budget-based capacity guard
src/main/ssh/ssh-channel-multiplexer.ts Allows timeoutMs: null to disable per-request timeout while preserving AbortSignal cancellation; timer field in PendingRequest becomes nullable, cleanup() correctly clears it via closure
src/main/ipc/workspace-space.ts Adds owner destroyed listener to abort the in-flight scan when the owning renderer is destroyed, preventing a later renderer from inheriting a stale pending request
src/main/workspace-space-analysis-du-timeout.test.ts Replaces execFile-based du mock with spawn-based EventEmitter child; adds tests for streaming output, multibyte path splits, timeout, budget exceeded, and Node fallback
src/relay/workspace-space-scan-du.test.ts New test file covering relay-side streaming du: streamed output, multibyte path splits, timeout-while-preserving-cancellation, and Node fallback on ENOENT
src/relay/workspace-space-scan-fallback-concurrency.test.ts New test file verifying relay-side portable fallback concurrency and that no deep child-tree state is retained
src/main/workspace-space-analysis-fallback-concurrency.test.ts New test file verifying that the portable Node fallback scans directory entries concurrently without retaining the full child tree
src/relay/workspace-space-scan-du-capacity.test.ts Updated to split du and listing budget limits into separate mock state; adds test that du is killed and fails closed when streamed rows exceed the retained budget
src/main/ssh/ssh-channel-multiplexer.test.ts Adds test verifying that timeoutMs: null disables the request timeout while AbortSignal cancellation still sends rpc.cancel and rejects with AbortError
src/main/ipc/workspace-space.test.ts Upgrades createEvent() to use an EventEmitter-backed sender so destroyed can be emitted; adds test that a destroyed renderer aborts the in-flight scan and allows a fresh scan to start
src/main/providers/ssh-filesystem-provider.ts Minor: numeric literal 130000 to 130_000 formatting; WORKSPACE_SPACE_SCAN_TIMEOUT_MS constant moved to its own line
src/main/providers/ssh-filesystem-provider.test.ts Trivial: test assertion updated to use 130_000 numeric separator to match the updated source literal

Sequence Diagram

sequenceDiagram
    participant R as Renderer
    participant IPC as workspace-space.ts
    participant Analysis as analyzeWorkspaceSpace
    participant DU as spawn('du')
    participant Relay as relay/workspace-space-scan
    participant SSH as SshChannelMultiplexer

    R->>IPC: workspaceSpace:analyze
    IPC->>IPC: register owner 'destroyed' listener
    IPC->>Analysis: "analyzeWorkspaceSpace(store, {signal})"

    alt Local worktree (non-Windows)
        Analysis->>Analysis: opendir + collectEntries
        Analysis->>DU: spawn('du', ['-k','-d','1', path])
        DU-->>Analysis: stdout data chunks (streaming)
        Analysis->>Analysis: consumeDuOutputChunk() + budget check
        DU-->>Analysis: close(0)
        Analysis-->>Analysis: resolve sizes Map
    else Remote worktree (SSH)
        Analysis->>SSH: "mux.request('fs.workspaceSpaceScan', {signal, timeoutMs: null})"
        SSH->>Relay: JSON-RPC request
        Relay->>DU: spawn('du', [...])
        DU-->>Relay: stdout streaming
        Relay-->>SSH: JSON-RPC response
        SSH-->>Analysis: result
    end

    alt Owner renderer destroyed mid-scan
        R->>IPC: emit 'destroyed'
        IPC->>Analysis: controller.abort()
        Analysis->>DU: child.kill()
    end

    Analysis-->>IPC: WorkspaceSpaceAnalysis
    IPC-->>R: WorkspaceSpaceAnalyzeResult
Loading

Reviews (2): Last reviewed commit: "fix(space): bound streamed workspace sca..." | Re-trigger Greptile

@greptile-apps

greptile-apps Bot commented Jul 30, 2026

Copy link
Copy Markdown

Want your agent to iterate on Greptile's feedback? Try greploops.

@bbingz
bbingz force-pushed the fix/space-stream-scans branch from 06dff82 to e377983 Compare August 4, 2026 00:44
@bbingz
bbingz force-pushed the fix/space-stream-scans branch from e377983 to de5c171 Compare September 8, 2026 22:12
@coderabbitai

coderabbitai Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Note

The previously reviewed commits are no longer reachable (likely due to a force-push or rebase), so CodeRabbit is performing a full review instead of an incremental one. This review may take a little longer.

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/main/workspace-space-analysis-du-timeout.test.ts (1)

53-60: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚖️ Poor tradeoff

Key the mocked capacity limit to the budget purpose. scanLocalWorktreeWithDu creates the directory-listing budget before readWorkspaceSpaceDuDepthOne creates the budget for streamed du rows. The mock selects the latter with budgetState.created === 2, so a future budget insertion or reorder can apply duMaxEntries to another budget and stop this test from covering the streamed-row capacity path. Pass an explicit purpose marker to createWorkspaceSpaceScanBudget, or use separate listing and du budget factories.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 86d96781-ffd9-4fbc-92dc-41303c99c701

📥 Commits

Reviewing files that changed from the base of the PR and between 12f2c6b and de5c17159fe6bae69460dd6bbab25b2a044508f5.

📒 Files selected for processing (17)
  • src/main/ipc/workspace-space.test.ts
  • src/main/ipc/workspace-space.ts
  • src/main/providers/ssh-filesystem-provider.test.ts
  • src/main/providers/ssh-filesystem-provider.ts
  • src/main/ssh/ssh-channel-multiplexer.test.ts
  • src/main/ssh/ssh-channel-multiplexer.ts
  • src/main/workspace-space-analysis-du-timeout.test.ts
  • src/main/workspace-space-analysis-fallback-concurrency.test.ts
  • src/main/workspace-space-analysis.ts
  • src/main/workspace-space-local-scan.ts
  • src/main/workspace-space-scan-control.test.ts
  • src/main/workspace-space-scan-control.ts
  • src/relay/workspace-space-scan-du-capacity.test.ts
  • src/relay/workspace-space-scan-du.test.ts
  • src/relay/workspace-space-scan-fallback-concurrency.test.ts
  • src/relay/workspace-space-scan.ts
  • src/shared/workspace-space-du-stream.ts
🚧 Files skipped from review as they are similar to previous changes (5)
  • src/main/ssh/ssh-channel-multiplexer.test.ts
  • src/main/workspace-space-analysis-fallback-concurrency.test.ts
  • src/relay/workspace-space-scan.ts
  • src/main/ssh/ssh-channel-multiplexer.ts
  • src/relay/workspace-space-scan-fallback-concurrency.test.ts

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

Comment thread src/shared/workspace-space-du-stream.ts Resolved
bbingz and others added 2 commits September 20, 2026 19:10
Stream native du output under the shared scan budget and fail closed on
timeout or overflow so large or stalled folders cannot buffer unbounded
output or inherit a destroyed renderer's in-flight scan.

Co-authored-by: Cursor <[email protected]>
@bbingz
bbingz force-pushed the fix/space-stream-scans branch from e9da2f5 to 19b802e Compare September 20, 2026 11:12

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to GitHub limitations.

⚠️ Outside diff range comments (1)

🟡 Minor · Cancel du when the relay request becomes stale. · workspace-space-du-stream.ts:75-196

src/shared/workspace-space-du-stream.ts:75-196
🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

Cancel du when the relay request becomes stale. fs.workspaceSpaceScan passes RequestContext.isStale to readWorkspaceSpaceDuDepthOne, but the helper checks that callback only before spawning and when stdout emits data. If the request becomes stale after du starts and du emits no further stdout, the child and RPC remain active until du exits or the 120-second deadline kills it. Make staleness cancellation observable independently of stdout and terminate the child promptly.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: aac28d76-c637-45d1-919b-4d78e004dc2b

📥 Commits

Reviewing files that changed from the base of the PR and between e9da2f56e4e5eb8ff334aeafc84e992a80592aaf and 19b802e.

📒 Files selected for processing (5)
  • src/main/providers/ssh-filesystem-provider.test.ts
  • src/main/providers/ssh-filesystem-provider.ts
  • src/main/workspace-space-analysis-du-timeout.test.ts
  • src/relay/workspace-space-scan-du-capacity.test.ts
  • src/relay/workspace-space-scan-du.test.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/main/providers/ssh-filesystem-provider.ts
  • src/main/providers/ssh-filesystem-provider.test.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 4 remain after this review.

expect(spawnMock).not.toHaveBeenCalled()
})

it('kills du and fails closed when streamed rows exceed the retained budget', async () => {

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.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Skip this native du test on Windows.

scanWorkspaceSpaceDirectory uses the Node walker on Windows. It does not call spawn. The wait at Line 105 therefore times out on Windows.

Use it.skipIf(process.platform === 'win32'), as the other relay native-du tests do.

@bbingz

bbingz commented Oct 25, 2026

Copy link
Copy Markdown
Contributor Author

Closing as obsolete: the relay and SSH filesystem provider this streamed through were removed (#27215, #27214), and local du was rewritten in #29513.

@bbingz bbingz closed this Oct 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants