Repository navigation
fix(daemon): replace a permanently wedged daemon instead of preserving it forever (#8689) - #8697
Merged
nwparker merged 2 commits intoJul 14, 2026
Conversation
…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]>
Contributor
📝 WalkthroughWalkthroughDaemon 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)
✅ 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 |
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]>
6 tasks
This was referenced Aug 30, 2026
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What & why
Fixes #8689 — on macOS, terminals show
DaemonProtocolError: Hello response timed outrepeatedly 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 protocolhellohandshake — two behaviors combined into a permanent break: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.isDaemonGoneError(daemon-pty-adapter.ts) matchedENOENT/ECONNREFUSED/Connection lost/Not connected— but notHello response timed out— sowithDaemonRetrynever respawned. Every spawn rethrew the error.The fix (two coordinated changes)
daemon-init.ts— bounded grace instead of unconditional preserve. Retry thehello+listSessionsprobe up toWEDGED_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 tokillStaleDaemon+ 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).daemon-pty-adapter.ts— hello timeout is daemon-gone.isDaemonGoneErrornow also matchesHello response timed out, so an already-running adapter that reconnects into a wedge triggerswithDaemonRetry'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 answershello:New/changed tests (all green; full daemon suite 808 passed | 5 skipped):
daemon-init.test.tskillStaleDaemoncalled; asserts the probe ran exactly1 + WEDGED_DAEMON_GRACE_RETRIEStimes.rejectedfast-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 realDaemonProtocolError).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 = 1failed 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:exitfanout. Verified this is identical to the existingENOENT/ECONNREFUSEDdaemon-death respawn path (the adapter'sonDisconnectedhandler has never fanned exits) — so this PR introduces no new behavior there; it's a separate improvement affecting all respawn triggers.Closes #8689.