fix(runs): stamp completed_at on cancel/terminal SetState transitions
CI / Lint + build + test (push) Successful in 1m35s
Release / release (push) Successful in 11m53s

CancelRun goes through Runner.Transition → Runs.SetState, which was a
bare UPDATE state=? with no completed_at write. The host-page
runDuration helper treats nil CompletedAt as "still running", so a
cancelled run kept ticking forever. MarkCompleted / MarkFailed /
MarkDispatchFailed already stamp completed_at; SetState now does the
same for any terminal target state, using COALESCE so we never
clobber an already-set timestamp.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-04-19 20:21:39 -04:00
parent bbe1b19819
commit 988448664a
+7
View File
@@ -45,6 +45,13 @@ func (r *Runs) CreateWithProfile(ctx context.Context, hostID int64, tokenHash st
}
func (r *Runs) SetState(ctx context.Context, runID int64, state model.RunState) error {
if state.IsTerminal() {
_, err := r.DB.ExecContext(ctx, `
UPDATE runs SET state = ?, completed_at = COALESCE(completed_at, ?)
WHERE id = ?
`, string(state), time.Now().UTC(), runID)
return err
}
_, err := r.DB.ExecContext(ctx, `UPDATE runs SET state = ? WHERE id = ?`, string(state), runID)
return err
}