Repository navigation
fix(platform): hand over a drained job only once its claim ended - #4003
Conversation
Independent review of #3985 at 5c17689: the draining worker's hand-over (jobs/runner.ts) discarded what boss.complete answered and sent the successor anyway. pg-boss completes active jobs only, so a claim cancelled between its fetch and its hand-over, or completed elsewhere meanwhile, answers { affected: 0 } and still got a successor, which can bring back withdrawn or finished work once no same-key job remains. The hand-over now reads both answers inside its one transaction. The claim is still completed first, and the successor still carries the job's own key, priority and payload, five seconds out. - affected 1: this worker's claim ended here, so the successor is sent. - affected 0: the claim was no longer active (cancelled, completed or expired), so nothing is sent and the empty transaction commits. The worker logs it, and pg-boss's own completion of the batch, which touches active jobs only, changes nothing. - Any other answer confirms nothing (pg-boss types the response as an empty interface), so the hand-over throws and rolls back, and the claim takes pg-boss's failure path under its queue's retry policy. - A refused successor (send answers null) collapses only on a short or stately queue, where the job already queued under the key does the work. The policy is pg-boss's own record of the queue, read on that path only. On any other policy, or a queue it cannot find, the hand-over rolls back. The transaction adapter is now one helper, bossDbInTx in jobs/enqueue.ts, used by addJobInTx and the hand-over alike. Proof: runner.test.ts covers each answer: affected 1, the real zero shape, six malformed answers, and a refusal on short and stately versus standard, exclusive, singleton, key_strict_fifo and a missing queue. It also shows both writes ride the transaction through the shared adapter. checkWorkerDrainHandOff adds, with the actual worker on real Postgres: - a claim cancelled between its fetch and its hand-over, and one completed elsewhere (each: no successor, the completion answering affected 0); - a real stately collapse; - through a scripted boss, since pg-boss does not give these answers there: a refused successor on a standard and on an exclusive queue, and an unconfirmed completion. Each rolls back: the claim ends failed with the reason, not completed, and nothing is sent. The manual register row says so. Refs #3977
The Type check job of e6bdde0 died with V8 heap exhaustion in the platform's tsc (exit 137, about 4 GB), not with a type error. Main's own run minutes earlier passed, and on the same scoped program this change adds 0.1% types and 0.08% instantiations. The token cannot re-run a job, so this empty commit re-runs the checks. Refs #3977
|
CI at
I left the type-check setup alone because it is outside this correction. One way to add headroom is to change the platform script to |
|
Merged through the normal protected squash path at All five normal workflows passed. The backend retry actually executed 1,225/1,225 checks across all 206 lanes, with no skips or failures, including the worker drain controls. The original ffmpeg prerequisite timeout is retained and tracked separately in #4010. Full platform typecheck, unit/component/browser checks, E2E, fresh platform-image production pruning, image validation 40/40, runtime 89/89 and smoke 29/29 passed; existing caches, inherited test skips and the advisory Trivy result remain explicit in the review evidence. Main advanced with the separately reviewed Gemini update while these checks ran. Independent source composition found no overlap and preserved both complete five-file changes. The actual squash commit has parent |
Fixes #4000. References #3977; broader capacity work remains open.
A draining worker could recreate cancelled or already-completed work because it ignored
boss.completeand always queued a successor. The hand-over now validates both results inside one transaction:affected: 1permits a successor;affected: 0stands down; malformed or unconfirmed completion rolls back. A null successor coalesces only under the supportedshort/statelyqueue policy; other policies or a missing queue roll back. The worker and normal enqueue path sharebossDbInTx, and the manual automation register names the new controls.The correction preserves the original key, priority, payload, delay and transaction order. Agent admission and the recheck queue are unchanged.
Validation:
bd4200dada9b66b587e201b2a23670351745f5fd: all five normal workflows passed. Strict hosted backend integration actually ran 1,225/1,225 checks across 206/206 lanes, including all 11 drain controls, with no skips or failures. One retained ffmpeg prerequisite timeout preceded a single successful normal retry; diagnostics are tracked in CI: make ffmpeg prerequisite timeouts diagnosable #4010.bd25a6acb64b5fce8215f9e888fd19a24ded4291preserved the exact reviewed fix plus the separately accepted, disjoint Gemini update on main. The combined tree matches the independent source-composition result. These PR checks tested the prior merge base; complete combined candidate validation is required before release.Final merge acceptance and proof boundaries. Historical failure and paired-control evidence remain in the review comments. No production test or recurring-cycle activation was performed.