Repository navigation
perf(windows): dedupe per-pane process-table scans in agent inspection - #7384
Conversation
Windows agent foreground-process inspection forks a whole-process-table PowerShell/CIM scan per pane on the same 750ms/2000ms cadence the POSIX path uses. The POSIX side routes through getProcessTableSnapshot (500ms TTL + single in-flight, #6288/#6667), collapsing N concurrent panes to ~2 scans/sec. The Windows path (queryWindowsProcessDescendants) had no such dedup: K concurrent agent panes forked K powershell.exe cold-starts, each enumerating the ENTIRE process table then filtering per-pid in JS — ~10-40x heavier than `ps` (a powershell cold start is ~150-400ms CPU + tens of MB RSS). The degraded/local PTY provider path calls it with no per-pane throttle at all. This is the Windows analogue of the idle-CPU churn #6288 fixed for POSIX. Generalize the existing createProcessTableSnapshotReader factory to be generic over its scan result (default T = string, so the POSIX path and its test are byte-identical) and add a Windows singleton reader that caches parsed WindowsProcessRow[]. queryWindowsProcessDescendants now reads the shared snapshot and runs its own descendant walk; runWindowsProcessRows throws on total enumeration failure so the miss is not cached and the prior null-fallback contract (callers fall through to node-pty's name) is preserved. Windows scan-volume regression test (mirrors the POSIX #6288 guard) drives PANE_COUNT concurrent panes over the cadence window and asserts powershell.exe spawns are bounded by ticks, not pane count, while every pane still resolves its descendant. Reverting the dedup fails both cases. POSIX snapshot + volume tests unchanged and green; node/web/cli typecheck clean. Co-authored-by: Orca <[email protected]>
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThis PR makes the shared process-table snapshot reader generic, uses it to cache Windows process-row enumeration across concurrent descendant queries, and adds a reset helper for tests. ChangesRelated issues: None identified Related PRs: None identified Suggested labels: windows, tests, performance Suggested reviewers: None identified Poem: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 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.
🧹 Nitpick comments (1)
src/main/providers/windows-foreground-process-rows.ts (1)
26-32: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueTrim the comment to 1-2 lines per guideline.
This 7-line block explaining the dedup rationale is much longer than the repo's comment-brevity rule for non-obvious-reason comments.
As per coding guidelines, "Keep comments short — one or two lines, capturing only the non-obvious reason."
✏️ Suggested trim
-// Why: agent foreground inspection forks a whole-process-table PowerShell/CIM -// scan per pane on the same 750ms/2000ms cadence as the POSIX `ps` path. Without -// dedup, K concurrent agent panes fork K powershell.exe cold-starts, each ~10-40x -// heavier than `ps` — the Windows analogue of the idle-CPU churn `#6288/`#6667 fixed -// for POSIX. Reuse the same TTL + single-in-flight reader, caching parsed rows so -// a burst of panes collapses to ~2 scans/sec; every caller runs its own descendant -// walk over the shared snapshot. +// Why: dedupes per-pane PowerShell/CIM scans (same idle-CPU issue as POSIX `ps`, +// see `#6288/`#6667) via the shared TTL + single-in-flight reader.Source: Coding guidelines
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 1a448b13-2cb9-47f1-817f-abf4433c9f96
📒 Files selected for processing (3)
src/main/providers/windows-agent-foreground-process-scan-volume.test.tssrc/main/providers/windows-foreground-process-rows.tssrc/shared/process-table-snapshot.ts
The new module-level Windows rows reader caches for 500ms with real Date.now(), so one case's mocked process table was served to the next case's assertions (7 CI failures in agent-foreground-process.test.ts). Mirror the suite's existing POSIX resetProcessTableSnapshotForTests() with the Windows reset in beforeEach. Co-authored-by: Orca <[email protected]>
|
Took ownership; re-verified and fixed the CI failure before merge. The Independent verification (adversarial review agent + local re-runs):
No further improvements taken without tradeoffs: sharing the snapshot with the other |
stablyai#7384) * perf(windows): dedupe per-pane process-table scans in agent inspection Windows agent foreground-process inspection forks a whole-process-table PowerShell/CIM scan per pane on the same 750ms/2000ms cadence the POSIX path uses. The POSIX side routes through getProcessTableSnapshot (500ms TTL + single in-flight, stablyai#6288/stablyai#6667), collapsing N concurrent panes to ~2 scans/sec. The Windows path (queryWindowsProcessDescendants) had no such dedup: K concurrent agent panes forked K powershell.exe cold-starts, each enumerating the ENTIRE process table then filtering per-pid in JS — ~10-40x heavier than `ps` (a powershell cold start is ~150-400ms CPU + tens of MB RSS). The degraded/local PTY provider path calls it with no per-pane throttle at all. This is the Windows analogue of the idle-CPU churn stablyai#6288 fixed for POSIX. Generalize the existing createProcessTableSnapshotReader factory to be generic over its scan result (default T = string, so the POSIX path and its test are byte-identical) and add a Windows singleton reader that caches parsed WindowsProcessRow[]. queryWindowsProcessDescendants now reads the shared snapshot and runs its own descendant walk; runWindowsProcessRows throws on total enumeration failure so the miss is not cached and the prior null-fallback contract (callers fall through to node-pty's name) is preserved. Windows scan-volume regression test (mirrors the POSIX stablyai#6288 guard) drives PANE_COUNT concurrent panes over the cadence window and asserts powershell.exe spawns are bounded by ticks, not pane count, while every pane still resolves its descendant. Reverting the dedup fails both cases. POSIX snapshot + volume tests unchanged and green; node/web/cli typecheck clean. Co-authored-by: Orca <[email protected]> * test: reset windows process-rows snapshot between agent-foreground cases The new module-level Windows rows reader caches for 500ms with real Date.now(), so one case's mocked process table was served to the next case's assertions (7 CI failures in agent-foreground-process.test.ts). Mirror the suite's existing POSIX resetProcessTableSnapshotForTests() with the Windows reset in beforeEach. Co-authored-by: Orca <[email protected]> --------- Co-authored-by: Orca <[email protected]>
Description
Windows agent foreground-process inspection (
queryWindowsProcessDescendants) forks a whole-process-table PowerShell/CIM scan per pane, on the same 750ms/2000ms cadence the POSIX path uses. The POSIX side routes throughgetProcessTableSnapshot(500ms TTL + single in-flight promise, #6288/#6667), which collapses N concurrent panes to ~2 scans/sec. Windows had no equivalent, so K concurrent agent panes forked Kpowershell.execold-starts, each enumerating the entireWin32_Processtable and filtering per-pid in JS.Fix: generalize the existing
createProcessTableSnapshotReaderfactory to be generic over its scan result (<T = string>, so the POSIX path stays byte-identical), and add a Windows singleton reader that caches parsedWindowsProcessRow[].ELI5
To show which AI agent is running in each terminal, Orca on Windows ran a heavy "list every process on the machine" PowerShell command — separately for each terminal, a few times a second. With several agent terminals open, that spun up lots of PowerShell processes (each ~10–40× heavier than the Mac/Linux
psequivalent) and chewed idle CPU. Now they all share one recent scan, refreshed twice a second, instead of each running their own.Evidence
New
windows-agent-foreground-process-scan-volume.test.tsmirrors the POSIX #6288 guard: mocksexecFile, drivesPANE_COUNTpanes concurrently across the cadence window, and assertspowershell.exespawns are bounded by poll ticks, not pane count, while every pane still resolves its foreground descendant. A second case asserts a concurrent burst collapses to a single scan. Reverting the dedup fails both.POSIX snapshot +
ps-scan volume tests are unchanged and green (the generic change defaults to the oldstringtype); node/web/cli typecheck + oxlint clean.The null-fallback contract is preserved:
runWindowsProcessRowsthrows on total enumeration failure so the miss isn't cached, andqueryWindowsProcessDescendantscatches it and returnsnull(callers then fall through to node-pty's process name, exactly as before).Trade-offs
process-table-snapshot.ts, also used by the SSH relay). The change is purely additive (generic withT = stringdefault → POSIX/relay runtime is byte-identical and re-tested), but the blast radius technically includes that proven path — the reason it was kept type-parametric rather than rewritten.Scope
src/shared/process-table-snapshot.ts(additive generic) +src/main/providers/windows-foreground-process-rows.ts+ test. No behavior change for POSIX/relay.