Skip to content

feat(daemon): flock-only liveness, durable state with backup, checkpoints and crash recovery - #73

Merged
bsommers merged 6 commits into
mainfrom
feat/daemon-resilience
Nov 10, 2026
Merged

bsommers merged 6 commits into
mainfrom
feat/daemon-resilience

Conversation

@bsommers

@bsommers bsommers commented Nov 10, 2026 •

Copy link
Copy Markdown
Owner

What

  • Durable writes: src/secure_fs.rs writes state atomically with fsync and keeps a last-good backup. An older backup never replaces a newer saved layout.
  • Liveness: the flock is the only source of truth for whether a daemon is alive (src/daemon/liveness.rs); pid files are no longer trusted. Children are reaped, and crashed daemons are shown as crashed.
  • Checkpoints and crash recovery: src/wm/resilience.rs.
  • bilterm ctl auto-start used the wrong socket path; fixed in src/main.rs.
  • Tests no longer touch the real runtime dir: tests/phase55_daemon_parity.rs ran against the user's real $XDG_RUNTIME_DIR/bilterm and is now sandboxed.
  • Docs are honest about detach: detach saves the layout; it does not keep programs running. Session "reparenting" is session-tree metadata, not process migration.

Not in this PR

Keeping programs alive across detach is a separate feature.

Note on running the gate

With XDG_RUNTIME_DIR set to a very long path, phase51_1_tracing fails because ssh ControlMaster logs a path-length warning. That is an environment artifact: the same failure appears on the tmux branch (#74), which does not touch that code, and the test passes with a short path.

Verification

🤖 Generated with Claude Code

bsommers and others added 6 commits November 10, 2026 01:07
write_private_file_durable keeps the previous file as <name>.bak (hard link),
writes temp + fsync + rename and fsyncs the directory. read_with_backup falls
back to the backup when the primary is missing, truncated or invalid, puts the
good copy back and keeps the damaged one as <name>.corrupt.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…ashed daemons

- liveness.rs: daemon state comes from the lockfile flock (held = running,
  record without a holder = crashed, empty = stopped), so zombies and reused
  PIDs are never mistaken for a live daemon; kill(pid,0) also rejects zombies.
- The lockfile is never unlinked (release/stop truncate the record under the
  lock), which removes the race where a concurrent starter lost its file.
- acquire_lock no longer deletes sockets from a lock it does not hold; stale
  sockets are only removed after a refused connect.
- spawn_daemon_in / spawn_background_daemon_for_session reap the child.
- stop_daemon refuses to act on its own process instead of unlinking its own
  lock and socket while still running.
- daemon.status / the daemon window report 'crashed' instead of 'locked';
  daemon.* RPC resolves the runtime dir like the colon command does.
- phase55_daemon_parity no longer locks and stops 'default' in the user's real
  runtime dir.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
- wm/resilience.rs: debounced (750 ms) and periodic (30 s) checkpoints of the
  active session on layout, pane or cwd change; the UI thread only builds the
  snapshot, a worker serializes and writes <session>.ckpt. A <session>.running
  marker detects an unclean shutdown; the next start restores the last
  checkpoint and reports it.
- :daemon start/stop run on a worker when a UI is attached and report through
  the tick, so the UI thread never waits on a daemon.
- Session files carry format_version, are written durably with a .bak, and a
  corrupt or truncated file falls back to the backup with a message; a failed
  restore at startup is shown instead of silently starting fresh.
- detach_client cancels and says why when the session cannot be saved; wording
  no longer implies programs keep running.
- Journal writes/loads are durable and versioned and use one directory.
- The session tree (reparenting) persists across restarts; the MCP reparent
  path reports rejected grafts (self, cycle, missing) instead of success.
- session.save / session.restore over RPC share the colon command's function
  and default (the active session).
- bilterm ctl auto-start retries on the socket the started daemon listens on.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@bsommers
bsommers merged commit 12a1bff into main Nov 10, 2026
3 checks passed
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.

1 participant