fix(daemon): Kill zombie tmux sessions before recreating

The daemon was failing to restart agents when zombie tmux sessions existed
(session alive but Claude dead). Added EnsureSessionFresh() helper to
tmux package that:
- Checks if session exists
- If exists but Claude not running (zombie), kills the session
- Creates fresh session

Updated all daemon session creation points to use EnsureSessionFresh:
- ensureDeaconRunning()
- ensureWitnessRunning()
- restartPolecatSession()
- restartSession() in lifecycle.go

Added tests for the new helper function. (gt-j1i0r)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
dag
2026-01-02 18:52:06 -08:00
committed by Steve Yegge
parent 883997e044
commit 9ad826cd8c
4 changed files with 137 additions and 4 deletions
+2 -1
View File
@@ -348,7 +348,8 @@ func (d *Daemon) restartSession(sessionName, identity string) error {
}
// Create session
if err := d.tmux.NewSession(sessionName, workDir); err != nil {
// Use EnsureSessionFresh to handle zombie sessions that exist but have dead Claude
if err := d.tmux.EnsureSessionFresh(sessionName, workDir); err != nil {
return fmt.Errorf("creating session: %w", err)
}