fix(windows): reap daemon on app quit
Fixes #9195
ELI5
Closing Orca on Windows used to close the window but leave its detached terminal helper running, like hanging up a phone while the other end stays connected. A normal Windows Quit now asks every local daemon generation Orca adopted to stop its terminal sessions, then uses a bounded, exact-process identity check if a daemon is stuck.
Restart and update exits still only disconnect, so their warm terminal sessions survive and reattach as before. macOS/Linux quit behavior is unchanged.
What changed
- Choose daemon shutdown only for ordinary Windows Quit and dev-parent teardown.
- Preserve daemon sessions for intentional Restart/relaunch and updater exits.
- Shut down the current daemon plus adopted legacy protocol generations.
- Fence daemon initialization and manual restart so a detached process cannot launch after quit teardown starts.
- Bound quit RPCs and begin an identity-checked PID fallback before the global quit deadline.
- Remove only the PID record matching the captured PID + launch nonce.
- Exercise the production restart API in restart E2Es while retaining force-close cleanup.
Behavioral note: ordinary Windows Quit ends local daemon-backed terminal processes. Restart/update preserves them. This is scoped to the local user-data daemon provider, so SSH daemons are unaffected; it also does not depend on Git worktree metadata, so folder workspaces are covered.
Proof of reproduction
On the pre-fix build, the isolated Windows E2E closed Electron successfully, waited 10 seconds, and observed:
daemonAlive: true
pidRecordExists: true
That reproduces #9195: the app exited, but its detached Orca daemon remained.
Proof of fix
The same test now passes and requires both values to become false:
pnpm run test:e2e tests/e2e/windows-app-quit-daemon.spec.ts --project=electron-headless --workers=1
# 1 passed
It captures the exact daemon PID/start identity/launch nonce before Quit, then proves both that process and its scoped PID record disappear.
Proof of no regression
# lifecycle/unit coverage
113 focused tests passed
# restart persistence: clean restart input, scrollback, and workspace/tab restoration
3 E2E tests passed
pnpm run typecheck
# passed (node + CLI + web)
pnpm run check:max-lines-ratchet
# passed
oxlint on every changed/new TypeScript file
# passed
git diff --check
# passed
The focused coverage includes Windows/update/relaunch/macOS/Linux policy, current + deduplicated legacy teardown, stalled-RPC fallback timing, PID identity safety, quit during initialization, and quit during manual restart.
Repository-wide pnpm test was also run. Its changed lifecycle suites pass; the aggregate remains red on the existing Windows baseline (128 unrelated failures dominated by POSIX /bin/sh, symlink/path, and CRLF source-snapshot assumptions). Aggregate pnpm lint likewise passes code lint, reliability gates, and the max-lines ratchet before stopping on pre-existing stale generated skill manifests.
📝 Walkthrough
Walkthrough
The changes add relaunch request tracking and centralize daemon quit-mode selection. Daemon initialization, restart, launch, and shutdown now coordinate in-flight operations and interrupt publication during shutdown. Teardown handles current and legacy daemon generations, graceful RPC timeouts, fallback termination, process identity checks, and PID cleanup. End-to-end helpers use the production restart path, and a Windows test verifies daemon reaping and PID-record deletion.
🚥 Pre-merge checks | ✅ 3 | ❌ 2
❌ Failed checks (2 warnings)
| Check name | Status | Explanation | Resolution |
|---|---|---|---|
| Description check | ⚠️ Warning | The description has useful detail, but it does not follow the required template sections for the repository. | Rewrite it to match the template and add the missing Summary, Screenshots, Testing, AI Review Report, Security Audit, and Notes sections. |
| Docstring Coverage | ⚠️ Warning | Docstring coverage is 12.50% which is insufficient. The required threshold is 80.00%. | Write docstrings for the functions missing them to satisfy the coverage threshold. |
✅ Passed checks (3 passed)
| Check name | Status | Explanation |
|---|---|---|
| Title check | ✅ Passed | The title is concise and accurately summarizes the Windows daemon reaping fix. |
| Linked Issues check | ✅ Passed | The PR addresses #9195 by terminating Windows daemon processes on normal app quit and adds verification for the cleanup. |
| Out of Scope Changes check | ✅ Passed | The added daemon lifecycle and E2E changes appear tied to the Windows quit fix and do not look unrelated. |
✨ 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.
Comment @coderabbitai help to get the list of available commands.