Skip to content

fix(daemon): detect and restart stale daemons after binary upgrade#613

Merged
Wirasm merged 3 commits intomainfrom
kild/fix/stale-daemon-on-upgrade
Feb 26, 2026
Merged

fix(daemon): detect and restart stale daemons after binary upgrade#613
Wirasm merged 3 commits intomainfrom
kild/fix/stale-daemon-on-upgrade

Conversation

@Wirasm
Copy link
Copy Markdown
Owner

@Wirasm Wirasm commented Feb 26, 2026

Summary

  • Daemon now records its binary path + mtime at startup in ~/.kild/daemon.bin
  • ensure_daemon_running detects stale daemons (binary updated since startup) and auto-restarts them
  • kild daemon status warns when the running daemon is stale
  • Added kild daemon restart command (stop + start)

Test plan

  • Build and install new daemon binary (cargo install --path crates/kild-daemon)
  • Verify kild daemon status shows stale warning after upgrade
  • Verify kild daemon restart stops old daemon and starts new one
  • Verify kild create --daemon auto-restarts stale daemon transparently
  • Verify clean daemon start/stop cycle writes and removes daemon.bin
  • Run cargo test -p kild-paths -p kild-daemon -p kild-core — all pass

Closes #608

After cargo install, old daemon processes kept running from the previous
binary. Auto-start saw the daemon alive via ping and returned immediately,
never comparing binaries.

Now the daemon records its binary path + mtime at startup in
~/.kild/daemon.bin. On auto-start, if the running daemon's recorded mtime
differs from the current binary on disk, it is gracefully restarted.

- kild daemon status warns when the daemon is stale
- kild daemon restart added as a convenience command (stop + start)
- ensure_daemon_running auto-restarts stale daemons transparently

Closes #608
- Fix autostart logic: stale restart now bypasses auto_start guard,
  preventing Disabled error after stopping a stale daemon
- Fix mtime fallback: return false (not stale) when mtime is unreadable,
  preventing false-positive restart loops
- Fix bin_path derivation: use KildPaths-based bin_file_path() in both
  daemon and client for consistent path resolution
- Add proper error logging to kild-core read_bin_file (match daemon version)
- Extract spawn_daemon_background() helper to deduplicate CLI start/restart
…ents

Silent failure fixes:
- Log find_sibling_binary error in is_daemon_stale instead of swallowing
- Return Option<u32> from spawn_daemon_background to avoid printing PID 0
- Log mtime read failure in write_bin_file instead of silent fallback
- Wait for socket removal (not just PID file) in stop_stale_daemon
- Add error! log on restart stop timeout path
- Make handle_daemon_start PID read failure soft (was hard error)
- Log mtime parse failures in both read_bin_file implementations

Simplification:
- Replace needs_spawn flag with early return spawn_daemon() in
  ensure_daemon_running for clearer control flow

Comment fixes:
- Update run_server docstring to include bin file write step
- Match bin_file_path doc to daemon version with path literal
- Add actionable hint when stale daemon stop fails
@Wirasm Wirasm merged commit 14f11c2 into main Feb 26, 2026
6 checks passed
@Wirasm Wirasm deleted the kild/fix/stale-daemon-on-upgrade branch February 26, 2026 23:25
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: stale daemon processes persist after binary upgrade

1 participant