diff --git a/internal/store/runs.go b/internal/store/runs.go index 9f40b0d..77c7ba3 100644 --- a/internal/store/runs.go +++ b/internal/store/runs.go @@ -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 }