[FIX] queue_job: apply max_retries to PostgreSQL concurrency errors #1009
All Vouch review confidence checks passed
Residual risk 0.28 = Change Risk (0.50) × (1 − Review Confidence (0.45)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.50 · 367 lines diff across 4 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.353
Shallow Review Depth
shallow_review_depth
0.344
Real PR Conversation Timeline
1 comments
"Review active on #1009"
general
weight: 0.35
RicardCForgeFlow
The problem
The typical PostgreSQL transaction serialization errors are retried, but the conversion from
OperationalErrortoRetryableJobErrorhappens in the runners, outsideJob.perform()— andperform()is the only placemax_retriesis consulted.queue_job/controllers/main.pywraps_try_perform_joband raisesRetryableJobErrorfrom there; the surroundingexcept RetryableJobErrorcallsretry_postpone(), which writes a new eta and requeues.queue_job_cron_jobrunner/models/queue_job.pydoes the same inline, callingpostpone()+set_pending(reset_retry=False)directly.Neither consults
max_retries.perform()has already incrementedretryby the time the error surfaces, so a job that keeps colliding is retried for ever while its counter climbs past the limit, and it never reachesfailed.Seen in production on a long report-building job: it sat at try 10 of a maximum of 5, each attempt running for about eight minutes, until it was closed by hand.
The change
Convert the error inside
Job.perform()instead, so it falls into theRetryableJobErrorhandling already there and is subject tomax_retrieslike any other retryable error:The duplicated handling then comes out of both runners, and
PG_RETRYmoves besideDEFAULT_MAX_RETRIESinjob.py. Net effect is a deletion: one conversion in one place, and both runners behave identically._enqueue_dependent_jobskeeps its ownOperationalErrorhandling — that is a separate retry loop around the dependency update, not around the job.Behaviour
| | before | after |
|---|---|---|
| serialization failure, under
max_retries| postponed | postponed, unchanged || serialization failure, at
max_retries| postponed for ever |FailedJobError, job fails || any other
OperationalError| fails the job | fails the job, unchanged ||
max_retries = 0| infinite | infinite, unchanged |Tests
test_queue_jobgains araise_pg_concurrencyoption ontesting_method, backed by a smallOperationalErrorsubclass — psycopg2 exposespgcoderead-only anderrors.lookup()leaves it unset, so the code has to be carried that way. Two cases intest_job.py, mirroring the existingtest_retryable_error:max_retriesOperationalErroris not retriedFull suite on 19.0: 186 tests, 0 failed, 0 errors (
queue_job,test_queue_job,queue_job_cron_jobrunner).