diff --git a/scripts/stage2_worker.py b/scripts/stage2_worker.py index b8df56f..61064d6 100644 --- a/scripts/stage2_worker.py +++ b/scripts/stage2_worker.py @@ -220,8 +220,15 @@ def enqueue_stage3(pg, source, full_text, orientation, metadata, supersedes_prior_state = EXCLUDED.supersedes_prior_state, state_type_rationale = EXCLUDED.state_type_rationale, enqueued_at = NOW(), + -- Reset all run-state fields on re-enqueue. Without this, + -- stale started_at from a prior attempt makes the row + -- invisible to the Stage 3 worker's claim filter (which + -- typically uses started_at IS NULL). + started_at = NULL, completed_at = NULL, failed_at = NULL, + failure_reason = NULL, + external_job_id = NULL, attempts = 0 """, (source, full_text, orientation, json.dumps(metadata), state_type, state_type_confidence, supersedes_prior_state,