Repository navigation
fix(win): harden startup during partial updates - #11613
Conversation
| const EXTERNAL_MAIN_DEPENDENCIES = Object.keys(packageJson.dependencies).filter( | ||
| (dependency) => !BUNDLED_MAIN_DEPENDENCIES.has(dependency) | ||
| ) | ||
| const BOOTSTRAP_FATAL_EXIT_GUARD_KEY = '__ORCA_BOOTSTRAP_FATAL_EXIT_GUARD__' |
There was a problem hiding this comment.
The guard key is declared independently here as a local
const and in src/main/startup/bootstrap-fatal-exit-guard.ts as an exported constant. The two values must always match: the build-time code embeds the local copy into the generated banner string, while the runtime and tests import the source-module copy. If they ever diverge the banner will install the guard under a key that removeBootstrapFatalExitGuard never cleans up, silently leaving a stale uncaughtException listener on the process. The contract test catches this only at test-run time, not at the import site. Importing the single exported constant would eliminate the coupling.
| const BOOTSTRAP_FATAL_EXIT_GUARD_KEY = '__ORCA_BOOTSTRAP_FATAL_EXIT_GUARD__' | |
| import { BOOTSTRAP_FATAL_EXIT_GUARD_KEY } from './src/main/startup/bootstrap-fatal-exit-guard' |
Greptile SummaryThis PR hardens Electron startup against the Windows NSIS non-transactional install race where
Confidence Score: 4/5Safe to merge; the fix is targeted, well-tested, and the generated guard integrates cleanly with the existing source-level error handling. The logic is correct: zod is bundled in, the bootstrap listener is installed before any require calls, and it is removed without a coverage gap when the durable handler takes over. The one thing worth cleaning up before long-term maintenance becomes a burden is that BOOTSTRAP_FATAL_EXIT_GUARD_KEY lives independently in two files; if they diverge the stale listener silently persists, but the contract test would catch it at test-run time. No functional defects were found. Files Needing Attention: electron.vite.config.ts — the locally re-declared BOOTSTRAP_FATAL_EXIT_GUARD_KEY should ideally be imported from bootstrap-fatal-exit-guard.ts to avoid a hidden coupling.
|
| Filename | Overview |
|---|---|
| electron.vite.config.ts | Adds zod to BUNDLED_MAIN_DEPENDENCIES, exports createBootstrapFatalExitBanner, and renames the bootstrap plugin; BOOTSTRAP_FATAL_EXIT_GUARD_KEY is re-declared locally instead of imported from the source module. |
| src/main/startup/bootstrap-fatal-exit-guard.ts | New module that exports the guard key constant and removeBootstrapFatalExitGuard(); logic is correct and safe with optional-chaining on the undefined guard case. |
| src/main/startup/main-process-error-guards.ts | Adds removeBootstrapFatalExitGuard() call at the end of installUncaughtPipeErrorGuard(); ordering (on then remove-bootstrap) is correct with no gap in coverage. |
| config/scripts/electron-vite-output-contract.test.ts | Adds VM-sandboxed test for the bootstrap banner and a contract assertion that zod is excluded from externalization; test logic and assertions are correct. |
| src/main/startup/bootstrap-fatal-exit-guard.test.ts | Unit test for removeBootstrapFatalExitGuard; covers the installed-guard path; the no-guard-present path is implicitly safe due to optional-chaining. |
Sequence Diagram
sequenceDiagram
participant NSIS as NSIS Installer
participant asar as app.asar (new)
participant res as resources/node_modules
participant EM as Electron Main
NSIS->>asar: "deploy at t=0"
asar->>EM: bootstrap banner runs, installs uncaughtException guard
asar->>EM: source graph loads (zod bundled inline, no race)
EM->>EM: installUncaughtPipeErrorGuard installs source-level handler
EM->>EM: removeBootstrapFatalExitGuard removes bootstrap listener
NSIS->>res: "deploy at t=8s later"
Note over EM: App already running normally
Reviews (1): Last reviewed commit: "fix(win): harden startup during partial ..." | Re-trigger Greptile
📝 WalkthroughWalkthroughThe main-process build now bundles 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
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
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: ce9cc65c-05df-41d3-9381-d273895a1ebd
📒 Files selected for processing (5)
config/scripts/electron-vite-output-contract.test.tselectron.vite.config.tssrc/main/startup/bootstrap-fatal-exit-guard.test.tssrc/main/startup/bootstrap-fatal-exit-guard.tssrc/main/startup/main-process-error-guards.ts
| const BUNDLED_MAIN_DEPENDENCIES = new Set([ | ||
| '@xterm/headless', | ||
| '@xterm/addon-serialize', | ||
| // Why: Windows NSIS deploys app.asar before external resources; bootstrap must | ||
| // not race the later resources/node_modules copy. | ||
| 'zod' | ||
| ]) | ||
| const EXTERNAL_MAIN_DEPENDENCIES = Object.keys(packageJson.dependencies).filter( | ||
| (dependency) => !BUNDLED_MAIN_DEPENDENCIES.has(dependency) | ||
| ) | ||
| const BOOTSTRAP_FATAL_EXIT_GUARD_KEY = '__ORCA_BOOTSTRAP_FATAL_EXIT_GUARD__' |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
Guard key is duplicated instead of imported from the canonical module.
BOOTSTRAP_FATAL_EXIT_GUARD_KEY is redeclared here with the same literal already exported from src/main/startup/bootstrap-fatal-exit-guard.ts. The values currently match, but if they ever drift, removeBootstrapFatalExitGuard() would silently fail to find the installed guard (the runtime lookup uses a different key than the one baked into the bundled banner), leaving the process.once('uncaughtException', ...) handler permanently attached alongside the durable handler installed later — the first post-bootstrap uncaught exception would then hit process.exit(1) before the durable handler's crash recording/re-throw can run.
Import the constant from the single source instead of redefining it.
♻️ Proposed fix
+import { BOOTSTRAP_FATAL_EXIT_GUARD_KEY } from './src/main/startup/bootstrap-fatal-exit-guard'
+
const BUNDLED_MAIN_DEPENDENCIES = new Set([
'`@xterm/headless`',
'`@xterm/addon-serialize`',
// Why: Windows NSIS deploys app.asar before external resources; bootstrap must
// not race the later resources/node_modules copy.
'zod'
])
const EXTERNAL_MAIN_DEPENDENCIES = Object.keys(packageJson.dependencies).filter(
(dependency) => !BUNDLED_MAIN_DEPENDENCIES.has(dependency)
)
-const BOOTSTRAP_FATAL_EXIT_GUARD_KEY = '__ORCA_BOOTSTRAP_FATAL_EXIT_GUARD__'📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| const BUNDLED_MAIN_DEPENDENCIES = new Set([ | |
| '@xterm/headless', | |
| '@xterm/addon-serialize', | |
| // Why: Windows NSIS deploys app.asar before external resources; bootstrap must | |
| // not race the later resources/node_modules copy. | |
| 'zod' | |
| ]) | |
| const EXTERNAL_MAIN_DEPENDENCIES = Object.keys(packageJson.dependencies).filter( | |
| (dependency) => !BUNDLED_MAIN_DEPENDENCIES.has(dependency) | |
| ) | |
| const BOOTSTRAP_FATAL_EXIT_GUARD_KEY = '__ORCA_BOOTSTRAP_FATAL_EXIT_GUARD__' | |
| import { BOOTSTRAP_FATAL_EXIT_GUARD_KEY } from './src/main/startup/bootstrap-fatal-exit-guard' | |
| const BUNDLED_MAIN_DEPENDENCIES = new Set([ | |
| '`@xterm/headless`', | |
| '`@xterm/addon-serialize`', | |
| // Why: Windows NSIS deploys app.asar before external resources; bootstrap must | |
| // not race the later resources/node_modules copy. | |
| 'zod' | |
| ]) | |
| const EXTERNAL_MAIN_DEPENDENCIES = Object.keys(packageJson.dependencies).filter( | |
| (dependency) => !BUNDLED_MAIN_DEPENDENCIES.has(dependency) | |
| ) |
Electron validation (Windows)Validated PR head 8e6f05c from the intended
|


Summary
zodinto the Electron main-process output so startup does not depend on the laterresources/node_modulesdeploymentrequire()prelude, then replace it with the normal durable error guard after the source graph loadsCannot find module 'zod'failureRoot cause
The Windows NSIS install updates the live application directory non-transactionally. In the captured failure, the new
app.asarand plugin-host chunk were visible 8.343 seconds beforeresources/node_modules/zodexisted. The new main bundle immediately executedrequire("zod"), lost that race, and Electron displayed its native fatal-error dialog. That failed main process remained resident, held the updater lock, and prevented the runtime/pairing listener from starting.This change uses the packaging-safe alternative to an installer rewrite: the bootstrap-critical schema dependency is part of the main bundle itself. It also ensures any future exception that occurs before source-level guards load exits instead of stranding a dialog-only Electron process.
User-visible behavior
Cannot find module 'zod'dialog; no Orca windowzodis already in the startup bundle, so launch proceeds normallyValidation
pnpm exec vitest run config/scripts/electron-vite-output-contract.test.ts src/main/startup/bootstrap-fatal-exit-guard.test.ts src/main/startup/main-process-error-guards.test.ts(17 tests)pnpm run build:desktoppnpm run typecheck:nodepnpm run check:max-lines-ratchetout/main: bootstrap guard is the first code inindex.js; no barerequire("zod")remainsA final
electron-builder --dirpackage was not produced locally because this host lacks the Visual Studio toolchain required to rebuildwindows-native-registry; the complete desktop build and packaging-relevant emitted-output checks passed.