From 59aa1733843c19ae66595efd3610d1062086f5fd Mon Sep 17 00:00:00 2001 From: jordan Date: Sat, 7 Feb 2026 08:51:34 -0700 Subject: [PATCH] fix: clear stale error when dequeuing work tasks When a task is retried (dequeued again after failure), the previous error message was persisting in the work_queue table. This caused the API to return confusing responses with status="running" but also containing an error message from the previous attempt. Now clears error and completed_at when claiming a task, matching the fix already applied to build_audit.UpdateStatus. Co-Authored-By: Claude Opus 4.5 --- internal/adapter/postgres/work_queue.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/internal/adapter/postgres/work_queue.go b/internal/adapter/postgres/work_queue.go index d0cdbff..c14a731 100644 --- a/internal/adapter/postgres/work_queue.go +++ b/internal/adapter/postgres/work_queue.go @@ -60,9 +60,11 @@ func (r *WorkQueueRepository) Dequeue(ctx context.Context, workerID string) (*do var resultJSON []byte var errorMsg sql.NullString + // Clear stale error/completed_at when claiming for execution or retry. + // This prevents the API from returning confusing "running" status with stale error messages. err := r.db.QueryRowContext(ctx, ` UPDATE work_queue - SET status = 'running', worker_id = $1, started_at = NOW() + SET status = 'running', worker_id = $1, started_at = NOW(), error = NULL, completed_at = NULL WHERE id = ( SELECT id FROM work_queue WHERE status = 'pending'