Skip to content

fix(daemon): replace a permanently wedged daemon instead of preserving it forever (#8689) - #8697

Merged
nwparker merged 2 commits into
mainfrom
nwparker/bug-daemonprotocolerror-hello-response-timed-out
Jul 14, 2026
Merged

nwparker merged 2 commits into
mainfrom
nwparker/bug-daemonprotocolerror-hello-response-timed-out

Conversation

@nwparker

@nwparker nwparker commented Jul 14, 2026 •

Copy link
Copy Markdown
Contributor

What & why

Fixes #8689 — on macOS, terminals show DaemonProtocolError: Hello response timed out repeatedly with no recovery (screenshot in the issue shows it stacked 4×).

Root cause. The terminal daemon runs as a detached process. When it gets wedged — its socket still accept()s connections but its event loop never answers the protocol hello handshake — two behaviors combined into a permanent break:

  1. The launcher adopted the wedge forever. In createOutOfProcessLauncher's unhealthy branch, a daemon that failed the health check but whose socket still accepted a raw connection was preserved unconditionally (daemon-init.ts). That branch was a deliberate fix for a Windows update-relaunch case (a transiently busy daemon that still owns live sessions must not be killed) — but it couldn't tell a transient wedge from a permanent one, so a permanent wedge was preserved on every launch.
  2. A hello timeout wasn't "daemon-gone". isDaemonGoneError (daemon-pty-adapter.ts) matched ENOENT/ECONNREFUSED/Connection lost/Not connected — but not Hello response timed out — so withDaemonRetry never respawned. Every spawn rethrew the error.

The fix (two coordinated changes)

  1. daemon-init.ts — bounded grace instead of unconditional preserve. Retry the hello+listSessions probe up to WEDGED_DAEMON_GRACE_RETRIES (=11) times while the socket keeps probing alive. A transient wedge drains within the window (~60s) and is preserved with its live sessions; a permanent wedge exhausts the grace and falls through to killStaleDaemon + fork (replacement). A transient wedge drains early (well under the 60s local-PTY fail-open cap); only a permanent wedge runs the full ~60s window, after which restored panes fail open to the in-process provider for that session and adopt the freshly forked daemon on the next launch. Daemon init is off the first-paint path (the window still shows at 12s).
  2. daemon-pty-adapter.ts — hello timeout is daemon-gone. isDaemonGoneError now also matches Hello response timed out, so an already-running adapter that reconnects into a wedge triggers withDaemonRetry's respawn, which re-enters the same grace-bounded launcher — drain-or-replace, not fail-forever.

ELI5

Orca keeps your terminals alive in a little always-on background helper (the "daemon"). Sometimes that helper freezes: it still answers the phone, but nobody's actually on the line. Orca used to see "the phone rings" and assume the helper was fine, so it kept calling forever and every terminal showed the red error. Now Orca waits a short, bounded time to see if the helper wakes up (it usually does, right after an update — so we don't throw away your running work). If it's truly frozen, Orca hangs up, starts a fresh helper, and your terminals work again — instead of staying broken until you quit and reopen the app.

Evidence

Root cause reproduced end-to-end against the real product code (DaemonClient + checkDaemonHealth) with a socket that accepts connections but never answers hello:

health=unreachable  probeSocketAlive=true  clientOutcome="Hello response timed out"
=> launcher's old preserve condition (health !== 'rejected' && probeAlive) is true:
   the wedged daemon was PRESERVED forever, so every spawn kept throwing the error.

New/changed tests (all green; full daemon suite 808 passed | 5 skipped):

  • daemon-init.test.ts
    • adopts a transiently wedged daemon that drains and reports live sessions within the grace window — the Windows case: no fork, sessions kept.
    • replaces a permanently wedged daemon after the grace window is exhausted ([Bug]: DaemonProtocolError: Hello response timed out #8689) — fork + killStaleDaemon called; asserts the probe ran exactly 1 + WEDGED_DAEMON_GRACE_RETRIES times.
    • grace budget is generous enough to ride out a ~60s transient wedge + preserves a daemon that stays wedged until the LAST allowed grace retry — pin the ~60s magnitude so the transient-wedge protection can't be silently shrunk.
    • replaces a hello-rejected daemon… — now asserts the rejected fast-path skips the grace (probed once).
  • daemon-pty-adapter.test.ts — treats a hello handshake timeout as daemon-gone and respawns ([Bug]: DaemonProtocolError: Hello response timed out #8689) (throws the real DaemonProtocolError).
  • issue-6814-daemon-failure-classification.test.ts — WEDGED-HELLO: a daemon that accepts connections but never answers hello classifies as unreachable ([Bug]: DaemonProtocolError: Hello response timed out #8689).

Pin proof: temporarily setting WEDGED_DAEMON_GRACE_RETRIES = 1 failed the magnitude-pin tests (verified during development), then reverted.

This change was reviewed by an adversarial multi-agent pass (6 lenses → per-finding refute-or-confirm by 2 independent skeptics → synthesis). Verdict: SHIP. It refuted the "tears down live terminals up-front" and "grace too short/destructive on the runtime path" concerns (a hello timeout only occurs on a fresh connect, so an actively-streaming client never re-runs the handshake), and confirmed the launcher grace mechanics are correct. The remaining surviving items are pre-existing or fast-follow (see below).

Trade-offs / user regressions

Zero regression to the common path. A healthy daemon takes the existing 'healthy' branch and never enters the grace loop — no added latency, no behavior change. The grace loop only runs for a daemon that already failed the health check.

One inherent, bounded trade-off (narrowing of the Windows update-relaunch preserve). The old code preserved a connectable-but-unresponsive daemon with no time bound. The new code replaces it after ~60s. So a genuinely transient wedge that still owns live sessions and takes longer than ~60s to drain now loses those sessions (the live child processes; scrollback still cold-restores from checkpoints) where the old code kept them. This is unavoidable given the fix: a permanent wedge and an arbitrarily-long transient wedge are indistinguishable at the decision point, and unbounded preserve is exactly the reported bug. During that whole window the sessions are frozen and unusable anyway, and the within-window transient case is still preserved (kept + newly tested). The bound is a single documented tuning constant with its floor pinned in tests; raise it (alongside the fail-open cap) if field telemetry shows update-relaunch drains routinely exceed ~60s.

Deliberately out of scope (pre-existing, not introduced here): when the runtime respawn path replaces a daemon, its killed sessions get no synthetic pty:exit fanout. Verified this is identical to the existing ENOENT/ECONNREFUSED daemon-death respawn path (the adapter's onDisconnected handler has never fanned exits) — so this PR introduces no new behavior there; it's a separate improvement affecting all respawn triggers.

Closes #8689.

…g it forever (#8689)

A daemon whose socket accepts connections but whose event loop never answers the
'hello' handshake was adopted by the launcher unconditionally and never re-evaluated,
so every terminal spawn failed with 'DaemonProtocolError: Hello response timed out'
with no recovery.

- daemon-init.ts: bound the launcher's 'preserve any unresponsive-but-connectable
  daemon' with a grace window. A transient wedge (Windows update-relaunch AV/disk
  pressure) drains within ~20s and is preserved WITH its live sessions; a permanent
  wedge exhausts the grace and is replaced. Stays well under the 60s local-PTY
  fail-open cap.
- daemon-pty-adapter.ts: isDaemonGoneError now treats 'Hello response timed out' as
  daemon-gone, so a runtime wedge triggers withDaemonRetry's respawn (re-entering the
  same grace-bounded launcher) instead of failing every spawn until app restart.

Tests pin the grace magnitude so it cannot be silently shrunk.

Co-authored-by: Orca <[email protected]>
@coderabbitai

coderabbitai Bot commented Jul 14, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Daemon initialization now uses bounded grace retries for connectable but unhealthy daemons, preserving those that recover and replacing those that remain wedged or are rejected. PTY adapters treat hello-response timeouts as daemon-gone errors and respawn accordingly. Health-check regression coverage verifies that a socket accepting connections without completing the hello handshake is classified as unreachable.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description is informative, but it does not follow the required template and omits Summary, Screenshots, Testing, AI Review Report, Security Audit, and Notes sections. Rewrite the PR description using the repository template and include all required sections, especially testing, cross-platform review, security audit, screenshots or no visual change, and notes.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The changes implement the #8689 fix by bounding grace for wedged daemons and treating hello timeouts as daemon-gone, with matching tests.
Out of Scope Changes check ✅ Passed All file changes are directly tied to the daemon timeout/wedge fix and associated regression tests; no unrelated changes stand out.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Title check ✅ Passed The title is concise and accurately summarizes the main change: replacing a permanently wedged daemon with bounded recovery.
✨ 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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Bump WEDGED_DAEMON_GRACE_RETRIES 3 -> 11 (~20s -> ~60s) to keep live-session
loss on the transient-wedge (Windows update-relaunch) path as close to zero as
possible. A transient wedge drains early and stays under the 60s fail-open cap;
only a permanent wedge runs the full window. Export the constant and pin its
floor in tests so it can't be silently shrunk.

Co-authored-by: Orca <[email protected]>
@nwparker
nwparker merged commit 840d327 into main Jul 14, 2026
5 of 6 checks passed
nwparker added a commit that referenced this pull request Aug 31, 2026
…y budget

The rescue probe in the launcher's outer catch was clamped to the recovery
budget's remainder, but it runs *after* that budget by construction — past
prepareDaemonReplacement, killStaleDaemon, the fork and the adoption lease.
The remainder is therefore essentially always negative, so Math.max(1, ...)
handed a live socket a 1ms connect window. On the loaded machine this path
exists for the probe loses to its own timer, the launcher rethrows, and a
recoverable degraded adoption becomes total daemon loss for the whole run —
the outcome the comment above it exists to prevent. Restore the 1s default
and pin the window with a test that drives the launcher to that catch with
the budget already spent.

Also make the deliberate narrowing legible instead of implicit:

- daemon-recovery-budget.ts: TRANSIENT_WEDGE_DRAIN_MS documented 20s as the
  grace #8697 sized, but #8697's merged second commit (840d327) widened
  it to 11 retries ~= 60s. Record that 20s is the drain estimate and that the
  budget deliberately sits under #8697's shipped grace.
- daemon-init-wedged-daemon-grace.test.ts: pin the trade directly — a wedge
  draining after the budget is replaced and loses its live sessions.
- Rewrite 'preserves a daemon that stays wedged until the LAST allowed grace
  retry' onto the simulated clock. It never mocked Date.now, so its 12 probes
  elapsed ~0ms and asserted a retry grace the wall clock can no longer
  deliver; it now pins the last drain the budget still adopts.
nwparker added a commit that referenced this pull request Aug 31, 2026
…STA-5732) (#17427)

* fix(daemon): bound the whole boot-recovery sequence with one budget (STA-5732)

* fix(daemon): keep socket probes inside recovery budget

* fix(daemon): size the recovery budget against the real post-kill tail

The 24s budget reserved only 9s for everything after the deadline, leaving
27s of the startup PTY gate's fail-open cap unused — and every unused second
is one where a daemon that would have drained gets killed with its live PTYs
instead. Reserve each post-deadline stage's actual hard cap (kill 10.5s, fork
10s, lease 5s) and spend the rest: 24s -> 32s of adopt window.

* fix(daemon): keep the last-resort endpoint rescue outside the recovery budget

The rescue probe in the launcher's outer catch was clamped to the recovery
budget's remainder, but it runs *after* that budget by construction — past
prepareDaemonReplacement, killStaleDaemon, the fork and the adoption lease.
The remainder is therefore essentially always negative, so Math.max(1, ...)
handed a live socket a 1ms connect window. On the loaded machine this path
exists for the probe loses to its own timer, the launcher rethrows, and a
recoverable degraded adoption becomes total daemon loss for the whole run —
the outcome the comment above it exists to prevent. Restore the 1s default
and pin the window with a test that drives the launcher to that catch with
the budget already spent.

Also make the deliberate narrowing legible instead of implicit:

- daemon-recovery-budget.ts: TRANSIENT_WEDGE_DRAIN_MS documented 20s as the
  grace #8697 sized, but #8697's merged second commit (840d327) widened
  it to 11 retries ~= 60s. Record that 20s is the drain estimate and that the
  budget deliberately sits under #8697's shipped grace.
- daemon-init-wedged-daemon-grace.test.ts: pin the trade directly — a wedge
  draining after the budget is replaced and loses its live sessions.
- Rewrite 'preserves a daemon that stays wedged until the LAST allowed grace
  retry' onto the simulated clock. It never mocked Date.now, so its 12 probes
  elapsed ~0ms and asserted a retry grace the wall clock can no longer
  deliver; it now pins the last drain the budget still adopts.

* fix(daemon): name the socket probe default and correct the grace-retry rationale

Answers the review round on the budget accounting: the outer-catch endpoint
rescue is deliberately outside it, and the preflight clamp no longer duplicates
probeDaemonSocket's default as a bare literal.
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…g it forever (stablyai#8689) (stablyai#8697)

* fix(daemon): replace a permanently wedged daemon instead of preserving it forever (stablyai#8689)

A daemon whose socket accepts connections but whose event loop never answers the
'hello' handshake was adopted by the launcher unconditionally and never re-evaluated,
so every terminal spawn failed with 'DaemonProtocolError: Hello response timed out'
with no recovery.

- daemon-init.ts: bound the launcher's 'preserve any unresponsive-but-connectable
  daemon' with a grace window. A transient wedge (Windows update-relaunch AV/disk
  pressure) drains within ~20s and is preserved WITH its live sessions; a permanent
  wedge exhausts the grace and is replaced. Stays well under the 60s local-PTY
  fail-open cap.
- daemon-pty-adapter.ts: isDaemonGoneError now treats 'Hello response timed out' as
  daemon-gone, so a runtime wedge triggers withDaemonRetry's respawn (re-entering the
  same grace-bounded launcher) instead of failing every spawn until app restart.

Tests pin the grace magnitude so it cannot be silently shrunk.

Co-authored-by: Orca <[email protected]>

* fix(daemon): widen wedged-daemon grace window to ~60s

Bump WEDGED_DAEMON_GRACE_RETRIES 3 -> 11 (~20s -> ~60s) to keep live-session
loss on the transient-wedge (Windows update-relaunch) path as close to zero as
possible. A transient wedge drains early and stays under the 60s fail-open cap;
only a permanent wedge runs the full window. Export the constant and pin its
floor in tests so it can't be silently shrunk.

Co-authored-by: Orca <[email protected]>

---------

Co-authored-by: Orca <[email protected]>
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…STA-5732) (stablyai#17427)

* fix(daemon): bound the whole boot-recovery sequence with one budget (STA-5732)

* fix(daemon): keep socket probes inside recovery budget

* fix(daemon): size the recovery budget against the real post-kill tail

The 24s budget reserved only 9s for everything after the deadline, leaving
27s of the startup PTY gate's fail-open cap unused — and every unused second
is one where a daemon that would have drained gets killed with its live PTYs
instead. Reserve each post-deadline stage's actual hard cap (kill 10.5s, fork
10s, lease 5s) and spend the rest: 24s -> 32s of adopt window.

* fix(daemon): keep the last-resort endpoint rescue outside the recovery budget

The rescue probe in the launcher's outer catch was clamped to the recovery
budget's remainder, but it runs *after* that budget by construction — past
prepareDaemonReplacement, killStaleDaemon, the fork and the adoption lease.
The remainder is therefore essentially always negative, so Math.max(1, ...)
handed a live socket a 1ms connect window. On the loaded machine this path
exists for the probe loses to its own timer, the launcher rethrows, and a
recoverable degraded adoption becomes total daemon loss for the whole run —
the outcome the comment above it exists to prevent. Restore the 1s default
and pin the window with a test that drives the launcher to that catch with
the budget already spent.

Also make the deliberate narrowing legible instead of implicit:

- daemon-recovery-budget.ts: TRANSIENT_WEDGE_DRAIN_MS documented 20s as the
  grace stablyai#8697 sized, but stablyai#8697's merged second commit (6f08017) widened
  it to 11 retries ~= 60s. Record that 20s is the drain estimate and that the
  budget deliberately sits under stablyai#8697's shipped grace.
- daemon-init-wedged-daemon-grace.test.ts: pin the trade directly — a wedge
  draining after the budget is replaced and loses its live sessions.
- Rewrite 'preserves a daemon that stays wedged until the LAST allowed grace
  retry' onto the simulated clock. It never mocked Date.now, so its 12 probes
  elapsed ~0ms and asserted a retry grace the wall clock can no longer
  deliver; it now pins the last drain the budget still adopts.

* fix(daemon): name the socket probe default and correct the grace-retry rationale

Answers the review round on the budget accounting: the outer-catch endpoint
rescue is deliberately outside it, and the preflight clamp no longer duplicates
probeDaemonSocket's default as a bare literal.
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.

[Bug]: DaemonProtocolError: Hello response timed out

1 participant