Skip to content

fix(daemon): preload the windowsHide shim via --require (rc.6 shim was inert) - #7499

Merged
Jinwoo-H merged 1 commit into
mainfrom
Jinwoo-H/daemon-console-shim-preload
Jul 6, 2026
Merged

Jinwoo-H merged 1 commit into
mainfrom
Jinwoo-H/daemon-console-shim-preload

Conversation

@Jinwoo-H

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

Copy link
Copy Markdown
Contributor

Problem

The rc.6 windowsHide shim (#7486) ships in the bundle but does nothing — rc.6 daemons still flash a Windows Terminal window every ~3 seconds. Two independent defeats, found by driving the real probe path on a live rc.6 machine:

  1. Bundler ordering defeats the "first import". Rollup's CJS output hoists chunk require() calls above inlined module code. Confirmed in the shipped daemon-entry.js: the session chunk (containing windows-foreground-process-rows.ts, whose module scope captures promisify(execFile)) evaluates at byte 375; the inlined shim installs at byte 1063. The capture wins; the shim patches nothing anyone uses.
  2. util.promisify.custom bypasses the wrapper. Node's execFile carries a custom promisify implementation that internally calls the original function. The shim copied that symbol verbatim, so promisify(execFile) — exactly what the daemon's CIM probes use — returned Node's original, skipping the injection even when the wrapper was reachable.

Fix

  • The shim is now its own self-contained bundle entry (out/main/windows-hidden-console-children.js, zero chunk requires — verified in the built output) and the daemon fork preloads it with node --require, which Node guarantees runs before the module graph loads. Immune to bundler ordering by construction. Applied only on the relocated-node.exe host path (Electron hosts already default windowsHide=true).
  • wrapChildProcessApi now wraps each symbol-attached function (the promisify customs) with the same windowsHide-default injection instead of copying them verbatim.

Verification (Windows, staged production Node 24 binary)

Ambient rc.6 flashing on the test machine contaminates window-count assertions, so probes set a unique console title (XVER-FLASH-CANARY) and trials assert on canary-titled Windows Terminal windows only:

  • callback-style execFile, no preload: 3/3 trials flash → with preload: 0/6
  • promisify(execFile) (the exact daemon probe shape), no preload: 3/3 flash → with preload: 0/5
  • promisify(execFile) under the preload resolves to the injection wrapper (inspected directly); without it, Node's original
  • built daemon + --require boots and serves getForegroundProcess RPCs end-to-end under a standalone node.exe
  • 14 unit tests including a promisify-bypass regression test; daemon suites green; typecheck clean

Rollout note

Daemons already running from rc.5/rc.6 keep flashing until replaced (they survive updates by design). One Manage Sessions → Restart Daemon after this ships — or updating with no terminals open (staleness check then auto-replaces) — clears it permanently.

The rc.6 shim shipped broken twice over:

1. Bundler ordering: rollup's CJS output hoists chunk requires above
   inlined module code, so daemon-entry's "first import" of the shim ran
   AFTER sibling chunks evaluated `promisify(childProcess.execFile)` at
   module scope. The shim is now its own self-contained bundle entry and
   the daemon fork preloads it with `node --require`, which runs before
   the module graph loads - immune to bundler ordering by construction.

2. promisify bypass: exec/execFile carry a util.promisify.custom
   implementation that calls the ORIGINAL function internally; copying
   the symbol verbatim onto the wrapper let every promisified call site
   (exactly what the daemon's CIM probes use) skip the injection. The
   wrapper now wraps each symbol-attached function with the same
   windowsHide-default injection.

Verified on Windows against the staged production Node 24 binary with
canary-titled probes (attributable amid ambient rc.6 flashing):
plain execFile and promisify(execFile) both flash 100% of trials
without the preload and 0% with it; promisify(execFile) under the
preload resolves to the injection wrapper; built preload bundle has
zero chunk requires; daemon boots and serves getForegroundProcess RPCs
end-to-end under --require.
@Jinwoo-H
Jinwoo-H merged commit 8f396ba into main Jul 6, 2026
1 of 2 checks passed
@Jinwoo-H
Jinwoo-H deleted the Jinwoo-H/daemon-console-shim-preload branch July 6, 2026 05:13
@coderabbitai

coderabbitai Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 9a52296b-0364-4d43-bd30-e66d43a9c8d8

📥 Commits

Reviewing files that changed from the base of the PR and between 8478bab and 415adbd.

📒 Files selected for processing (5)
  • electron.vite.config.ts
  • src/main/daemon/daemon-entry.ts
  • src/main/daemon/daemon-init.ts
  • src/main/daemon/windows-hidden-console-children.test.ts
  • src/main/daemon/windows-hidden-console-children.ts

📝 Walkthrough

Walkthrough

Changes

This change alters how the Windows "hidden console children" shim is applied to the daemon process. The shim's wrapper logic is refactored into an exported wrapChildProcessApi function that also rebinds symbol-attached functions, with updated tests covering direct and promisify-based usage. The shim's static import in daemon-entry.ts is removed and replaced with a Node --require preload configured in daemon-init.ts, using a new dedicated Rollup build entry for the shim file.

Sequence Diagram(s)

See diagrams within the hidden review stack artifact above.

Related PRs: None specified.

Suggested labels: bug, windows, daemon

Suggested reviewers: None specified.

Poem:
A rabbit hops through Windows woods so deep,
Hiding console windows while children sleep,
No more static imports rushed too soon,
Now preloaded shims dance to Rollup's tune,
windowsHide: true — hop, hop, all is neat!

✨ 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.

AmethystLiang added a commit that referenced this pull request Jul 6, 2026
CI test-merges main, which carries the windows-hidden-console-children
test from #7499 (admin-merged with a failing verify). promisify(wrapped)
resolved to its zero-arg overload; cast to the promisify.custom signature
so tsgo accepts the two-arg call.

Co-authored-by: Orca <[email protected]>
AmethystLiang added a commit that referenced this pull request Jul 6, 2026
The windows-hidden-console-children test (from #7499, admin-merged with a
failing verify) failed tsgo: promisify(wrapped) resolved to its zero-arg
overload because the wrapper erased its argument to a bare variadic function
and the fake never statically carried promisify.custom. Preserve the wrapped
type via a generic overload (accurate: the wrapper copies the call signature
and symbols verbatim) and build the fake as a real CustomPromisify, so
promisify routes through the custom overload as it does in production.

Co-authored-by: Orca <[email protected]>
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.
AmethystLiang added a commit that referenced this pull request Jul 6, 2026
* Show all worktrees across all hosts on mobile

Avoid honoring desktop's host-filtering settings since mobile lacks the
UI to manage or unhide them. This prevents worktrees from being silently
hidden under certain host scopes.

Additionally, this removes worktree filtering based on repo metadata, which
previously caused worktrees to vanish when same-named repos on different
hosts collapsed to a single ID.

* fix(daemon): preserve promisify.custom type through wrapChildProcessApi

The windows-hidden-console-children test (from #7499, admin-merged with a
failing verify) failed tsgo: promisify(wrapped) resolved to its zero-arg
overload because the wrapper erased its argument to a bare variadic function
and the fake never statically carried promisify.custom. Preserve the wrapped
type via a generic overload (accurate: the wrapper copies the call signature
and symbols verbatim) and build the fake as a real CustomPromisify, so
promisify routes through the custom overload as it does in production.

Co-authored-by: Orca <[email protected]>

---------

Co-authored-by: Orca <[email protected]>
Jinwoo-H added a commit that referenced this pull request Jul 6, 2026
Records why the #7421->#7499 chain was reverted in #7505 (failure
mechanisms, why verification missed them, non-negotiables), and lays out
the from-scratch plan: proof harness first, relocate the daemon file
closure out of the install dir while keeping the exact Electron runtime,
fix adoption interactivity, and gate every phase on a packaged-artifact
update test.
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…tom (stablyai#7499)

The rc.6 shim shipped broken twice over:

1. Bundler ordering: rollup's CJS output hoists chunk requires above
   inlined module code, so daemon-entry's "first import" of the shim ran
   AFTER sibling chunks evaluated `promisify(childProcess.execFile)` at
   module scope. The shim is now its own self-contained bundle entry and
   the daemon fork preloads it with `node --require`, which runs before
   the module graph loads - immune to bundler ordering by construction.

2. promisify bypass: exec/execFile carry a util.promisify.custom
   implementation that calls the ORIGINAL function internally; copying
   the symbol verbatim onto the wrapper let every promisified call site
   (exactly what the daemon's CIM probes use) skip the injection. The
   wrapper now wraps each symbol-attached function with the same
   windowsHide-default injection.

Verified on Windows against the staged production Node 24 binary with
canary-titled probes (attributable amid ambient rc.6 flashing):
plain execFile and promisify(execFile) both flash 100% of trials
without the preload and 0% with it; promisify(execFile) under the
preload resolves to the injection wrapper; built preload bundle has
zero chunk requires; daemon boots and serves getForegroundProcess RPCs
end-to-end under --require.
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.
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
* Show all worktrees across all hosts on mobile

Avoid honoring desktop's host-filtering settings since mobile lacks the
UI to manage or unhide them. This prevents worktrees from being silently
hidden under certain host scopes.

Additionally, this removes worktree filtering based on repo metadata, which
previously caused worktrees to vanish when same-named repos on different
hosts collapsed to a single ID.

* fix(daemon): preserve promisify.custom type through wrapChildProcessApi

The windows-hidden-console-children test (from stablyai#7499, admin-merged with a
failing verify) failed tsgo: promisify(wrapped) resolved to its zero-arg
overload because the wrapper erased its argument to a bare variadic function
and the fake never statically carried promisify.custom. Preserve the wrapped
type via a generic overload (accurate: the wrapper copies the call signature
and symbols verbatim) and build the fake as a real CustomPromisify, so
promisify routes through the custom overload as it does in production.

Co-authored-by: Orca <[email protected]>

---------

Co-authored-by: Orca <[email protected]>
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