fix(runs): stamp completed_at on cancel/terminal SetState transitions
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:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user