Repository navigation
fix(daemon): drop a legacy daemon that can no longer accept a connection - #27436
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Priority: ➖ Normal Severity of issue fixed: Medium Merge Risk: ⚪ Minimal · up to Clean worktree removal should no longer be blocked by a dead legacy daemon. Other failure modes remain fail-closed. No actionable merge-blocking risk was identified. Pre-merge checks |
|
7a18c01 to
720c169
Compare
worktree rm lists every routed daemon and fails closed if any list fails. A leftover socket from a previous app version answers with ECONNREFUSED or connect ENOENT, which blocked removal of every clean worktree. Treat only that dead connect as an empty inventory and forget the adapter. The current daemon, a missing token file, and every other error still fail closed.
The owner resolver and subscription fanout kept the adapter list they copied at startup, so a dropped socket was still treated as an unknown session owner. Co-authored-by: Cursor <[email protected]>
Removing it from the adapter list left the data and exit listeners attached, so a gone socket could still forward events. Co-authored-by: Cursor <[email protected]>
Co-authored-by: Wooseong Kim <[email protected]>
A refused or missing socket is loss of contact, not proof of death. The router now also requires the pid from the daemon's last hello to be gone before it drops the adapter, and keeps failing closed otherwise (and on Windows). This keeps main's observed-exit close contract, which treats an unreachable unrelated daemon as unverifiable. Co-authored-by: Wooseong Kim <[email protected]>
720c169 to
54b2633
Compare
Copy of #24313 by @innocarpe, rebased onto current
mainso it can land without more work from the author. All three original commits keep their authorship. Thank you, Wooseong.ELI5
After an app update, an old terminal background service (a "legacy daemon") can die but stay on Orca's list. Removing a worktree asks every daemon on that list what is still running, and the dead one never answers, so every worktree removal failed until Orca was restarted. Now Orca notices that the old daemon's socket is gone, stops asking it, and lets the removal go ahead.
What Changed
worktree rmfailed withECONNREFUSEDorconnect ENOENTfor every clean worktree after a legacy daemon died, until the app restarted.ECONNREFUSED/ENOENTand the process that daemon last answered from has exited, the router treats it as an empty list, removes that adapter from its legacy list, the session-owner resolver and the event fanout, and disconnects it in the background. Later lists do not ask it again.ECONNREFUSED. A missing token file (ENOENTonopen),ECONNRESET, timeouts and protocol errors still fail closed, and the legacy adapter stays registered for them.getLegacyAdapters), added the requiredSAFETY:notes on two test fakes, and added one behaviour fix. A refused or missing socket only shows that Orca lost contact with the daemon. It does not prove the daemon died. Main's terminal-close tests rely on that: an unreachable unrelated daemon has to make the close result "unverifiable". So the router now remembers the pid each legacy daemon last answered with (daemon-legacy-exit-proof.ts). It drops the adapter only when that pid no longer exists. If the pid is still alive, was never seen, or the platform is Windows, the list still fails closed, as it does onmain. The worktree rm fails for every worktree after a preserved daemon dies: legacy adapter stays registered (recurrence of #9569, 1.4.217 Linux AppImage) #24281 case (a daemon that crashed) still clears.Why
A daemon is treated as gone only with positive proof: its socket refuses connections and its process no longer exists. That matches how
mainalready maps the same error to "terminal host gone" elsewhere. A connected client never sees a connect error, so a live legacy daemon with an open connection is not affected. Respawning the dead daemon was out of scope, since legacy daemons are never respawned.Linked Issue
Fixes #24281
Visual Proof
N/A: no UI change.
Testing
New regression tests:
daemon-pty-router-legacy-gone.test.tsanddaemon-pty-adapter-subscription-fanout.test.ts. Router, fanout and owner-resolver tests pass locally (73 tests).pnpm tc,oxlint,pnpm run check:code-quality:changedandpnpm lintpass locally.Automated tests added/updated
Review
A second-model P0/P1 review of the original change found no P0/P1 issues. It flagged a lower-severity case: a live daemon whose socket file was deleted would be dropped. Then CI failed main's observed-exit close tests for the same reason. The exit-proof commit fixes both.
Agent skill upstream boundary
Notes
Main process only. No wire change. Windows named pipes report
ENOENTonly when no pipe instance exists.Supersedes #24313.