From 243a201a646c3c8b203e0d10d8f63001fb017283 Mon Sep 17 00:00:00 2001 From: jester Date: Tue, 10 Mar 2026 18:29:40 +0000 Subject: [PATCH] crash report updates 3-10-26 --- internal/state/state.go | 42 ++++++++++++++++++++++++++++---------- internal/system/process.go | 8 +++++++- 2 files changed, 38 insertions(+), 12 deletions(-) diff --git a/internal/state/state.go b/internal/state/state.go index ead1913..1f65fc3 100755 --- a/internal/state/state.go +++ b/internal/state/state.go @@ -65,17 +65,18 @@ const ( ----------------------------------------------------------------------------*/ type agentStatus struct { - mu sync.Mutex - state AgentState - lastChange time.Time - installStep string - lastError error - crashCount int - lastCrash time.Time - ready bool - readySource string - readyError string - lastReadyAt time.Time + mu sync.Mutex + state AgentState + lastChange time.Time + installStep string + lastError error + crashCount int + lastCrash time.Time + intentionalStop bool + ready bool + readySource string + readyError string + lastReadyAt time.Time } var global = &agentStatus{ @@ -141,6 +142,12 @@ func GetLastReadyAt() time.Time { return global.lastReadyAt } +func IsIntentionalStop() bool { + global.mu.Lock() + defer global.mu.Unlock() + return global.intentionalStop +} + /* -------------------------------------------------------------------------- STATE SETTERS — unified with logging ----------------------------------------------------------------------------*/ @@ -168,6 +175,18 @@ func SetError(err error) { global.lastError = err } +func MarkIntentionalStop() { + global.mu.Lock() + defer global.mu.Unlock() + global.intentionalStop = true +} + +func ClearIntentionalStop() { + global.mu.Lock() + defer global.mu.Unlock() + global.intentionalStop = false +} + func RecordCrash(err error) { global.mu.Lock() defer global.mu.Unlock() @@ -178,6 +197,7 @@ func RecordCrash(err error) { global.lastError = err global.crashCount++ global.lastCrash = time.Now() + global.intentionalStop = false global.ready = false global.readySource = "" global.readyError = fmt.Sprintf("%v", err) diff --git a/internal/system/process.go b/internal/system/process.go index f431745..ed2e182 100755 --- a/internal/system/process.go +++ b/internal/system/process.go @@ -64,6 +64,7 @@ func StartServer(cfg *state.Config) error { serverCmd = cmd serverPTY = ptmx + state.ClearIntentionalStop() state.SetState(state.StateRunning) state.SetError(nil) state.SetReadyState(false, "", "") @@ -78,7 +79,11 @@ func StartServer(cfg *state.Config) error { _ = serverPTY.Close() } - if err != nil { + if state.IsIntentionalStop() { + state.ClearIntentionalStop() + state.SetState(state.StateIdle) + state.SetReadyState(false, "", "") + } else if err != nil { state.RecordCrash(err) } else { state.SetState(state.StateIdle) @@ -105,6 +110,7 @@ func StopServer() error { } state.SetState(state.StateStopping) + state.MarkIntentionalStop() state.SetReadyState(false, "", "") // Try graceful stop