fix(crew): auto-recover from stale tmux pane references

When a session exists but its pane is gone (e.g., after account switch
or town reboot), 'gt crew at' now detects the "can't find pane" error
and automatically recreates the session instead of failing.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
mayor
2026-01-21 22:39:10 -08:00
committed by beads/crew/emma
parent b612df0463
commit fb4c415127

View File

@@ -3,6 +3,7 @@ package cmd
import ( import (
"fmt" "fmt"
"os" "os"
"strings"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/steveyegge/gastown/internal/config" "github.com/steveyegge/gastown/internal/config"
@@ -216,6 +217,12 @@ func runCrewAt(cmd *cobra.Command, args []string) error {
style.PrintWarning("could not kill pane processes: %v", err) style.PrintWarning("could not kill pane processes: %v", err)
} }
if err := t.RespawnPane(paneID, startupCmd); err != nil { if err := t.RespawnPane(paneID, startupCmd); err != nil {
// If pane is stale (session exists but pane doesn't), recreate the session
if strings.Contains(err.Error(), "can't find pane") {
fmt.Printf("Stale session detected, recreating...\n")
_ = t.KillSession(sessionID)
return runCrewAt(cmd, args) // Retry with fresh session
}
return fmt.Errorf("starting runtime: %w", err) return fmt.Errorf("starting runtime: %w", err)
} }
@@ -265,6 +272,12 @@ func runCrewAt(cmd *cobra.Command, args []string) error {
style.PrintWarning("could not kill pane processes: %v", err) style.PrintWarning("could not kill pane processes: %v", err)
} }
if err := t.RespawnPane(paneID, startupCmd); err != nil { if err := t.RespawnPane(paneID, startupCmd); err != nil {
// If pane is stale (session exists but pane doesn't), recreate the session
if strings.Contains(err.Error(), "can't find pane") {
fmt.Printf("Stale session detected, recreating...\n")
_ = t.KillSession(sessionID)
return runCrewAt(cmd, args) // Retry with fresh session
}
return fmt.Errorf("restarting runtime: %w", err) return fmt.Errorf("restarting runtime: %w", err)
} }
} }