Repository navigation
fix(daemon): daemon cannot start in 1.4.129-rc.1 — electron require leaked into daemon-entry chunk - #7844
Conversation
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.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThis PR adds a new Rollup plugin, 🚥 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 |
…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.
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]>
…eaked into daemon-entry chunk (stablyai#7844)
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 1in 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:
Root cause
daemon-entry.tsis forked as a plain Node process (ELECTRON_RUN_AS_NODE). In a packaged app,require("electron")throwsMODULE_NOT_FOUNDthere because the Electron runtime module isn't available to plain Node.#7642 added
import { ensureShellReadyWrappersAt } from './local-pty-shell-ready'towindows-shell-args.ts. That created a new import edge:local-pty-shell-ready.tshad a top-levelimport { app } from 'electron'. Rollup pulled it into a chunk shared with the daemon entry, sorequire("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.jsunder plain Node. Unit tests import the TS source in a dev tree whererequire("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
Minimal:
local-pty-shell-ready.tsno longer imports electron.getShellReadyWrapperRoot()resolves the wrapper root fromprocess.env.ORCA_USER_DATA_PATH. Main canonicalizes that env var to its ownuserDataat startup (configureOrcaUserDataPathEnv, before any PTY spawns) and the daemon fork sets it explicitly, so the resolved root still matches this instance'suserData.Permanent build guard —
build-plugins/plain-node-entry-guard.ts, wired into the main build inelectron.vite.config.ts:daemon-entry,parcel-watcher-process-entry,computer-sidecar, the CLI-runagent-hooks/managed-agent-hook-controls) and fails the build if any reachable chunk containsrequire("electron").process.execPath out/main/daemon-entry.jsunder plain Node and requires it to exit non-zero with theUsage: daemon-entryerror — proving the whole module graph resolves under plain Node. AMODULE_NOT_FOUNDor a missing usage line fails the build.electron-vite devwatch mode so hot rebuilds aren't slowed.Verification (Windows)
npm run typecheck:node— passlocal-pty-shell-ready+windows-shell-argssuites — pass (34 passed, 16 zsh-gated skips), including a new test asserting the wrapper root resolves fromORCA_USER_DATA_PATHosc7-file-uri,daemon-pty-adapterhistory) are pre-existing Windows failures on the base commit, unrelated to this changenpm run build:electron-vite— pass with the guard active (static check + daemon-entry smoke run on every build)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 afterwardnode out/main/daemon-entry.jsprints theUsage: daemon-entryerror (notMODULE_NOT_FOUND), exit 1Confirmed guarded entries:
daemon-entry,parcel-watcher-process-entry,computer-sidecar,agent-hooks/managed-agent-hook-controls.