feat(fleet): launcher heartbeat sidecar — HB for all runtimes (pi/claude/codex) #584
Reference in New Issue
Block a user
Delete Branch "feat/fleet-heartbeat-sidecar"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Runtime-agnostic heartbeat: start-agent-session.sh resolves the pane PID and spawns a detached setsid sidecar that writes ~/.config/mosaic/fleet/run/.hb (ts/pid/status) every interval while the runtime PID is alive, self-terminating on death. Closes the HB=unknown gap for real pi/claude/codex sessions (previously only the dogfood stub heartbeat). Preserves PATH-baking + exec pane identity. Gate + 7 sh tests pass (incl. real-tmux .hb write).
Replace the terminal `exec tmux` with a plain `tmux new-session -d` so the launcher continues running after creating the pane. The script then resolves the pane PID via `tmux list-panes -F '#{pane_pid}'` (with a brief retry loop) and spawns a detached, runtime-agnostic heartbeat sidecar via `setsid bash -c ... &` + `disown`. The sidecar loops while `kill -0 <pane_pid>` succeeds, writing ~/.config/mosaic/fleet/run/<AGENT>.hb atomically (tmp + mv) every MOSAIC_HEARTBEAT_INTERVAL seconds (default 15), then exits naturally when the runtime process dies — making `mosaic fleet ps` show stale then dead. HB_RUN_DIR and interval are configurable via env; sidecar startup is best-effort (failures warn but do not abort the launch). Two new shell tests cover pane-PID resolution (test 6, real tmux) and sidecar invocation correctness (test 7, fake-tmux + fake-setsid shims). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RMoEx7hfdFGjUiCHuN1RRi