crash report updates 3-10-26

This commit is contained in:
jester 2026-03-10 18:29:40 +00:00
parent b7afe5733a
commit 243a201a64
2 changed files with 38 additions and 12 deletions

View File

@ -72,6 +72,7 @@ type agentStatus struct {
lastError error
crashCount int
lastCrash time.Time
intentionalStop bool
ready bool
readySource string
readyError string
@ -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)

View File

@ -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