fix: prevent transient failed status when interrupting sessions

When a session is interrupted, there's a race condition where the monitor
goroutine sees the process exit with an error and briefly marks the session
as failed before it transitions to completed. This fix checks if the session
is in "completing" status (indicating an intentional interrupt) before
marking it as failed, eliminating the transient failed status in the UI.
This commit is contained in:
Allison Durham
2025-07-01 12:16:34 -07:00
parent 55a810b74a
commit 4eb48dfedd

View File

@@ -277,7 +277,17 @@ eventLoop:
endTime := time.Now()
if err != nil {
// Check if this was an intentional interrupt
session, dbErr := m.store.GetSession(ctx, sessionID)
if dbErr == nil && session != nil && session.Status == string(StatusCompleting) {
// This was an interrupted session, not a failure
// Let it transition to completed naturally
slog.Debug("session was interrupted, not marking as failed",
"session_id", sessionID,
"status", session.Status)
} else {
m.updateSessionStatus(ctx, sessionID, StatusFailed, err.Error())
}
} else if result != nil && result.IsError {
m.updateSessionStatus(ctx, sessionID, StatusFailed, result.Error)
} else {