Repository navigation
feat(task-queue): capped stalled-job recovery as a supervised ops loop - #590
aivong-openhands wants to merge 1 commit into
Conversation
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
||||||||||||||||||||||||||||||||||||
2df3394 to
4595f83
Compare
a22c7d3 to
5092d31
Compare
4595f83 to
45286ad
Compare
5092d31 to
940abb6
Compare
45286ad to
9a1cb45
Compare
Recovery is not a Procrastinate task: a locked recovery task whose worker died would block every later occurrence of itself. Each ops worker runs it on a thread with a dedicated connection instead. - One bounded transaction per pass under pg_try_advisory_xact_lock, so replicas coordinate under every pooling mode; a busy lock skips. - Candidates are Class A queues only (business, ops) whose worker's heartbeat is older than stalled_worker_timeout, or whose worker row was pruned. - Each candidate is re-read FOR UPDATE and revalidated (same worker_id, same attempts, worker still stale) before retry_job_v2 or finish_job: retry_job_v2 checks neither worker nor attempt, so a stale selection could requeue a healthy execution. - Capped at MAX_ATTEMPTS executions; the last is failed, not retried. - Each pass registers a deadline with the watchdog, so a pass hung on a black-holed socket still ends in a bounded self-exit. - Retention deletes final-state jobs past TASK_QUEUE_RETENTION_HOURS in batches, skipping jobs a periodic_defers row still references. OHE-3417 (Track 1, T1.6, T1.7.1) Co-authored-by: openhands <openhands@all-hands.dev>
940abb6 to
13e607c
Compare
9a1cb45 to
af1314e
Compare
|
Closing this in favour of #602, which does the same job out of the box.
The design argument in the PR description doesn't hold either. I had it that recovery can't be a Procrastinate task, because the job would stay One gap I'll raise on #602 separately: I'm re-examining #589 (the local watchdog) on the same grounds. Its premise is that a hung job keeps the heartbeat alive so stalled detection never fires, but that only holds for an async job awaiting something that never returns, and a per-task Net effect on the stack: this PR closes, #591 and #592 rebase onto #589, and the worker in #588 uses the housekeeping from #602 instead of its own. This comment was drafted by an AI agent (OpenHands) on behalf of @aivong. |
Stack 5/7: OHE-3417 Track 1. Based on #589. Implements T1.6 (
retry_stalled_jobsandremove_old_jobs) and T1.7.1.Why not a Procrastinate task
procrastinate_fetch_job_v2rejects a candidate whoselockmatches a job alreadydoing. If recovery were a locked periodic task and its worker died mid-run, every later occurrence would be unfetchable, and the only thing that could clear it is the task that can no longer run. Recovery would deadlock itself. Instead, each ops worker runs it as a timer thread with a dedicated connection, with no queue row and no execution lock.Design
pg_try_advisory_xact_lock. Transaction-scoped, so replicas coordinate under every pooling mode, including PgBouncer transaction pooling. A busy lock skips the pass. Passes are batch-limited.business,ops) are recovery candidates, and only when the worker's heartbeat is older thanstalled_worker_timeoutor its row was pruned. Class B work (Track 2) is excluded by filter, not convention.FOR UPDATEand must still have the sameworker_id, the sameattempts, and a stale worker.retry_job_v2checks neither worker nor attempt, so acting on a stale selection could requeue a healthy execution.MAX_ATTEMPTS. The last attempt isfailed, not retried, so a poison job cannot restart a worker every minute forever.TASK_QUEUE_RETENTION_HOURS(168) in batches. It skips jobs still referenced byprocrastinate_periodic_defers, whose FK has noON DELETE.Tests
Real Postgres. The recovery unit suite covers:
Also an end-to-end process test (#13): a frozen business worker self-exits, a separate ops process recovers the job, and a fresh business worker completes it.
This PR was created by an AI agent (OpenHands) on behalf of the user.
@aivong-openhands can click here to continue refining the PR
Enterprise server image for this PR: