Skip to content

fix(daemon): drop a legacy daemon that can no longer accept a connection - #27436

Merged
OrcaWin merged 5 commits into
mainfrom
OrcaWin/appimage-legacy-daemon-gone
Oct 11, 2026
Merged

OrcaWin merged 5 commits into
mainfrom
OrcaWin/appimage-legacy-daemon-gone

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Oct 11, 2026 •

Copy link
Copy Markdown
Collaborator

Copy of #24313 by @innocarpe, rebased onto current main so 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

  • Before: worktree rm failed with ECONNREFUSED or connect ENOENT for every clean worktree after a legacy daemon died, until the app restarted.
  • After: when a legacy adapter's process list fails with a connect ECONNREFUSED/ENOENT and 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.
  • The current daemon still fails the whole list on any error, including ECONNREFUSED. A missing token file (ENOENT on open), ECONNRESET, timeouts and protocol errors still fail closed, and the legacy adapter stays registered for them.
  • Our changes: resolved one rebase conflict (a comment above getLegacyAdapters), added the required SAFETY: 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 on main. 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 main already 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.ts and daemon-pty-adapter-subscription-fanout.test.ts. Router, fanout and owner-resolver tests pass locally (73 tests).

  • pnpm tc, oxlint, pnpm run check:code-quality:changed and pnpm lint pass 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

  • Not applicable.

Notes

Main process only. No wire change. Windows named pipes report ENOENT only when no pipe instance exists.

Supersedes #24313.

@coderabbitai

coderabbitai Bot commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: fa65c17b-d10b-4eab-913a-e80ad20670f4


📥 Commits

Reviewing files that changed from the base of the PR and between 720c169 and 54b2633.



📒 Files selected for processing (3)
  • src/main/daemon/daemon-legacy-exit-proof.ts
  • src/main/daemon/daemon-pty-router-legacy-gone.test.ts
  • src/main/daemon/daemon-pty-router.ts


Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.




📝 Walkthrough
📝 Walkthrough

Walkthrough

The router now records legacy adapter PIDs and checks whether a daemon has exited before handling endpoint-gone errors during process listing. When the check confirms exit, the router removes the adapter from the legacy list, owner resolver, and subscription fanout. It attempts to disconnect the adapter and treats its process list as empty. Other errors continue to propagate. Tests cover removal, subscription forwarding, and error handling.



Priority: ➖ Normal

Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to 54b26

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 | Passed 4 | Failed 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 6 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check Passed Issue #24281 requires clean removal to continue after a dead legacy daemon returns connect ECONNREFUSED or ENOENT. DaemonPtyRouter.listProcesses identifies endpoint-gone errors for legacy adapte…
Out of Scope Changes check Passed The changes stay within issue #24281. Mutable provider and subscription tracking, exit-proof tracking, adapter cleanup, and the related tests support safe removal of a dead legacy adapter. The changes…
Title check Passed The title clearly and concisely describes the primary change: removing legacy daemons that can no longer accept connections.
Description check Passed The description is mostly complete. It explains the user impact, behavior change, rationale, linked issue, testing, platform scope, and absence of UI changes. The AI Disclosure and Checklist sections …

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR




  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@OrcaWin
OrcaWin force-pushed the OrcaWin/appimage-legacy-daemon-gone branch from 7a18c01 to 720c169 Compare October 11, 2026 09:47
innocarpe and others added 5 commits October 11, 2026 03:28
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]>
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]>
@OrcaWin
OrcaWin force-pushed the OrcaWin/appimage-legacy-daemon-gone branch from 720c169 to 54b2633 Compare October 11, 2026 10:28
@OrcaWin
OrcaWin merged commit 43bf799 into main Oct 11, 2026
42 checks passed
@OrcaWin
OrcaWin deleted the OrcaWin/appimage-legacy-daemon-gone branch October 11, 2026 10:44
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.

worktree rm fails for every worktree after a preserved daemon dies: legacy adapter stays registered (recurrence of #9569, 1.4.217 Linux AppImage)

2 participants