Skip to content

fix(windows): start the WSL holder with only a NUL handle to inherit - #35799

Merged
nwparker merged 2 commits into
mainfrom
nwparker/windows-spawn-handle-list
Oct 29, 2026
Merged

nwparker merged 2 commits into
mainfrom
nwparker/windows-spawn-handle-list

Conversation

@nwparker

@nwparker nwparker commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​425 $\color{#cf222e}{\Huge{\mathbf{−}}}$​5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​420
Prod 20 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​402 $\color{#cf222e}{\Huge{\mathbf{−}}}$​15 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​387

ELI5

When Orca starts a helper program on Windows, Windows copies into it every connection Orca has marked "shareable". The program that keeps a WSL distro awake (the "holder") runs long after Orca does. Anything it receives stays open for that long: a pipe a script is reading Orca's output from, a debugging socket, and so on. This change starts the holder with an explicit list of what it may inherit, and that list holds one "nowhere" handle (NUL) for its input and output. Nothing of Orca's comes along.

What Changed

  • Before:
    • Every Windows child started through Node gets every inheritable handle Orca has open. Node's spawn always turns on "inherit handles" and has no option to limit them.
    • The previous PR stopped Orca's own input, output and error from being inheritable. Any other inheritable handle (for example a DevTools debugging socket, or a pipe end that is briefly inheritable while another spawn is in progress) could still reach the long-lived WSL holder and stay open after Orca exits.
  • After: the WSL holder inherits exactly one handle: a NUL device handle used as its stdin, stdout and stderr. That's what it effectively had before, since it was started with stdio ignored.

Mechanism:

  • Native: native/windows-security adds spawnDetachedIsolated:
    • It opens one NUL handle and calls CreateProcessW with extended startup info whose PROC_THREAD_ATTRIBUTE_HANDLE_LIST contains only that handle.
    • The creation flags match what Node uses for a detached, hidden child (detached, new process group, Unicode environment, hidden window).
    • It reports the exit code through a Windows wait callback that never keeps the event loop alive.
  • process-host: @orca/process-host/isolated-detached-spawn adds spawnDetachedWithoutInheritance:
    • It accepts only the detached, stdio-ignoring shape.
    • It reuses process-host's spawn resolution, including the WSL distro allowlist.
    • It builds the command line and environment block exactly as Node does. This matters because Orca recognises its holder later by that command line.
    • The child it returns has the pid, spawn, error, exit, close, kill and unref surface the holder already used, with libuv's exit and kill reporting.
  • Fallbacks: it falls back to the normal spawn when any of these is true:
    • it's not on Windows;
    • no native spawner is installed (the CLI, the daemon and the relay never install one);
    • the program needs cmd.exe or a relative path lookup.
  • Startup: main installs the native spawner right after clearing the std-handle inheritance. A missing addon, or one built from older source, is logged and leaves the normal spawn in place.
  • WSL holder: src/main/wsl/wsl-distro-holder.ts now spawns through it.
  • Build check: the install and Electron load probes no longer call into the addon. They call currentUserSid() and hasNativeExport('spawnDetachedIsolated'), which reads the binary the package actually resolved. So a binary built from older source still fails the probe and gets rebuilt. The native cache key now covers the new source files.
  • Lane receipt: the WSL lane receipt renames the ConPTY "first paint" to conptyStartupOutputMs (ConPTY's own startup output, not the distro's), and a test comment now says nine distro restarts, not six.

Why

  • The leak path: Node only exposes libuv's spawn flags, and none of them limits inheritance. The only way to start a child without leaking Orca's inheritable handles is our own CreateProcessW with a handle list.
  • Why the holder first: it has the simplest stdio and the longest life, so it is the child most likely to pin a handle after Orca exits.
  • Why not the daemon: it stays on Node's spawn on purpose. It needs a Node IPC channel and a stderr pipe, which only Node's own spawn can create. fix(windows): keep Orca's std handles out of every spawned child #35678 already removed the leak users could see (Orca's std handles). What's left, such as a DevTools socket, only exists in dev and e2e runs. Changing the daemon's launch handshake would put terminal restore at risk for little gain. A possible future option is to detect daemon readiness by connecting to its own endpoint and report startup failures through a per-launch file, which would let it use this same isolated spawn.
  • Alternatives rejected:
    • Clearing the inherit flag on every handle Orca owns isn't possible: Orca can't enumerate them, and Chromium owns many of them.
    • An intermediate launcher process would itself inherit everything.

Linked Issue

N/A (maintainer change; follow-up to #35678 in the WSL host idle-release work).

Visual Proof

N/A. There is no UI change: this only affects which handles Windows copies into the WSL holder process.

Testing

  • process-host unit tests (isolated-detached-spawn.test.ts):

    • the quoting matches every example libuv documents;
    • the environment block is sorted case-insensitively, required variables are filled in from the parent, and it is double-NUL terminated;
    • spawns are routed to the normal spawn off Windows, without a spawner, and for .cmd or relative programs;
    • the native spawner receives the expected command line, working directory and environment;
    • the spawn/exit/error events behave as expected;
    • exits follow libuv's rules: after our own kill() the exit is reported as (null, 'SIGTERM'), and any other exit reports its code, so the holder's "exit code 1 means the distro stopped" rule keeps working;
    • the WSL distro allowlist is still enforced.
  • Startup unit test (windows-isolated-spawner.test.ts): installs the spawner only when the binary exports it; no-op off Windows; never throws.

  • Windows lane (windows-isolated-spawner.win32.test.ts, registered in pr-package-test-paths.mjs):

    • a child whose arguments contain spaces, quotes, backslashes and an empty string receives them byte-for-byte, and its exit code 7 arrives;
    • a kill-and-exit check on both the new path and Node's spawn: our own kill reports (null, 'SIGTERM') and an outside kill reports (1, null);
    • a missing program surfaces as an error event naming CreateProcessW;
    • from a real Electron main process (which keeps its std handles inheritable), the holder started through the new path does not keep the test's pipe open;
    • control: the same holder started through the normal spawn keeps the pipe open until it exits.
  • Local (macOS): pnpm run typecheck:ci, the touched tests, check:code-quality:changed, the ast-grep gates and the process-host import check pass. The native code compiles and runs only in Windows CI.

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

Review

Reviewers: fix-reviewer, e9-reviewer (touches process spawning).

EDR notes:

  • Extended startup info with PROC_THREAD_ATTRIBUTE_HANDLE_LIST is the standard way to limit inheritance; Chromium starts its own child processes this way.
  • No PROC_THREAD_ATTRIBUTE_PARENT_PROCESS, which is parent-PID spoofing and is scored by EDR.
  • No breakaway-from-job flag, no suspended creation and no remote-thread or injection APIs.
  • No new interpreter, PowerShell, cmd.exe /c or runtime code generation.
  • The program is still the absolute wsl.exe path it was before, and the command line is byte-identical to what Node produced.

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Flag-off / User-risk: This is not behind a flag. It changes how the WSL holder starts, and the holder exists only when the WSL host feature is in use. If the addon is missing, stale or fails to load, Orca logs it and starts the holder exactly as before.

  • Remaining risk: a native spawn bug on some Windows version would make holder start fail. That surfaces through the holder's existing error handling, which already treats a failed spawn as no holder.

  • Exit watch: if Windows refuses the exit wait, the holder still runs and Orca logs that its exit is unobservable. The holder's existing liveness check, by pid, creation time and command line, still applies.

  • Security: narrows what the holder inherits; grants nothing new.

  • macOS/Linux: no-op.

  • SSH and remote: unaffected (local process start only).

  • Mobile: unaffected.

  • Performance: one native call per holder start.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

@nwparker
nwparker force-pushed the nwparker/windows-spawn-handle-list branch from fb8dc29 to 340437e Compare October 29, 2026 07:26
@coderabbitai

coderabbitai Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 6 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 10 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 2041fefa-ef4f-458f-aed1-09a17c5c3071
Commits

Reviewing files that changed from the base of the PR and between 340437e and bd30fce.

Files selected for processing: 26
  • .github/actions/prepare-native-runtime/action.yml
  • config/scripts/ensure-native-runtime.mjs
  • config/scripts/ensure-native-runtime.test.mjs
  • config/scripts/pr-package-test-paths.mjs
  • config/scripts/rebuild-native-deps-test-fixtures.mjs
  • config/scripts/rebuild-native-deps.mjs
  • native/windows-security/binding.gyp
  • native/windows-security/index.d.ts
  • native/windows-security/index.js
  • native/windows-security/package.json
  • native/windows-security/src/addon.cc
  • native/windows-security/src/isolated-spawn.cc
  • native/windows-security/src/isolated-spawn.h
  • src/main/index.ts
  • src/main/startup/windows-install-dir-package-acl-grant.test.ts
  • src/main/startup/windows-isolated-spawn-electron-fixture.ts
  • src/main/startup/windows-isolated-spawner.test.ts
  • src/main/startup/windows-isolated-spawner.ts
  • src/main/startup/windows-isolated-spawner.win32.test.ts
  • src/main/wsl/wsl-distro-holder.ts
  • src/main/wsl/wsl-orcad-real-distro-idle-release-lane.test.ts
  • src/packages/process-host/package.json
  • src/packages/process-host/src/isolated-detached-spawn.test.ts
  • src/packages/process-host/src/isolated-detached-spawn.ts
  • src/shared/windows-security-addon.test-fixture.ts
  • src/shared/windows-security-addon.ts

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 90ff330a-728d-46cf-bcf8-18474e3edb6e
Commits

Reviewing files that changed from the base of the PR and between 3633c1b and 340437e.

Files selected for processing: 26
  • .github/actions/prepare-native-runtime/action.yml
  • config/scripts/ensure-native-runtime.mjs
  • config/scripts/ensure-native-runtime.test.mjs
  • config/scripts/pr-package-test-paths.mjs
  • config/scripts/rebuild-native-deps-test-fixtures.mjs
  • config/scripts/rebuild-native-deps.mjs
  • native/windows-security/binding.gyp
  • native/windows-security/index.d.ts
  • native/windows-security/index.js
  • native/windows-security/package.json
  • native/windows-security/src/addon.cc
  • native/windows-security/src/isolated-spawn.cc
  • native/windows-security/src/isolated-spawn.h
  • src/main/index.ts
  • src/main/startup/windows-install-dir-package-acl-grant.test.ts
  • src/main/startup/windows-isolated-spawn-electron-fixture.ts
  • src/main/startup/windows-isolated-spawner.test.ts
  • src/main/startup/windows-isolated-spawner.ts
  • src/main/startup/windows-isolated-spawner.win32.test.ts
  • src/main/wsl/wsl-distro-holder.ts
  • src/main/wsl/wsl-orcad-real-distro-idle-release-lane.test.ts
  • src/packages/process-host/package.json
  • src/packages/process-host/src/isolated-detached-spawn.test.ts
  • src/packages/process-host/src/isolated-detached-spawn.ts
  • src/shared/windows-security-addon.test-fixture.ts
  • src/shared/windows-security-addon.ts

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

Walkthrough

The Windows security addon adds a native detached-spawn function with restricted handle inheritance and exit notification. The process-host package adds a cross-platform API that uses this function for eligible Windows commands and falls back to spawnProcess otherwise. Application startup installs the native spawner on Windows, and the WSL distro holder uses the new API. The changes also add native runtime checks and spawn tests, and rename a ConPTY startup-output metric in a WSL test.

Priority: Normal

Merge Risk: Minimal · previous review 34043

No identified issue remains that should block merging. The Windows-specific tests should run in CI as planned.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 69.23% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title "fix(windows): start the WSL holder with only a NUL handle to inherit" names the main change. The PR adds a native CreateProcessW spawn that limits the WSL holder's inherited handles to one …
Description check Passed The description follows the repository template closely. It includes ELI5, What Changed, Why, Testing, Review, Notes, and Checklist sections. It explains the before and after behavior, the native and …
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: Title check

Explanation

The title "fix(windows): start the WSL holder with only a NUL handle to inherit" names the main change. The PR adds a native CreateProcessW spawn that limits the WSL holder's inherited handles to one NUL handle. The title is specific and matches the changeset and objectives. It uses a conventional commit prefix, and at 68 characters it stays within a readable length.

Full details: Description check

Explanation

The description follows the repository template closely. It includes ELI5, What Changed, Why, Testing, Review, Notes, and Checklist sections. It explains the before and after behavior, the native and process-host mechanism, the fallbacks, the rejected alternatives, and the EDR considerations. Testing lists the unit, Windows lane, and macOS checks. The Linked Issue section says N/A and gives a reason, not an issue link. The template requires a link for outside contributors, but the author is a maintainer, so this gap is minor. The AI Disclosure section is empty, which the template allows for internal team members. Some checklist items remain unchecked, including the lint, typecheck, test, and build run, and the author notes that native code runs only in Windows CI. The description is substantially complete.

Full details: Docstring Coverage

Explanation

Docstring coverage is 69.23% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 13 functions across 22 files. (4 skipped: 4 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@greptile-apps

greptile-apps Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no actionable new issue was established.

Summary

Starts the Windows WSL holder with an explicit inheritance list containing only a NUL handle.

  • The WSL holder starts without inheriting Orca’s other Windows handles.
  • The WSL lane receipt names ConPTY startup output directly.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Desktop startup] --> B{Native export available?}
  B -->|Yes| C[Install isolated spawner]
  B -->|No| D[Keep ordinary spawn]
  C --> E[WSL holder requested]
  E --> F[Check distro allowlist and resolve program]
  F --> G{Absolute program without cmd quoting?}
  G -->|Yes| H[CreateProcessW with only NUL inherited]
  G -->|No| D
  H --> I[Report child exit to holder]
Loading

Reviews (2) · Last reviewed commit: "fix(windows): report isolated holder exi..." · Reviewed by Greptile

libuv starts every Windows child with bInheritHandles=TRUE and no handle
list, so a detached holder that outlives Orca kept any inheritable handle
Orca had open, such as a launcher's pipe or a DevTools socket. Start it
through CreateProcessW with PROC_THREAD_ATTRIBUTE_HANDLE_LIST naming one NUL
handle for its stdio. The build probes now check the newest export without
calling it, and the lane receipt labels ConPTY's own startup output.
@nwparker
nwparker force-pushed the nwparker/windows-spawn-handle-list branch from 340437e to bd30fce Compare October 29, 2026 09:25
@nwparker
nwparker merged commit 9f62a4f into main Oct 29, 2026
89 checks passed
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