Repository navigation
Relocate node-pty ConPTY runtime outside the Windows install dir (fixes update-time terminal loss) - #7421
Conversation
Root cause of update-time terminal loss (verified with a reproduction harness running the installer sweep commands verbatim): the NSIS update installer force-closes every process whose image path is under the install directory. Since #6968 started bundling conpty.dll and OpenConsole.exe under resources/, every live terminal's console host - and with 2+ matches the daemon too - is killed mid-update. Before #6968 the daemon was the only install-dir process and survived only by luck: the sweep's find step does (...).Count -gt 0, and in Windows PowerShell 5.1 a single-instance CIM result has null Count, so one match reads as "nothing running". Fix: copy the node-pty native runtime (conpty binding + conpty.dll + OpenConsole.exe + winpty) to userData/node-pty-runtime/<version>/ at startup and point the node-pty loader at it via ORCA_NODE_PTY_NATIVE_DIR (loader override added to the existing node-pty patch; falls through to the stock search paths on any failure). The daemon inherits the env var, so console hosts for both main- and daemon-owned PTYs run outside the installer kill zone. Stale version dirs are removed only when a rename probe proves nothing inside is still running. Verified end-to-end against the verbatim sweep: with the relocated runtime, OpenConsole spawns from userData, the sweep finds nothing to kill, and daemon + shell + console host all survive.
Reproduction harness evidence (installer sweep commands run verbatim against disposable topologies)Topology legs (sweep-repro.mjs)Single-match .Count blind spot (Windows PowerShell 5.1)Post-fix end-to-end (fix-verify.mjs: patched loader + relocated runtime + verbatim sweep) |
📝 WalkthroughWalkthroughChangesThis PR adds Windows-only relocation of node-pty native binaries into a versioned user-data directory, then points node-pty at that directory through an environment variable before the first PTY load. It also patches node-pty’s native loader to try the relocated path first, and adds tests for source resolution, copy and cleanup behavior, and the override path. Separately, the patch updates some Windows build settings, hardens native helper path rewriting, and makes console-list and spawn error handling more resilient. Related issues: None provided 🚥 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: 5
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 1de08489-4548-4d9b-917c-f2d8b200476b
⛔ 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/index.tssrc/main/pty/node-pty-runtime-relocation.test.tssrc/main/pty/node-pty-runtime-relocation.ts
The update relaunch chain (old app -> installer -> new app) inherits ORCA_NODE_PTY_NATIVE_DIR from the previous version, so honoring a pre-set value would pin the new process to stale binaries and skip copying the current version. Also restore any pre-existing override in the loader integration test instead of unconditionally deleting it.
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/main/pty/node-pty-runtime-relocation.ts (1)
134-136: 🩺 Stability & Availability | 🟠 Major | ⚡ Quick winClear an inherited stale override when relocation fails.
The comment on Lines 114-117 states a pre-set
ORCA_NODE_PTY_NATIVE_DIR(inherited from the previous version via the update relaunch chain) must not pin the new process to stale binaries. That guarantee only holds on the success path. WhenensureRelocatedNodePtyNativeRuntimereturnsnull, the env var is left untouched, so the inherited stale value survives inprocess.envand is honored by the patched loader (and by the forked daemon). This breaks the documented fail-open behavior of loading from the install directory and can pin the new process to a previous version's runtime dir.🛡️ Proposed fix
if (destDir) { process.env[NODE_PTY_NATIVE_DIR_ENV_VAR] = destDir + } else { + // Relocation failed: drop any inherited stale override so node-pty + // falls back to the install-dir runtime instead of a previous version's dir. + delete process.env[NODE_PTY_NATIVE_DIR_ENV_VAR] }
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 816c7b70-47ac-4e69-9927-2f0c6a2cd929
📒 Files selected for processing (2)
src/main/pty/node-pty-runtime-relocation.test.tssrc/main/pty/node-pty-runtime-relocation.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- src/main/pty/node-pty-runtime-relocation.test.ts
Re-based onto the current shared remote tip (4110c29, which already carried an older main sync + windows-update-daemon-adoption); this brings in the 18 newer main commits through v1.4.124-rc.1. MERGE, not rebase. Conflict resolutions (our structure wins; main's semantics graft in): - update-check feature (update-check-click-options.ts + test, GeneralUpdateSettingsSection.tsx, SidebarSettingsHelpMenu.tsx + test, updater.ts + test): took main's shape — getUpdateCheckHint() centralizes the RC/perf hint, pointerdown modifier-capture handler, and the refined `checkVariant === 'prerelease'` guard so a perf check never permanently opts background retries into the RC channel. getUpdateCheckClickOptions (the actual behavior) was byte-identical on both sides. - Ctrl+K clear vs producer flow control (pty-subprocess.ts, session.ts, session.test.ts): kept BOTH — our pause()/resume() flow-control methods AND main's clear() ConPTY screen-state resync (#7413). Orthogonal. - orca-runtime.ts: took main's public visibility on clearHeadlessTerminalBuffer (ipc/pty.ts Ctrl+K path calls it); dropped main's createHeadlessEmulator factory — our Phase-5 query-authority emulator construction is restructured and has no caller for it. Incoming (auto-merged, off the byte-delivery path): #6277 agent cold- restore fallback (pty-connection.ts), node-pty ConPTY relocation (#7421), MiniMax rate limits, translations. Gates: typecheck 0 errors; ipc+daemon+terminal-pane+pane-manager 4204 passed; both fuzz suites pass; hand-resolved renderer files pass. No delivery/restore/flow-control/ACK/batching/scheduler bytes changed, so no 10MB bench required. Co-authored-by: Orca <[email protected]>
The terminal daemon was fork()ed with no explicit execPath, so its process image was the install-dir Orca.exe run via ELECTRON_RUN_AS_NODE. On Windows, the NSIS installer's CHECK_APP_RUNNING sweep force-kills processes whose image lives under the install directory, so an app update killed the live daemon and every terminal it hosted (including the user's running Claude process). Relocate the daemon host image out of the install dir: stage a standalone, version-correct node.exe under %APPDATA%\orca\daemon-host\<appVersion>\ and fork the daemon from it. The daemon's image now lives in userData, outside the installer's kill zone, so it survives updates. Fail-open: if no relocated node.exe is present, fall back to the current Orca.exe + ELECTRON_RUN_AS_NODE path (zero regression). Adoption and stale-kill are unaffected — process identification matches on daemon-entry/socket/token args and the unchanged entryPath, never the host image name. Build: afterPack stages the build host's own official (OpenJS-signed) Node 24.x node.exe into resources/daemon-host/node.exe. engines.node="24" pins the build host to the ABI Electron 42 embeds (Node 24.15, NAPI 10) so the relocated host loads node-pty's NAPI conpty.node addon. Shipping the OpenJS-signed binary means it is validly signed regardless of whether SignPath re-signs nested PEs. Extract the version-keyed copy + daemon-pinned GC shared by the node-pty native relocation (#7421) into install-dir-runtime-relocation.ts and reuse it for the host relocation. CI verify step + contract/config tests guard the staging.
) (#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.
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.
…es update-time terminal loss) (stablyai#7421)
…#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.
Summary
Windows terminal sessions die on every app update since June 30 because the NSIS update installer force-closes every process running from the install directory — and #6968 moved the ConPTY console hosts into it. This PR relocates node-pty's native runtime (
conpty.node,conpty.dll,OpenConsole.exe, winpty binaries) touserData/node-pty-runtime/<version>/, taking terminal infrastructure out of the installer's kill zone. Verified end-to-end against the installer's verbatim kill commands.Root cause (reproduction-harness verified, not inferred)
electron-builder's NSIS template (
allowOnlyOneInstallerInstance.nsh, unchanged in this repo since the initial commit) runsCHECK_APP_RUNNINGduring every update install:Three facts, each demonstrated by running these commands verbatim against disposable process topologies (harness output in the PR comments):
CimInstancewhose.Countis$null, so-gt 0is false and the installer concludes "nothing running" and kills nothing. Pre-Fix Windows bundled ConPTY packaging #6968, terminals used the System32 console host, so the detached daemon was the only install-dir process → single match → spared on every update. Same-process daemon survival across updates was real — and an accident.OpenConsole.exeinstances now underresources/, there are 2+ matches,.Countworks, and the sweep kills the daemon and every console host mid-install. Killing a console host kills its attached shell (reproduced; matches theGetConsoleScreenBufferInfoconsole-loss crashes Windows Error Reporting captured during the July 4 and July 5 update windows on the incident machine — and at no June update).OpenConsole.exespawns from userData, FIND reports nothing (the daemon is again the sole install-dir process, back under the single-match umbrella), and daemon + shell + console host all survive the sweep.This also corrects the earlier working theory: the update-relaunch wedge-kill path fixed in #7340 is real and reproducible, but the installer sweep — not that path — is what killed sessions in the July incidents.
Fix
config/patches/[email protected]):loadNativeModulehonorsORCA_NODE_PTY_NATIVE_DIRbefore its stock search paths, falling through on any failure. The native side already resolvesconpty.dll(and spawnsOpenConsole.exe) fromconpty/beside the loaded binding, so relocating the binding relocates the console hosts.src/main/pty/node-pty-runtime-relocation.ts: at startup (win32 + packaged only), copy the binding dir (rebuiltbuild/Release, fallback platform prebuilds;.pdbexcluded) touserData/node-pty-runtime/<appVersion>/and set the env var. Crash-safe via a completion marker (partial copies redone). The forked daemon inherits the env, covering daemon-owned PTYs.Verification
ORCA_NODE_PTY_NATIVE_DIRpointing at a relocated runtime; real ConPTY session with a livepowershell.exe.OpenConsole.exeverified running from the relocated dir; the verbatim installer FIND/KILL sequence found nothing and daemon, shell, and console host all survived. Control legs: pre-fix (July) topology → all killed; pre-Fix Windows bundled ConPTY packaging #6968 (June) topology → all spared via the single-match blind spot.node-pty-runtime-relocation.test.ts): source-dir resolution order, tree copy without symbols, marker idempotency, interrupted-copy recovery, stale-version cleanup keeping the current version, fail-open on missing source — plus a win32 integration test loading the real conpty binding through the patched loader from a relocated dir.terminal-cwd-realpath.test.ts, untouched by this change and identical on the base branch).Follow-ups (not in this PR)
INSTDIR\Orca.exe; today it survives via the single-match blind spot. Moving its image out of the install dir makes survival principled instead of accidental (and is the fix that remains correct if electron-builder ever repairs the.Countcheck upstream)..Countbug means the sweep silently skips exactly-one-process cases for every Electron app; conversely apps with detached helpers under the install dir lose them whenever there are 2+.