Repository navigation
fix(daemon): hide console windows for children of the node.exe-hosted daemon - #7486
Conversation
Since #7473 the terminal daemon runs under a standalone node.exe. Electron's bundled Node defaults windowsHide to true; plain node.exe defaults it to false, so every child_process call in the daemon that does not pass the flag - the periodic PowerShell CIM process probes, node-pty's kill-path conpty_console_list_agent fork - now allocates a visible console, which opens and closes a Windows Terminal window on the user's screen every few seconds. Fix: daemon-entry installs a child_process shim (first import, before any module captures bindings like promisify(execFile)) that defaults windowsHide: true across spawn/exec/execFile/fork and their sync variants, restoring the Electron default the daemon has always relied on. Explicit windowsHide from a caller still wins. Also adds windowsHide to node-pty's console-list agent fork in the existing patch as defense in depth. Verified on Windows: reproduced the flash with the rc.5 production daemon (WindowsTerminal windows, ~3s cadence matching the CIM probe interval, conhost spawned visible-capable "0x4"); with the shim, a node.exe-hosted daemon's children (OpenConsole, powershell, node helpers) all run without a visible-capable console and session kill still works end to end.
📝 WalkthroughWalkthroughChangesThis pull request patches the bundled node-pty dependency to remove Windows Spectre mitigation build flags, fix batch script paths, hide console windows on Windows spawns, guard against duplicate asar path rewriting, add a native module directory override, and replace a simple integer error code with a structured error object carrying step/errno/detail information across the Unix PTY spawn implementation, including unified error cleanup. Separately, a new module is added that patches Node's child_process APIs (spawn, exec, fork variants) on Windows to default windowsHide to true, preserving function metadata and prototype chains, along with unit tests. This module is imported early in the daemon entrypoint before other modules are loaded. Sequence Diagram(s)Diagrams included in the hidden review stack artifact illustrate the PTY spawn error-handling flow and the child_process windowsHide patching flow. Estimated code review effort: 3/5 (moderate-to-high; native C++ error handling changes require careful review) Related issues: None specified Related PRs: None specified Suggested labels: windows, node-pty, daemon Suggested reviewers: None specified 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.
Actionable comments posted: 1
🧹 Nitpick comments (2)
src/main/daemon/windows-hidden-console-children.ts (2)
3-13: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueModule docstring exceeds the "1-2 line" comment guideline.
This nine-line rationale block is valuable context, but as per coding guidelines,
**/*.{ts,tsx,js,jsx}comments explaining non-obvious behavior should be "one or two lines, capturing only the non-obvious reason." Consider trimming to the essential why (Electron vs. bare node.exewindowsHidedefault mismatch) and moving the fuller narrative to the PR description or a linked doc.Source: Coding guidelines
54-70: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winConsider adding install-behavior tests, not just argument-shape tests.
withHiddenConsoleDefaulthas good coverage, butinstallHiddenConsoleChildDefaultsitself — the platform guard, install-once idempotency, and the promisify-symbol copy viaObject.setPrototypeOf/getOwnPropertySymbols— has no direct test. Since this function is what actually gets wired into the daemon, a regression here (e.g. breakingutil.promisify(execFile)) wouldn't be caught by the current suite.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: fa67fb53-a175-447e-a0fd-4a4f26e8aaed
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (4)
config/patches/[email protected]src/main/daemon/daemon-entry.tssrc/main/daemon/windows-hidden-console-children.test.tssrc/main/daemon/windows-hidden-console-children.ts
| export function withHiddenConsoleDefault(args: unknown[]): unknown[] { | ||
| for (let i = 1; i < args.length; i++) { | ||
| if (isPlainOptionsObject(args[i])) { | ||
| const next = [...args] | ||
| next[i] = { windowsHide: true, ...(args[i] as Record<string, unknown>) } | ||
| return next | ||
| } | ||
| } | ||
| // No options object: insert one before a trailing callback, else append. | ||
| const next = [...args] | ||
| const insertAt = typeof next.at(-1) === 'function' ? next.length - 1 : next.length | ||
| next.splice(insertAt, 0, { windowsHide: true }) | ||
| return next | ||
| } |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
git ls-files src/main/daemon/windows-hidden-console-children.ts src/main/daemonRepository: stablyai/orca
Length of output: 3721
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo '--- outline ---'
ast-grep outline src/main/daemon/windows-hidden-console-children.ts --view expanded || true
echo '--- file ---'
wc -l src/main/daemon/windows-hidden-console-children.ts
sed -n '1,220p' src/main/daemon/windows-hidden-console-children.ts
echo '--- usages ---'
rg -n "withHiddenConsoleDefault|windows-hidden-console-children" src/main/daemon src/main -g '!**/*.map'Repository: stablyai/orca
Length of output: 6601
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo '--- test file ---'
sed -n '1,220p' src/main/daemon/windows-hidden-console-children.test.ts
echo '--- current helper behavior for explicit undefined ---'
python3 - <<'PY'
def withHiddenConsoleDefault(args):
def is_plain(v):
return isinstance(v, dict)
for i in range(1, len(args)):
if is_plain(args[i]):
next_args = list(args)
next_args[i] = {'windowsHide': True, **args[i]}
return next_args
next_args = list(args)
insert_at = len(next_args) - 1 if callable(next_args[-1]) else len(next_args)
next_args[insert_at:insert_at] = [{'windowsHide': True}]
return next_args
def cb():
pass
print(withHiddenConsoleDefault(['cmd.exe', None, cb]))
print(withHiddenConsoleDefault(['cmd.exe', cb]))
PYRepository: stablyai/orca
Length of output: 2133
🌐 Web query:
Node.js child_process.exec command options callback undefined extra arguments implementation callback position
💡 Result:
In Node.js, the child_process.exec method follows the signature child_process.exec(command[, options][, callback]) [1][2]. The callback function is optional and is invoked when the child process terminates. It is called with exactly three arguments: (error, stdout, stderr) [1][2]. 1. error: If the process terminates with a non-zero exit code or is killed by a signal, this is an Error object. On success, it is null [1][2]. 2. stdout: The standard output of the child process. It is typically a string, or a Buffer if the encoding option is set to 'buffer' [1][2]. 3. stderr: The standard error output of the child process, also returned as a string or Buffer based on the encoding option [1][2]. There are no additional arguments passed to the callback by Node.js [1][2]. If you need to access extra variables within your callback, the standard approach is to use a closure by defining the callback inside the scope where your extra variables are available, or by using a wrapper function [3].
Citations:
- 1: https://nodejs.org/docs/latest-v26.x/api/child_process.html
- 2: https://github.com/nodejs/node/blob/master/doc/api/child_process.md
- 3: https://stackoverflow.com/questions/15971589/how-can-i-pass-argument-to-child-process-exec-callback
🌐 Web query:
Node.js child_process exec implementation options undefined callback argument shifting normalizeExecArgs source
💡 Result:
In Node.js, the child_process.exec method provides a flexible API that supports optional arguments. The normalizeExecArgs function is the internal utility responsible for standardizing these arguments before execution [1][2]. Functionality and Argument Shifting The normalizeExecArgs(command, options, callback) function handles cases where the options argument is omitted [1][2]. Because options is optional, users can call exec(command, callback) [3]. In this scenario, the callback is passed as the second argument, which would normally be occupied by options [1]. The normalizeExecArgs function performs the following logic to handle this: 1. It checks if the options argument is a function [1][2]. 2. If it is, the function treats that argument as the callback, shifts it, and sets options to undefined [1][2]. 3. It then ensures options is an object (or defaults to an empty object) and returns a standardized object containing the file (command), options, and callback [1][2]. Historical Implementation Historically, normalizeExecArgs relied on the arguments object to handle the variable number of parameters, which was found to cause deoptimization in the V8 engine [1][4]. Modern implementations have been refactored to use explicit named parameters in function signatures and avoid the direct use of the arguments object to maintain performance and code clarity [5][1][6]. Example Logic (Simplified) The core logic within normalizeExecArgs follows this pattern: function normalizeExecArgs(command, options, callback) { if (typeof options === 'function') { callback = options; options = undefined; } // Standardize options and return return { file: command, options: options || {}, callback }; } [1][2]
Citations:
- 1: nodejs/node@b46cf35
- 2: http://blog.safia.rocks/2018/01/05/node-module-deep-dive-childprocess/
- 3: https://github.com/nodejs/node/blob/master/doc/api/child_process.md
- 4: child_process: fix deoptimizing use of arguments nodejs/node#11535
- 5: nodejs/node@56e7e4f0cd
- 6: nodejs/node@3f93782
Handle explicit undefined/null options before the callback.
exec(cmd, undefined, cb) (and the same pattern with null) becomes [cmd, undefined, { windowsHide: true }, cb] here, so child_process.exec receives the callback as a 4th argument and never binds it. Treat a placeholder options slot as “no options” instead of inserting a new one.
🧰 Tools
🪛 ast-grep (0.44.1)
[warning] Importing child_process exposes a command-execution surface; ensure any command/argument built from input is validated, and prefer execFile/spawn with an argument array over exec.
Context: import childProcess from 'node:child_process'
Note: [CWE-78] Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection').
(detect-child-process-typescript)
) (#7505) * Revert "Preload the daemon windowsHide shim via --require; wrap promisify custom (#7499)" This reverts commit 8f396ba. * Revert "Hide console windows for children of the node.exe-hosted daemon (#7486)" This reverts commit f0fdd3a. * Revert "fix(daemon): relocate daemon host image out of the install-dir kill zone (#7473)" This reverts commit f4faafa. * Revert "fix(pty): keep runtime dirs a surviving daemon still uses (#7463)" This reverts commit 3cd23a1. * Revert "Relocate node-pty ConPTY runtime outside the Windows install dir (fixes update-time terminal loss) (#7421)" This reverts commit 509c41e.
…lyai#7486) Since stablyai#7473 the terminal daemon runs under a standalone node.exe. Electron's bundled Node defaults windowsHide to true; plain node.exe defaults it to false, so every child_process call in the daemon that does not pass the flag - the periodic PowerShell CIM process probes, node-pty's kill-path conpty_console_list_agent fork - now allocates a visible console, which opens and closes a Windows Terminal window on the user's screen every few seconds. Fix: daemon-entry installs a child_process shim (first import, before any module captures bindings like promisify(execFile)) that defaults windowsHide: true across spawn/exec/execFile/fork and their sync variants, restoring the Electron default the daemon has always relied on. Explicit windowsHide from a caller still wins. Also adds windowsHide to node-pty's console-list agent fork in the existing patch as defense in depth. Verified on Windows: reproduced the flash with the rc.5 production daemon (WindowsTerminal windows, ~3s cadence matching the CIM probe interval, conhost spawned visible-capable "0x4"); with the shim, a node.exe-hosted daemon's children (OpenConsole, powershell, node helpers) all run without a visible-capable console and session kill still works end to end.
…#7421→stablyai#7499) (stablyai#7505) * Revert "Preload the daemon windowsHide shim via --require; wrap promisify custom (stablyai#7499)" This reverts commit b5710ee. * Revert "Hide console windows for children of the node.exe-hosted daemon (stablyai#7486)" This reverts commit 081cf2f. * Revert "fix(daemon): relocate daemon host image out of the install-dir kill zone (stablyai#7473)" This reverts commit 38c2e2e. * Revert "fix(pty): keep runtime dirs a surviving daemon still uses (stablyai#7463)" This reverts commit 01ad86a. * Revert "Relocate node-pty ConPTY runtime outside the Windows install dir (fixes update-time terminal loss) (stablyai#7421)" This reverts commit 24d599f.
Problem
Since #7473 the terminal daemon runs under a standalone
node.exehost. Electron's bundled Node patches thewindowsHidedefault to true; plainnode.exedefaults it to false. The daemon's spawn call sites (periodic PowerShell CIM process probes, node-pty's kill-pathconpty_console_list_agentfork) never pass the flag because they never needed to — so on rc.5, every probe allocates a visible console, and users watch a Windows Terminal window open and close every ~3 seconds.Field evidence (rc.5 machine): the live daemon spawns its CIM probe (
Get-CimInstance Win32_Process -Property CommandLine,ExecutablePath...) on a ~3s cadence with a visible-capableconhost.exe 0x4; each one surfaces as a WindowsTerminal window titled "Windows PowerShell". Reproduced deterministically in an isolated harness — removingwindowsHidefrom a single fork produced the exact flashing; a window-watcher caught the WT windows appearing on the probe cadence, not at kill time only.Fix
daemon-entrynow installs achild_processshim as its first import (before any module captures bindings likepromisify(execFile)): defaultswindowsHide: trueacrossspawn/exec/execFile/forkand sync variants, restoring the Electron default the daemon has always implicitly relied on. Caller-providedwindowsHide(evenfalse) wins. Promisify custom symbols are preserved.windowsHide: trueto theconpty_console_list_agentfork (defense in depth; that fork runs on every ConPTY session kill).Why a shim and not per-call-site flags
The affected call sites span our code and dependencies (node-pty), and any future spawn added to the daemon would silently regress.
windowsHide(CREATE_NO_WINDOW) gives the child an invisible console that its own descendants attach to, so the shim contains the whole tree. Gated to win32; installing under an Electron host is a harmless no-op difference.Verification (Windows, real daemon under standalone node.exe)
OpenConsole.exe,powershell.exe, node helpers) run with no visible-capable console (conhost --headless/none, never0x4), and the kill still works end to end.