Skip to content

perf(windows): read the process table natively instead of forking PowerShell - #15749

Merged
nwparker merged 5 commits into
mainfrom
nwparker/w1b-windows-process-table
Aug 22, 2026
Merged

nwparker merged 5 commits into
mainfrom
nwparker/w1b-windows-process-table

Conversation

@nwparker

@nwparker nwparker commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 9 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​673 $\color{#cf222e}{\Huge{\mathbf{−}}}$​818 $\color{#cf222e}{\Huge{\mathbf{−}}}$​145
Prod 12 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​372 $\color{#cf222e}{\Huge{\mathbf{−}}}$​232 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​140

Stacked on #15746. Review that one first; this diff is against it.

Why

Seven independent readers each forked powershell.exe to run Get-CimInstance Win32_Process, with a wmic fallback that Windows 11 24H2 has removed. Node can't read parent-PIDs on Windows without native code, which is why they all existed.

That shape produced several unrelated-looking bugs:

A Toolhelp32 snapshot answers the same question with no child process at all, so none of those failure modes have anywhere to live.

Measured on real hardware

Windows 11, 1050 processes, same box, p50 / p95:

p50 p95
pid + ppid + name (the teardown identity path) 15.9 ms 17.5 ms
+ memory + command line 30.6 ms 33.7 ms
Get-CimInstance via PowerShell (today) 706 ms 723 ms

~44× on the path that currently sits behind a 3-second timeout during teardown.

Two upstream defects, both found by running it

Neither shows up in the docs; both came out of a spike on a real box.

  1. Spectre. The upstream binding.gyp requires Spectre-mitigated libraries our Windows agents don't install — build fails with MSB8040. node-pty is patched the same way for the same reason.
  2. A silent 1024-process cap. GetRawProcessList stopped after 1024 entries. On a host with 1051 processes it returned exactly 1024, and the querying process was itself among the 27 missing — getProcessList(self) failed outright. A truncated snapshot silently hides the descendants a teardown is looking for. That is precisely the bug class this change exists to remove, so adopting the package unpatched would have reimported it.

Both are one-line hunks in config/patches/@[email protected].

Also worth recording: the typings say commandLine is truncated at 512 chars. Measured, it isn't — longest observed was 26,059. That risk is closed, not worked around.

Scope — what is deliberately not migrated

  • The memory collector and three identity probes (daemon-process-inspection, daemon-process-identity-query, managed-hook-owner-identity) read Win32_Process.CreationDate, which has no native equivalent.
  • The package's getProcessCpuUsage() is not adopted: it takes both CPU samples inside one call with a blocking Sleep(1000), which would hold a libuv threadpool slot for a full second out of the Resource Manager's two-second poll. Given [Bug]: Terminal intermittently stops accepting text input #8104, that's not a trade worth making.

Start time is a proxy for identity. For trees Orca itself spawned, an inherited job handle is the real answer, so those readers belong with the job-object change rather than here. docs/reference/windows-process-enumeration.md records that reasoning so the next person doesn't just bolt a start time onto the facade.

Tests

  • New facade unit tests, including that an unreadable table rejects rather than reporting an empty machine. That distinction is load-bearing: callers act on "no processes" by declaring a tree dead.
  • Four suites retargeted from mocking child_process to the module seam. Cases that became unrepresentable were deleted, not neutered — "falls back to WMIC when PowerShell fails" and "the probe passes windowsHide" no longer describe anything real. Scan-volume bounds were kept and now count snapshots.
  • Packaging contract test extended. It also stops pinning a whole source literal that only tested its own formatting.
  • Full suite: 30,178 tests, no regressions.

Packaging

Follows the windows-native-registry contract exactly: optionalDependency, absent from onlyBuiltDependencies (pnpm installs optional deps on every host, so macOS/Linux must never run node-gyp for a Windows addon), win32-only in the packaged runtime. Verified createPackagedRuntimeNodeModuleResources emits it for win32 and not for darwin/linux.

Issues

Closes #15209. Materially addresses #15036 and #10686. Removes the probe-failure mode behind #9045 and #10475 — the kill decision itself is the next PR.

@nwparker
nwparker force-pushed the nwparker/w1b-windows-process-table branch 4 times, most recently from af3e36d to 3bd9e68 Compare August 22, 2026 04:10
@nwparker
nwparker requested a review from brennanb2025 as a code owner August 22, 2026 04:10
@greptile-apps

greptile-apps Bot commented Aug 22, 2026 •

Copy link
Copy Markdown

Too many files changed for review (174 files, 100 file limit).

Bypass the limit by tagging @greptile-apps to review.

…erShell

Seven independent readers each forked powershell.exe to run
Get-CimInstance Win32_Process, with a wmic fallback that Windows 11 24H2
has removed. On a domain-joined host with PowerShell Transcription
enabled by policy, one of them running every ~2s recorded ~289GB across
1.4 million files (#15209). The same scan cost ~700ms and ran per pane
(#15036), and a Group Policy or AV block turned it into 'unavailable',
which callers read as 'no evidence' -- which is how a PTY tree survives
its own teardown (#9045, #10475).

A Toolhelp32 snapshot answers the same question with no child process.
Measured on Windows 11 with 1050 processes, p50/p95:

  pid+ppid+name          15.9 / 17.5 ms
  +memory +command line  30.6 / 33.7 ms
  Get-CimInstance         706 / 723  ms

Two upstream defects needed patching, both found by running it on real
hardware. The binding requires Spectre-mitigated libraries our agents do
not carry (node-pty is patched the same way). And enumeration stopped
after 1024 processes: on a host with 1051 the module returned exactly
1024, and the querying process was itself among the 27 missing -- a
truncated snapshot silently hides the descendants teardown is looking
for, which is the failure this whole change exists to remove.

Migrated: the foreground/descendant reader (the #15209 scraper and the
teardown identity gate) and the port scanner's PID attribution. NOT
migrated: the memory collector and three identity probes, which need
Win32_Process.CreationDate and have no native equivalent. Start time is
a proxy for identity anyway; an inherited job handle is the real answer,
so those belong with the job-object work rather than here.

Packaging follows the windows-native-registry contract exactly:
optional, absent from onlyBuiltDependencies so macOS/Linux never run
node-gyp, win32-only in the packaged runtime. Asserted by the existing
contract test, which also stops pinning a whole source literal that only
tested its own formatting.
windows-foreground-process-rows.ts no longer spawns anything, so its
allowlist line is stale. The guard fails on a stale entry as well as a
new one, precisely so a migrated file cannot keep a slot open and hide
the next regression in the same path.
Missing import: the migration replaced the PowerShell call but the new
symbol was never imported, so tsc failed. Vitest transpiles without
typechecking, which is why the port-scanner suite stayed green.
Same class as the fix on the tip branch: pnpm records a hash per patched
dependency, and this branch introduces the windows-process-tree patch
without its lockfile entry matching. Every job here failed at install
with ERR_PNPM_LOCKFILE_CONFIG_MISMATCH.

Verified with --frozen-lockfile, which is what CI runs and what my local
runs were not.
Two relay cases fed a PowerShell CIM payload through a mocked execFile.
That reader is gone, so both failed -- deterministically, on every PR
run for this branch and the one above it.

I did not catch it because my own verification sweep was
'src/main src/shared config/scripts' and never included src/relay. The
relay is a first-class consumer of the process table; leaving it out of
the sweep is how a deterministic failure survived six review rounds.
@nwparker

Copy link
Copy Markdown
Contributor Author

Merged to main.

Closed by this stack: #10488, #15209, #9045, #10475, #10897, #9195, #10415.

Commented, not closed — partially addressed or needing a reporter re-test: #14543, #11771, #15036, #10686, #10087, #8275, #10150, #10358, #10857.

Withdrawn: #15549 — I claimed it early and hardware testing disproved it. Job liveness reports null, not [], for a dead tree.

Windows CI now gates the argv encoder against real cmd.exe, per-pane tree kill, clean-exit preservation, breakaway, and host-death reaping.

paidaxingyo666 pushed a commit to paidaxingyo666/Manta that referenced this pull request Aug 23, 2026
…erShell (stablyai#15749)

* perf(windows): read the process table natively instead of forking PowerShell

Seven independent readers each forked powershell.exe to run
Get-CimInstance Win32_Process, with a wmic fallback that Windows 11 24H2
has removed. On a domain-joined host with PowerShell Transcription
enabled by policy, one of them running every ~2s recorded ~289GB across
1.4 million files (stablyai#15209). The same scan cost ~700ms and ran per pane
(stablyai#15036), and a Group Policy or AV block turned it into 'unavailable',
which callers read as 'no evidence' -- which is how a PTY tree survives
its own teardown (stablyai#9045, stablyai#10475).

A Toolhelp32 snapshot answers the same question with no child process.
Measured on Windows 11 with 1050 processes, p50/p95:

  pid+ppid+name          15.9 / 17.5 ms
  +memory +command line  30.6 / 33.7 ms
  Get-CimInstance         706 / 723  ms

Two upstream defects needed patching, both found by running it on real
hardware. The binding requires Spectre-mitigated libraries our agents do
not carry (node-pty is patched the same way). And enumeration stopped
after 1024 processes: on a host with 1051 the module returned exactly
1024, and the querying process was itself among the 27 missing -- a
truncated snapshot silently hides the descendants teardown is looking
for, which is the failure this whole change exists to remove.

Migrated: the foreground/descendant reader (the stablyai#15209 scraper and the
teardown identity gate) and the port scanner's PID attribution. NOT
migrated: the memory collector and three identity probes, which need
Win32_Process.CreationDate and have no native equivalent. Start time is
a proxy for identity anyway; an inherited job handle is the real answer,
so those belong with the job-object work rather than here.

Packaging follows the windows-native-registry contract exactly:
optional, absent from onlyBuiltDependencies so macOS/Linux never run
node-gyp, win32-only in the packaged runtime. Asserted by the existing
contract test, which also stops pinning a whole source literal that only
tested its own formatting.

* chore(process): ratchet the child_process allowlist down

windows-foreground-process-rows.ts no longer spawns anything, so its
allowlist line is stale. The guard fails on a stale entry as well as a
new one, precisely so a migrated file cannot keep a slot open and hide
the next regression in the same path.

* fix(ports): import the process-table reader the scanner uses

Missing import: the migration replaced the PowerShell call but the new
symbol was never imported, so tsc failed. Vitest transpiles without
typechecking, which is why the port-scanner suite stayed green.

* fix(deps): sync this branch's lockfile with its patch set

Same class as the fix on the tip branch: pnpm records a hash per patched
dependency, and this branch introduces the windows-process-tree patch
without its lockfile entry matching. Every job here failed at install
with ERR_PNPM_LOCKFILE_CONFIG_MISMATCH.

Verified with --frozen-lockfile, which is what CI runs and what my local
runs were not.

* test(relay): drive the relay's Windows fixtures from the native snapshot

Two relay cases fed a PowerShell CIM payload through a mocked execFile.
That reader is gone, so both failed -- deterministically, on every PR
run for this branch and the one above it.

I did not catch it because my own verification sweep was
'src/main src/shared config/scripts' and never included src/relay. The
relay is a first-class consumer of the process table; leaving it out of
the sweep is how a deterministic failure survived six review rounds.

(cherry picked from commit 057fbfc)
dallascrilley pushed a commit to dallascrilley/orca that referenced this pull request Aug 27, 2026
…erShell (stablyai#15749)

* perf(windows): read the process table natively instead of forking PowerShell

Seven independent readers each forked powershell.exe to run
Get-CimInstance Win32_Process, with a wmic fallback that Windows 11 24H2
has removed. On a domain-joined host with PowerShell Transcription
enabled by policy, one of them running every ~2s recorded ~289GB across
1.4 million files (stablyai#15209). The same scan cost ~700ms and ran per pane
(stablyai#15036), and a Group Policy or AV block turned it into 'unavailable',
which callers read as 'no evidence' -- which is how a PTY tree survives
its own teardown (stablyai#9045, stablyai#10475).

A Toolhelp32 snapshot answers the same question with no child process.
Measured on Windows 11 with 1050 processes, p50/p95:

  pid+ppid+name          15.9 / 17.5 ms
  +memory +command line  30.6 / 33.7 ms
  Get-CimInstance         706 / 723  ms

Two upstream defects needed patching, both found by running it on real
hardware. The binding requires Spectre-mitigated libraries our agents do
not carry (node-pty is patched the same way). And enumeration stopped
after 1024 processes: on a host with 1051 the module returned exactly
1024, and the querying process was itself among the 27 missing -- a
truncated snapshot silently hides the descendants teardown is looking
for, which is the failure this whole change exists to remove.

Migrated: the foreground/descendant reader (the stablyai#15209 scraper and the
teardown identity gate) and the port scanner's PID attribution. NOT
migrated: the memory collector and three identity probes, which need
Win32_Process.CreationDate and have no native equivalent. Start time is
a proxy for identity anyway; an inherited job handle is the real answer,
so those belong with the job-object work rather than here.

Packaging follows the windows-native-registry contract exactly:
optional, absent from onlyBuiltDependencies so macOS/Linux never run
node-gyp, win32-only in the packaged runtime. Asserted by the existing
contract test, which also stops pinning a whole source literal that only
tested its own formatting.

* chore(process): ratchet the child_process allowlist down

windows-foreground-process-rows.ts no longer spawns anything, so its
allowlist line is stale. The guard fails on a stale entry as well as a
new one, precisely so a migrated file cannot keep a slot open and hide
the next regression in the same path.

* fix(ports): import the process-table reader the scanner uses

Missing import: the migration replaced the PowerShell call but the new
symbol was never imported, so tsc failed. Vitest transpiles without
typechecking, which is why the port-scanner suite stayed green.

* fix(deps): sync this branch's lockfile with its patch set

Same class as the fix on the tip branch: pnpm records a hash per patched
dependency, and this branch introduces the windows-process-tree patch
without its lockfile entry matching. Every job here failed at install
with ERR_PNPM_LOCKFILE_CONFIG_MISMATCH.

Verified with --frozen-lockfile, which is what CI runs and what my local
runs were not.

* test(relay): drive the relay's Windows fixtures from the native snapshot

Two relay cases fed a PowerShell CIM payload through a mocked execFile.
That reader is gone, so both failed -- deterministically, on every PR
run for this branch and the one above it.

I did not catch it because my own verification sweep was
'src/main src/shared config/scripts' and never included src/relay. The
relay is a first-class consumer of the process table; leaving it out of
the sweep is how a deterministic failure survived six review rounds.
OrcaWin pushed a commit that referenced this pull request Sep 8, 2026
The relocated daemon host mirrors the install dir, but the manifest copied
only node-pty out of resources/node_modules. `@vscode/windows-process-tree`
was never copied, so `require` failed inside orca-terminal-daemon.exe,
`readOneSnapshot` took the absent-module branch, and every process-table read
fell through to `powershell.exe Get-CimInstance Win32_Process`.

That is #16905. The transcript pasted in the issue is byte-identical to
POWERSHELL_PROCESS_QUERY, not to the memory collector's query -- which is also
why toggling Resource Manager off changed nothing. The foreground tracker
refreshes on the renderer's 2s agent-completion poll, so it ran about once per
agent pane per two seconds, indefinitely.

Copy the addon's runtime surface (package.json, lib/, the .node) into the
mirror, and hash the addon into the materialization marker so a host missing
or carrying a stale one is re-materialized rather than used: a host that
cannot load it still runs, and silently forks a shell per snapshot, which is
the failure this is fixing.

Check the addon exists before the copy, not after -- the marker hashes it, so
otherwise a ~260MB copy runs and is discarded when the hash throws, on every
launch. Absence still fails open to the install-dir host, which has it.

Finally, warn once when the CIM fallback engages. Absence is legitimate on a
relay; being quiet about it is how this lasted months.

Fixes #16905. Related to #15209 and #15749.
OrcaWin pushed a commit that referenced this pull request Sep 8, 2026
The relocated daemon host mirrors the install dir, but the manifest copied
only node-pty out of resources/node_modules. `@vscode/windows-process-tree`
was never copied, so `require` failed inside orca-terminal-daemon.exe,
`readOneSnapshot` took the absent-module branch, and every process-table read
fell through to `powershell.exe Get-CimInstance Win32_Process`.

That is #16905. The transcript pasted in the issue is byte-identical to
POWERSHELL_PROCESS_QUERY, not to the memory collector's query -- which is also
why toggling Resource Manager off changed nothing. The foreground tracker
refreshes on the renderer's 2s agent-completion poll, so it ran about once per
agent pane per two seconds, indefinitely.

Copy the addon's runtime surface (package.json, lib/, the .node) into the
mirror, and hash the addon into the materialization marker so a host missing
or carrying a stale one is re-materialized rather than used: a host that
cannot load it still runs, and silently forks a shell per snapshot, which is
the failure this is fixing.

Check the addon exists before the copy, not after -- the marker hashes it, so
otherwise a ~260MB copy runs and is discarded when the hash throws, on every
launch. Absence still fails open to the install-dir host, which has it.

Finally, warn once when the CIM fallback engages. Absence is legitimate on a
relay; being quiet about it is how this lasted months.

Fixes #16905. Related to #15209 and #15749.
OrcaWin pushed a commit that referenced this pull request Sep 8, 2026
The relocated daemon host mirrors the install dir, but the manifest copied
only node-pty out of resources/node_modules. `@vscode/windows-process-tree`
was never copied, so `require` failed inside orca-terminal-daemon.exe,
`readOneSnapshot` took the absent-module branch, and every process-table read
fell through to `powershell.exe Get-CimInstance Win32_Process`.

That is #16905. The transcript pasted in the issue is byte-identical to
POWERSHELL_PROCESS_QUERY, not to the memory collector's query -- which is also
why toggling Resource Manager off changed nothing. The foreground tracker
refreshes on the renderer's 2s agent-completion poll, so it ran about once per
agent pane per two seconds, indefinitely.

Copy the addon's runtime surface (package.json, lib/, the .node) into the
mirror, and hash the addon into the materialization marker so a host missing
or carrying a stale one is re-materialized rather than used: a host that
cannot load it still runs, and silently forks a shell per snapshot, which is
the failure this is fixing.

Check the addon exists before the copy, not after -- the marker hashes it, so
otherwise a ~260MB copy runs and is discarded when the hash throws, on every
launch. Absence still fails open to the install-dir host, which has it.

Finally, warn once when the CIM fallback engages. Absence is legitimate on a
relay; being quiet about it is how this lasted months.

Fixes #16905. Related to #15209 and #15749.
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…erShell (stablyai#15749)

* perf(windows): read the process table natively instead of forking PowerShell

Seven independent readers each forked powershell.exe to run
Get-CimInstance Win32_Process, with a wmic fallback that Windows 11 24H2
has removed. On a domain-joined host with PowerShell Transcription
enabled by policy, one of them running every ~2s recorded ~289GB across
1.4 million files (stablyai#15209). The same scan cost ~700ms and ran per pane
(stablyai#15036), and a Group Policy or AV block turned it into 'unavailable',
which callers read as 'no evidence' -- which is how a PTY tree survives
its own teardown (stablyai#9045, stablyai#10475).

A Toolhelp32 snapshot answers the same question with no child process.
Measured on Windows 11 with 1050 processes, p50/p95:

  pid+ppid+name          15.9 / 17.5 ms
  +memory +command line  30.6 / 33.7 ms
  Get-CimInstance         706 / 723  ms

Two upstream defects needed patching, both found by running it on real
hardware. The binding requires Spectre-mitigated libraries our agents do
not carry (node-pty is patched the same way). And enumeration stopped
after 1024 processes: on a host with 1051 the module returned exactly
1024, and the querying process was itself among the 27 missing -- a
truncated snapshot silently hides the descendants teardown is looking
for, which is the failure this whole change exists to remove.

Migrated: the foreground/descendant reader (the stablyai#15209 scraper and the
teardown identity gate) and the port scanner's PID attribution. NOT
migrated: the memory collector and three identity probes, which need
Win32_Process.CreationDate and have no native equivalent. Start time is
a proxy for identity anyway; an inherited job handle is the real answer,
so those belong with the job-object work rather than here.

Packaging follows the windows-native-registry contract exactly:
optional, absent from onlyBuiltDependencies so macOS/Linux never run
node-gyp, win32-only in the packaged runtime. Asserted by the existing
contract test, which also stops pinning a whole source literal that only
tested its own formatting.

* chore(process): ratchet the child_process allowlist down

windows-foreground-process-rows.ts no longer spawns anything, so its
allowlist line is stale. The guard fails on a stale entry as well as a
new one, precisely so a migrated file cannot keep a slot open and hide
the next regression in the same path.

* fix(ports): import the process-table reader the scanner uses

Missing import: the migration replaced the PowerShell call but the new
symbol was never imported, so tsc failed. Vitest transpiles without
typechecking, which is why the port-scanner suite stayed green.

* fix(deps): sync this branch's lockfile with its patch set

Same class as the fix on the tip branch: pnpm records a hash per patched
dependency, and this branch introduces the windows-process-tree patch
without its lockfile entry matching. Every job here failed at install
with ERR_PNPM_LOCKFILE_CONFIG_MISMATCH.

Verified with --frozen-lockfile, which is what CI runs and what my local
runs were not.

* test(relay): drive the relay's Windows fixtures from the native snapshot

Two relay cases fed a PowerShell CIM payload through a mocked execFile.
That reader is gone, so both failed -- deterministically, on every PR
run for this branch and the one above it.

I did not catch it because my own verification sweep was
'src/main src/shared config/scripts' and never included src/relay. The
relay is a first-class consumer of the process table; leaving it out of
the sweep is how a deterministic failure survived six review rounds.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant