Repository navigation
Conversation
7ce1bf5 to
a95b750
Compare
|
Strong +1 on this fix, with field data from macOS confirming the exact failure path this PR addresses. Environment: espanso 2.3.0 (Homebrew cask), macOS 26.5 (25F71), ARM64 (MacBookPro17,1). What we observed: five identical crash cascades within three days (accelerating; first occurrence 2026-06-30), each one: The engine-thread Why this PR matters: after each abort, the daemon exits per the code path this PR changes, and since the launchd plist that One adjacent observation while debugging (happy to file separately with full details if useful): with a lingering Full |
…quitting The daemon's worker-status-monitor only forwarded a worker exit to the daemon when the worker exited with a non-zero code (or died by signal). A worker that exited WORKER_SUCCESS (0) unexpectedly — or a failed `child.wait()` — was dropped silently, leaving the daemon blocked in its `select!` loop with a dead worker that was never respawned (a "half-dead" state: daemon alive, worker gone, expansion silently stops). On any other unexpected exit code the daemon would `return` and quit; combined with the macOS launchd plist having no `KeepAlive`, nothing relaunched espanso. This change: - forwards every worker exit to the daemon (including WORKER_SUCCESS and the `wait()` error case), so the daemon is always notified; - on an unexpected worker exit, respawns the worker with a bounded, backing-off retry (up to MAX_WORKER_AUTO_RESTARTS) instead of hanging or quitting, giving up only if the worker dies repeatedly in quick succession (crash-loop protection; the counter resets after a healthy run); - tracks daemon-initiated restarts (config / keyboard-layout change) via an expected-exit counter so the deliberately-terminated old worker is not mistaken for an unexpected death and double-spawned. restart_worker now returns whether it spawned a replacement, so the caller only records an expected exit when a replacement actually started. Tested on macOS: killing the worker now respawns it (was: daemon hung); repeated rapid kills back off (500ms -> 2.5s) and give up after 5 attempts. Refs: espanso#2530 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
bf27fca to
a2e359f
Compare
|
Tested this PR locally on Apple Silicon with macOS 26.6.1 (Darwin 25.6.0). The documented macOS Cargo build completed successfully. I launched the PR binary with isolated configuration and runtime directories, terminated only its worker, and reproduced worker exit code 90. The daemon stayed alive, logged the bounded respawn attempt, spawned a replacement worker, and the replacement worker initialized successfully. |
|
Another macOS 26 report, adding it since this PR looks like the fix for the half-dead state. Environment: espanso 2.4.1, macOS 26.5.2 (25F84), Apple Silicon (MacBookPro18,1). Two separate failures:
The only way to recover is to kill every espanso process, delete the A worker exit with no crash report plus a daemon that never notices fits the silently dropped |
|
This would likely also recover the Windows case in #2850: after a config change the new worker panics with |
Problem
On macOS (service mode), espanso can silently stop expanding for hours: the
daemonprocess stays alive while theworkerprocess is gone and is never respawned.espanso service statusreports "not running" even though the daemon PID is alive, and a manualespanso restartis required to recover. Reported in #2530 (the dead-worker symptom also appears in #2576).Root cause
In
espanso/src/cli/daemon/mod.rs:spawn_worker()'sworker-status-monitorthread only forwarded an exit code to the daemon when the worker exited non-zero (or died by signal →WORKER_ERROR_EXIT_NO_CODE). A worker that exitedWORKER_SUCCESS(0) unexpectedly — or a failedchild.wait()— was dropped silently, so the daemon'sselect!loop was never notified and the worker was never respawned (the "half-dead" state).exit_signalarm, any code other thanWORKER_EXIT_ALL_PROCESSES/WORKER_RESTARThit_ => { ...; return code; }, so an unexpected worker death made the daemon exit. Combined with the macOS launchd plist havingRunAtLoadbut noKeepAlive, nothing relaunched espanso.Fix
WORKER_SUCCESSand thewait()error case), so the daemon is always notified.MAX_WORKER_AUTO_RESTARTS), giving up only if it dies repeatedly in quick succession (crash-loop protection; the counter resets after a healthy run ofWORKER_HEALTHY_RUNTIME).expected_worker_exitscounter so the deliberately-terminated old worker is not mistaken for an unexpected death and double-spawned.restart_workernow returns whether it actually spawned a replacement.Testing
Built with
--no-default-features --features vendored-tls; clippy clean on the changed file. Manual test on macOS with isolated config/runtime dirs:worker exited unexpectedly with code 90thenrespawning worker (attempt 1/5) after 500ms; a new worker starts. (Before this change: the daemon hung with no worker.)500ms → 1s → 1.5s → 2s → 2.5s, thenworker died 5 times in quick succession; giving up to avoid a crash-loopand the daemon exits cleanly (no infinite spin).Note / open question
This makes the daemon resilient to worker death regardless of cause. On macOS the trigger appears to be the worker being torn down across sleep / secure-input transitions (see #2530). Separately, the macOS launchd plist lacks
KeepAlive; I deliberately left that out of this PR because the launchd-managed process is the short-livedlauncher, so addingKeepAlivenaively would cause a respawn loop — happy to address it properly in a follow-up if maintainers prefer.