Skip to content

fix(daemon): daemon cannot start in 1.4.129-rc.1 — electron require leaked into daemon-entry chunk - #7844

Merged
Jinwoo-H merged 2 commits into
mainfrom
Jinwoo-H/fix-daemon-entry-electron-crash
Jul 8, 2026
Merged

Jinwoo-H merged 2 commits into
mainfrom
Jinwoo-H/fix-daemon-entry-electron-crash

Conversation

@Jinwoo-H

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

Copy link
Copy Markdown
Contributor

Symptom

In v1.4.129-rc.1 the terminal daemon dies immediately on startup on all platforms. Users see terminals frozen / never attaching, daemon exited with code 1 in logs, and a silent fallback to local (non-persistent) PTYs. v1.4.128 stable is NOT affected; v1.4.129-rc.1 is.

The daemon actually exits at module load with:

Error: Cannot find module 'electron'
Require stack:
- <app>/out/main/chunks/daemon-file-log-*.js
- <app>/out/main/daemon-entry.js

Root cause

daemon-entry.ts is forked as a plain Node process (ELECTRON_RUN_AS_NODE). In a packaged app, require("electron") throws MODULE_NOT_FOUND there because the Electron runtime module isn't available to plain Node.

#7642 added import { ensureShellReadyWrappersAt } from './local-pty-shell-ready' to windows-shell-args.ts. That created a new import edge:

daemon-entry → daemon-main → daemon-server → pty-subprocess → windows-shell-args → local-pty-shell-ready

local-pty-shell-ready.ts had a top-level import { app } from 'electron'. Rollup pulled it into a chunk shared with the daemon entry, so require("electron") executed at daemon module load → the daemon exited code 1 before it could serve a single terminal.

Why CI missed it

Nothing in CI executes the built daemon-entry.js under plain Node. Unit tests import the TS source in a dev tree where require("electron") resolves to the npm shim (no throw), and the packaged smoke never runs the daemon as plain Node. The regression was further masked by daemon adoption — a previously-launched live daemon kept serving terminals until it died, at which point the new (broken) daemon could never take over.

The fix

  1. Minimal: local-pty-shell-ready.ts no longer imports electron. getShellReadyWrapperRoot() resolves the wrapper root from process.env.ORCA_USER_DATA_PATH. Main canonicalizes that env var to its own userData at startup (configureOrcaUserDataPathEnv, before any PTY spawns) and the daemon fork sets it explicitly, so the resolved root still matches this instance's userData.

  2. Permanent build guard — build-plugins/plain-node-entry-guard.ts, wired into the main build in electron.vite.config.ts:

    • Static check: walks the emitted chunk import graph from each plain-node fork entry (daemon-entry, parcel-watcher-process-entry, computer-sidecar, the CLI-run agent-hooks/managed-agent-hook-controls) and fails the build if any reachable chunk contains require("electron").
    • Runtime smoke (daemon-entry only): spawns process.execPath out/main/daemon-entry.js under plain Node and requires it to exit non-zero with the Usage: daemon-entry error — proving the whole module graph resolves under plain Node. A MODULE_NOT_FOUND or a missing usage line fails the build.
    • No-ops in electron-vite dev watch mode so hot rebuilds aren't slowed.

Verification (Windows)

  • npm run typecheck:node — pass
  • local-pty-shell-ready + windows-shell-args suites — pass (34 passed, 16 zsh-gated skips), including a new test asserting the wrapper root resolves from ORCA_USER_DATA_PATH
  • daemon suite — the only failures (osc7-file-uri, daemon-pty-adapter history) are pre-existing Windows failures on the base commit, unrelated to this change
  • npm run build:electron-vite — pass with the guard active (static check + daemon-entry smoke run on every build)
  • Guard negative test: temporarily re-adding import { app } from 'electron' (and referencing it) makes the build fail with "daemon-entry" reaches chunk "daemon-entry.js" that requires electron … (exit 1); reverted afterward
  • Manual node out/main/daemon-entry.js prints the Usage: daemon-entry error (not MODULE_NOT_FOUND), exit 1

Confirmed guarded entries: daemon-entry, parcel-watcher-process-entry, computer-sidecar, agent-hooks/managed-agent-hook-controls.

The terminal daemon in v1.4.129-rc.1 could not start on any platform. #7642
added `import { ensureShellReadyWrappersAt }` to windows-shell-args.ts, which
pulled local-pty-shell-ready.ts — and its top-level `import { app } from
'electron'` — into daemon-entry's shared chunk graph. The daemon is forked as
a plain Node process (ELECTRON_RUN_AS_NODE), where `require("electron")` throws
MODULE_NOT_FOUND at module load, so the daemon exited code 1 instantly. It was
masked by daemon adoption until a live old daemon died, at which point
terminals froze and silently fell back to local PTYs.

Minimal fix: local-pty-shell-ready.ts no longer imports electron. The wrapper
root now resolves from ORCA_USER_DATA_PATH, which main canonicalizes to its own
userData at startup (configureOrcaUserDataPathEnv) and the daemon fork sets
explicitly, so it still matches this instance's root.

Build guard: a new rollup plugin (build-plugins/plain-node-entry-guard.ts) runs
on the main build and fails it if any chunk reachable from a plain-node fork
entry (daemon-entry, parcel-watcher-process-entry, computer-sidecar, the CLI
agent-hooks entry) requires electron, plus smoke-loads daemon-entry under plain
node to prove its graph resolves. CI never executed the built daemon-entry
under plain node, so nothing caught the regression before.
@Jinwoo-H
Jinwoo-H marked this pull request as ready for review July 8, 2026 22:57
@coderabbitai

coderabbitai Bot commented Jul 8, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: b03f6e1d-1500-4eea-ad90-8d14b96bcf26

📥 Commits

Reviewing files that changed from the base of the PR and between ff81e98 and 1a04d43.

📒 Files selected for processing (1)
  • src/main/ipc/pty.test.ts

📝 Walkthrough

Walkthrough

This PR adds a new Rollup plugin, createPlainNodeEntryGuardPlugin, that checks plain-Node entrypoints for reachable require("electron") usage and smoke-tests the built daemon-entry.js under Node. The plugin is wired into the Electron main build and included in the Node TS project. Separately, local-pty-shell-ready.ts now derives its wrapper root from process.env.ORCA_USER_DATA_PATH with a tmpdir() fallback, and the related tests now set and restore that environment variable directly.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description covers the bug and fix, but it omits the required template sections for Summary, Screenshots, Testing, AI Review Report, Security Audit, and Notes. Reformat the PR description to match the template and add the missing sections, including screenshots, testing checklist, AI review report, security audit, and notes.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the daemon startup regression and the leaked electron import in the daemon-entry chunk.
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.

…oot assertions

The daemon-entry fix resolves the shell-ready wrapper root from
ORCA_USER_DATA_PATH instead of electron's app.getPath('userData'). This
suite mocked getPath but never set the env var, so ZDOTDIR assertions
resolved to tmpdir. Mirror production (main canonicalizes the env var at
startup before any spawn) in the suite env.
@Jinwoo-H
Jinwoo-H merged commit 685418d into main Jul 8, 2026
1 check passed
@Jinwoo-H
Jinwoo-H deleted the Jinwoo-H/fix-daemon-entry-electron-crash branch July 8, 2026 23:41
Jinwoo-H added a commit that referenced this pull request Jul 9, 2026
Clean auto-merge, no conflicts. Brought in from main:
- daemon boot hardening: fail builds/CI when terminal daemon can't start;
  plain-node-entry-guard + verify-packaged-daemon-entry (electron require
  leaked into daemon-entry chunk, #7844/#7849)
- perf(windows): relax whole-process-table scans for terminals with no
  agent evidence (#7607) — foreground-scan-cadence
- fix(agents): route WSL OMP hooks to the Windows listener (#7565/#7641)
- fix: recover fresh local terminal spawns from a deleted saved cwd (#7847)
- native-chat: upload composer attachments over SSH (#7832)
- mobile: keyboard dismiss control; agent-tab launch fix
- new GitHub issue draft persistence (#7778)

Perf-branch structure preserved (clean auto-merge; no restructured terminal
files conflicted). Gates: typecheck 0 errors; terminal-pane + ipc/pty +
daemon + pane-manager suites 4497 passed / 14 skipped / 0 failed.

Co-authored-by: Orca <[email protected]>
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
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