refactor(witness,refinery): ZFC-compliant state management
Remove state files from witness and refinery managers, following the "Discover, Don't Track" principle. Tmux session existence is now the source of truth for running state (like deacon). Changes: - Add IsRunning() that checks tmux HasSession - Change Status() to return *tmux.SessionInfo - Remove loadState/saveState/stateManager - Simplify Start()/Stop() to not use state files - Update CLI commands (witness/refinery/rig) for new API - Update tests to be ZFC-compliant This fixes state file divergence issues where witness/refinery could show "running" when the actual tmux session was dead. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
committed by
Steve Yegge
parent
126ec84bb3
commit
5218102f49
@@ -977,8 +977,7 @@ func runRigShutdown(cmd *cobra.Command, args []string) error {
|
||||
|
||||
// 2. Stop the refinery
|
||||
refMgr := refinery.NewManager(r)
|
||||
refStatus, err := refMgr.Status()
|
||||
if err == nil && refStatus.State == refinery.StateRunning {
|
||||
if running, _ := refMgr.IsRunning(); running {
|
||||
fmt.Printf(" Stopping refinery...\n")
|
||||
if err := refMgr.Stop(); err != nil {
|
||||
errors = append(errors, fmt.Sprintf("refinery: %v", err))
|
||||
@@ -987,8 +986,7 @@ func runRigShutdown(cmd *cobra.Command, args []string) error {
|
||||
|
||||
// 3. Stop the witness
|
||||
witMgr := witness.NewManager(r)
|
||||
witStatus, err := witMgr.Status()
|
||||
if err == nil && witStatus.State == witness.StateRunning {
|
||||
if running, _ := witMgr.IsRunning(); running {
|
||||
fmt.Printf(" Stopping witness...\n")
|
||||
if err := witMgr.Stop(); err != nil {
|
||||
errors = append(errors, fmt.Sprintf("witness: %v", err))
|
||||
@@ -1077,14 +1075,9 @@ func runRigStatus(cmd *cobra.Command, args []string) error {
|
||||
fmt.Printf("%s\n", style.Bold.Render("Witness"))
|
||||
witnessSession := fmt.Sprintf("gt-%s-witness", rigName)
|
||||
witnessRunning, _ := t.HasSession(witnessSession)
|
||||
witMgr := witness.NewManager(r)
|
||||
witStatus, _ := witMgr.Status()
|
||||
_ = witness.NewManager(r) // silence unused warning, manager created for consistency
|
||||
if witnessRunning {
|
||||
fmt.Printf(" %s running", style.Success.Render("●"))
|
||||
if witStatus != nil && witStatus.StartedAt != nil {
|
||||
fmt.Printf(" (uptime: %s)", formatDuration(time.Since(*witStatus.StartedAt)))
|
||||
}
|
||||
fmt.Printf("\n")
|
||||
fmt.Printf(" %s running\n", style.Success.Render("●"))
|
||||
} else {
|
||||
fmt.Printf(" %s stopped\n", style.Dim.Render("○"))
|
||||
}
|
||||
@@ -1092,16 +1085,10 @@ func runRigStatus(cmd *cobra.Command, args []string) error {
|
||||
|
||||
// Refinery status
|
||||
fmt.Printf("%s\n", style.Bold.Render("Refinery"))
|
||||
refinerySession := fmt.Sprintf("gt-%s-refinery", rigName)
|
||||
refineryRunning, _ := t.HasSession(refinerySession)
|
||||
refMgr := refinery.NewManager(r)
|
||||
refStatus, _ := refMgr.Status()
|
||||
refineryRunning, _ := refMgr.IsRunning()
|
||||
if refineryRunning {
|
||||
fmt.Printf(" %s running", style.Success.Render("●"))
|
||||
if refStatus != nil && refStatus.StartedAt != nil {
|
||||
fmt.Printf(" (uptime: %s)", formatDuration(time.Since(*refStatus.StartedAt)))
|
||||
}
|
||||
fmt.Printf("\n")
|
||||
fmt.Printf(" %s running\n", style.Success.Render("●"))
|
||||
// Show queue size
|
||||
queue, err := refMgr.Queue()
|
||||
if err == nil && len(queue) > 0 {
|
||||
@@ -1254,8 +1241,7 @@ func runRigStop(cmd *cobra.Command, args []string) error {
|
||||
|
||||
// 2. Stop the refinery
|
||||
refMgr := refinery.NewManager(r)
|
||||
refStatus, err := refMgr.Status()
|
||||
if err == nil && refStatus.State == refinery.StateRunning {
|
||||
if running, _ := refMgr.IsRunning(); running {
|
||||
fmt.Printf(" Stopping refinery...\n")
|
||||
if err := refMgr.Stop(); err != nil {
|
||||
errors = append(errors, fmt.Sprintf("refinery: %v", err))
|
||||
@@ -1264,8 +1250,7 @@ func runRigStop(cmd *cobra.Command, args []string) error {
|
||||
|
||||
// 3. Stop the witness
|
||||
witMgr := witness.NewManager(r)
|
||||
witStatus, err := witMgr.Status()
|
||||
if err == nil && witStatus.State == witness.StateRunning {
|
||||
if running, _ := witMgr.IsRunning(); running {
|
||||
fmt.Printf(" Stopping witness...\n")
|
||||
if err := witMgr.Stop(); err != nil {
|
||||
errors = append(errors, fmt.Sprintf("witness: %v", err))
|
||||
@@ -1387,8 +1372,7 @@ func runRigRestart(cmd *cobra.Command, args []string) error {
|
||||
|
||||
// 2. Stop the refinery
|
||||
refMgr := refinery.NewManager(r)
|
||||
refStatus, err := refMgr.Status()
|
||||
if err == nil && refStatus.State == refinery.StateRunning {
|
||||
if running, _ := refMgr.IsRunning(); running {
|
||||
fmt.Printf(" Stopping refinery...\n")
|
||||
if err := refMgr.Stop(); err != nil {
|
||||
stopErrors = append(stopErrors, fmt.Sprintf("refinery: %v", err))
|
||||
@@ -1397,8 +1381,7 @@ func runRigRestart(cmd *cobra.Command, args []string) error {
|
||||
|
||||
// 3. Stop the witness
|
||||
witMgr := witness.NewManager(r)
|
||||
witStatus, err := witMgr.Status()
|
||||
if err == nil && witStatus.State == witness.StateRunning {
|
||||
if running, _ := witMgr.IsRunning(); running {
|
||||
fmt.Printf(" Stopping witness...\n")
|
||||
if err := witMgr.Stop(); err != nil {
|
||||
stopErrors = append(stopErrors, fmt.Sprintf("witness: %v", err))
|
||||
|
||||
Reference in New Issue
Block a user