Skip to content

fix(daemon): hide console windows for children of the node.exe-hosted daemon - #7486

Merged
Jinwoo-H merged 1 commit into
mainfrom
Jinwoo-H/hide-conpty-console-list-window
Jul 6, 2026
Merged

Jinwoo-H merged 1 commit into
mainfrom
Jinwoo-H/hide-conpty-console-list-window

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Problem

Since #7473 the terminal daemon runs under a standalone node.exe host. Electron's bundled Node patches the windowsHide default to true; plain node.exe defaults it to false. The daemon's spawn call sites (periodic PowerShell CIM process probes, node-pty's kill-path conpty_console_list_agent fork) 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-capable conhost.exe 0x4; each one surfaces as a WindowsTerminal window titled "Windows PowerShell". Reproduced deterministically in an isolated harness — removing windowsHide from 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-entry now installs a child_process shim as its first import (before any module captures bindings like promisify(execFile)): defaults windowsHide: true across spawn/exec/execFile/fork and sync variants, restoring the Electron default the daemon has always implicitly relied on. Caller-provided windowsHide (even false) wins. Promisify custom symbols are preserved.
  • The existing node-pty patch also adds windowsHide: true to the conpty_console_list_agent fork (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)

  • Control: without the fix, the kill-path fork flashed WindowsTerminal windows (watcher caught 3 in one kill).
  • Fixed: built bundle + node.exe host, live ConPTY session, busy child process, session kill — all daemon children (OpenConsole.exe, powershell.exe, node helpers) run with no visible-capable console (conhost --headless/none, never 0x4), and the kill still works end to end.
  • 12 new unit tests for the argument-shape handling; full daemon suite green (2 pre-existing win32-environment failures reproduce identically on clean main); typecheck clean.

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

coderabbitai Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Changes

This 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:
A rabbit hops through consoles dark,
Hiding windows, leaving no stark mark.
Spawn errors now speak with clearer voice,
Step by step, errno by choice.
Windows hide, PTYs run true—
A tidy patch for me and you. 🐇

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description covers the fix and verification, but it does not follow the required template and omits several required sections. Rewrite it to match the template: add Summary, Screenshots, Testing checklist, AI Review Report with cross-platform checks, Security Audit, and Notes.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the main change: hiding child-process consoles for the Windows daemon.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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.

@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 (2)
src/main/daemon/windows-hidden-console-children.ts (2)

3-13: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Module 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.exe windowsHide default mismatch) and moving the fuller narrative to the PR description or a linked doc.

Source: Coding guidelines


54-70: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Consider adding install-behavior tests, not just argument-shape tests.

withHiddenConsoleDefault has good coverage, but installHiddenConsoleChildDefaults itself — the platform guard, install-once idempotency, and the promisify-symbol copy via Object.setPrototypeOf/getOwnPropertySymbols — has no direct test. Since this function is what actually gets wired into the daemon, a regression here (e.g. breaking util.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

📥 Commits

Reviewing files that changed from the base of the PR and between f6ba214 and 6c9fd68.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (4)
  • config/patches/[email protected]
  • src/main/daemon/daemon-entry.ts
  • src/main/daemon/windows-hidden-console-children.test.ts
  • src/main/daemon/windows-hidden-console-children.ts

Comment on lines +39 to +52
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
}

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 | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

git ls-files src/main/daemon/windows-hidden-console-children.ts src/main/daemon

Repository: 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]))
PY

Repository: 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:


🌐 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:


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)

@Jinwoo-H
Jinwoo-H merged commit f0fdd3a into main Jul 6, 2026
2 checks passed
@Jinwoo-H
Jinwoo-H deleted the Jinwoo-H/hide-conpty-console-list-window branch July 6, 2026 04:26
Jinwoo-H added a commit that referenced this pull request Jul 6, 2026
) (#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.
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…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.
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…#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.
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