Repository navigation
ci(daemon): fail builds, packaging, and CI when the terminal daemon cannot start — and stop failing silently - #7849
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.
…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.
…annot start — and stop failing silently v1.4.129-rc.1 shipped a terminal daemon that exited at module load (an electron require leaked into its bundle, fixed in #7844) while every CI check passed and the app fell back to local PTYs silently. Nothing executed the built daemon, and its startup stderr was discarded, so the outage was invisible until adopted old daemons died in the field. This adds defense-in-depth around daemon startup. A. Per-PR CI boot: config/scripts/daemon-boot-smoke.mjs forks the BUILT daemon-entry.js under plain Node (the way production forks it), hard-asserts the 'ready' IPC and a clean shutdown, and best-effort runs the daemon's own ptySpawnHealth RPC. Wired into the native-smoke job (ubuntu-22.04 + windows-latest); daemon bundle-graph paths now re-trigger the workflow. B. Packaging smoke: config/scripts/verify-packaged-daemon-entry.cjs boots the packaged daemon-entry under plain Node from the asar-unpacked layout in the electron-builder afterPack hook (arch-gated to the host slice), failing the build on MODULE_NOT_FOUND or a missing usage line — catches asar-unpack regressions the repo-tree build guard cannot see. C. Startup stderr is captured, not discarded: the daemon fork now pipes stderr, keeps a bounded tail during startup, attaches it to the failure error and logs it, and releases the pipe on ready (so the detached daemon does not keep Electron alive). daemon-entry swallows stderr EPIPE so a dead pipe cannot kill a healthy daemon. Unit tests cover both the capture and the release. D. Loud daemon-unavailable: onDaemonError logs a loud reason (carrying the captured stderr tail) and emits a low-cardinality daemon_start_failed telemetry event (error_class only; no raw stderr on the wire). No new UI — there is no existing lightweight main->renderer surface to reuse. Stacked on #7844 (its commits appear here until it merges).
📝 WalkthroughWalkthroughThis PR adds guards ensuring plain-Node daemon entries (built without Electron) can load and boot correctly: a Rollup build plugin detects 🚥 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.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/main/daemon/daemon-init.ts (1)
396-418: 🩺 Stability & Availability | 🟡 Minor | ⚡ Quick winMove
releaseStderr()beforewriteFileSyncto prevent resource leak on throw.In
onReadyMessage,releaseStderr()(line 415) is called afterwriteFileSync(lines 401–410). IfwriteFileSyncthrows (disk full, permission error, I/O failure),releaseStderr()is never reached — the piped stderr stream stays open, keeping the parent event loop alive and preventing clean Electron exit.child.disconnect()andchild.unref()are also skipped, leaving the IPC channel referenced. Meanwhile the daemon is actually running and ready, but the caller sees a rejection.The pid file write doesn't depend on the stderr pipe, so
releaseStderr()can safely move before it.🔧 Proposed fix
settled = true cleanupStartupListeners() + // Why: release the stderr pipe before any remaining work so a throw + // (e.g. writeFileSync I/O error) can't leave a live handle on the + // detached daemon's stderr that blocks Electron exit. + releaseStderr() if (child.pid) { writeFileSync( getDaemonPidPath(runtimeDir), serializeDaemonPidFile({ pid: child.pid, startedAtMs: getProcessStartedAtMs(child.pid), entryPath, appVersion: app.getVersion() }), { mode: 0o600 } ) } - // Why: disconnect IPC channel, release the stderr pipe, and unref so - // Electron can exit without waiting for the daemon. The daemon keeps - // running detached. - releaseStderr() child.disconnect() child.unref() resolve()
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: a24fd567-8feb-49b2-be1a-08bf5dfe3478
📒 Files selected for processing (16)
.github/workflows/computer-e2e.ymlbuild-plugins/plain-node-entry-guard.tsconfig/electron-builder.config.cjsconfig/scripts/computer-e2e-workflow.test.mjsconfig/scripts/daemon-boot-smoke.mjsconfig/scripts/verify-packaged-daemon-entry.cjsconfig/tsconfig.node.jsonelectron.vite.config.tssrc/main/daemon/daemon-entry.tssrc/main/daemon/daemon-init.test.tssrc/main/daemon/daemon-init.tssrc/main/index.tssrc/main/ipc/pty.test.tssrc/main/providers/local-pty-shell-ready.test.tssrc/main/providers/local-pty-shell-ready.tssrc/shared/telemetry-events.ts
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 <help@stably.ai>
…annot start — and stop failing silently (stablyai#7849)
Why
v1.4.129-rc.1 shipped a terminal daemon that exited at module load (an electron
requireleaked into its bundle graph — fixed in #7844) while every CI check passed. The app fell back to local PTYs silently, nothing executed the built daemon, and its startup stderr was discarded — so the outage was invisible until adopted old daemons died in the field.This PR adds the defense layers around daemon startup that would have caught it:
build guard (#7844) → per-PR CI boot → packaging smoke → field observability.
A — native-smoke CI boots the built daemon (per PR)
config/scripts/daemon-boot-smoke.mjsforks the builtout/main/daemon-entry.jsunder plain Node (the way production forks it underELECTRON_RUN_AS_NODE) and:{ type: 'ready' }IPC within 30s, and a clean shutdown (no hang/zombie);ptySpawnHealthRPC over the control socket (a real end-to-end PTY spawn), logging a skip rather than failing since node-pty spawn can be flaky on constrained runners.Wired into the
native-smokejob incomputer-e2e.yml(matrixubuntu-22.04+windows-latest, per PR) right afterbuild:electron-vite. Daemon bundle-graph paths (src/main/daemon/**,electron.vite.config.ts,build-plugins/**, the smoke script) now re-trigger the workflow, andcomputer-e2e-workflow.test.mjsasserts the step + triggers exist.node-pty is N-API (ABI-stable), so it loads under plain Node even when rebuilt for Electron — the
readyassertion is safe on both runners.B — packaging-time daemon smoke (electron-builder afterPack)
config/scripts/verify-packaged-daemon-entry.cjsboots the packagedapp.asar.unpacked/out/main/daemon-entry.jsunder plain Node in the existingafterPackhook, requiring theUsage: daemon-entrystderr and failing the build onMODULE_NOT_FOUND/ a missing usage line. This is a module-load proof against the real packaged layout — it catches asar-unpack/bundling regressions the repo-tree build guard cannot see. Arch-gated to the host slice (daemon-entry.js is JS but requires the target-arch native node-pty, which the host Node cannot load cross-arch); cross-arch slices are skipped with a log.C — daemon startup stderr is no longer discarded
The daemon fork previously used
stdio: ['ignore','ignore','ignore','ipc'], so a module-load crash surfaced only as "exited with code 1". Now:off+destroy) onreadyso the detached daemon does not keep Electron's event loop alive;daemon-entryinstalls aprocess.stderr.on('error', ...)guard so a broken pipe (after the parent releases its end) cannot kill a healthy daemon.Unit tests in
daemon-init.test.tscover both the capture-into-error path (the scope-C negative test) and the release-on-ready path.D — daemon-unavailable is loud, not silent
onDaemonErrornow logs a loud reason (carrying the captured stderr tail from C) and emits a low-cardinalitydaemon_start_failedtelemetry event via the existingtrack()pipeline —error_classenum only, no raw stderr on the wire (paths/usernames stay local). A spike in this event is the fleet-wide signal for a daemon outage.No new UI: there is no existing lightweight main->renderer toast/banner channel to reuse, and the spec said not to build new UI — surfacing this in-app is noted as a follow-up.
Verification
Local (quick, targeted):
typecheck:nodepasses;daemon-init+telemetry+computer-e2e-workflowsuites pass; the boot smoke and the packaged-entry verifier were exercised against the built/synthetic layouts. Full build/test verification is delegated to this PR's CI (native-smoke on both OSes exercises A; unit suites exercise C/D).