xai / grok-4.7-efficient / low / low effort preferred over xai / grok-4.7-efficient / high / high effort · close win.
Primary judge: Sol 6.1, requested Low. Effective provider effort and internal attempts were not verified. A close win is still a scored preference; it does not establish a material defect.
Reviewed public evidence
Task goal
Review the worker-queue claim and completion lifecycle for stuck work, duplicate execution, or incorrect capacity accounting after retries and worker interruption. Trace an exact plausible failure state through the provided code, identify whether the queue recovers, and recommend the smallest safe change plus focused failure-injection checks.
xai / grok-4.7-efficient / low / low effort answer
The queue does not self-heal a `/complete` that waits for a slot while holding the job row lock. Under a completion storm the worker’s heartbeats cannot refresh the lease, the wait ends in 503, the retry is 410, and the row stays `running` until an external reaper.
**Failure state.** Job 42 is `running`, `attempt_count=1`, `leased_until` still in the future, worker heartbeats every 60s. Other `/complete` calls already hold every `WORKER_COMPLETE_MAX_CONCURRENT` slot (`worker_complete_slots.py` 65–83).
1. `complete_job` locks job 42 with `FOR UPDATE` and `_validate_claim` succeeds (`worker_queue.py` 7823–7936).
2. PDF-full, convert-only, mdb, and review-pack then call `_complete_with_tenant_slots` without releasing that lock (7987–8096). Only the Apple Vision branch rollbacks first (8016).
3. `acquire_complete_slots` waits up to `WORKER_COMPLETE_SLOT_WAIT_TIMEOUT_S` (65–93). Heartbeat for job 42 also takes `FOR UPDATE` (3761–3776) and blocks behind that wait, so `leased_until` is not extended (3779).
4. While the slot pool stays saturated, each Mac 5xx retry repeats steps 1–3 and keeps pinning the row for the whole wait. Heartbeats never land. The lease expires.
5. The in-flight wait then raises 503 (`worker_queue.py` 5980–6004). The retry calls `_validate_claim`, sees `leased_until <= now`, and gets 410 (2385–2397). The worker is specified to stop on 410.
6. Claim will not take the row: status is still `running`, and the same-worker check requires `leased_until > now` (3028–3043, 3119–3120). `/fail` and `/release` also 410 before any requeue (8544–8564, 8686).
Recovery is not in these three files. Comments point at `scheduler.py`’s lease reaper, which is outside this packet. Until that reaper runs, the job is stuck and the API key still counts the expired lease only after `leased_until` passes (3009–3015), so the stuck row itself does not hold the concurrency cap — it simply never returns to `pending`.
**Smallest safe change.** After the initial claim check in `complete_job`, snapshot the fields the branches need and `await db.rollback()` before `_complete_with_tenant_slots`, matching the Apple Vision path at 8016. Inside the slotted helper, re-lock the job and call `_validate_claim` before any mutation (AV persist already does this at 6419–6432). Do not clear the token on the 503 path.
Also make slot acquire cancellation-safe. The increment is inside `_wait_and_enter` (79–86), but the decrement runs only after `wait_for` returns and the context is yielded (92–109). A client disconnect or `wait_for` timeout that cancels the waiter after the increment never enters that `finally`, so `_global_in_flight` / `_muni_in_flight` stay high until process restart and later completes 503 forever. Roll the increment back on `CancelledError` before re-raising.
**Discarded.** Idempotent claim replay and `SKIP LOCKED` prevent a second lease of the same job when `Idempotency-Key` is present (3028–3056, 3162–3168). Graceful release’s `attempt_count - graceful_release_count` discount (8689–8703) does not apply to `/fail` (8164), so interruptions still burn the real-failure budget — real, but it terminal-fails rather than sticking a live lease. A 429-before-replay at `MAX_ACTIVE_LEASES_PER_API_KEY` (3009–3026 vs 3042–3056) can block stale-lease self-heal, but only at the cap.
**Missing.** `get_db` transaction lifetime, `WORKER_COMPLETE_SLOT_WAIT_TIMEOUT_S`, and the reaper are outside the packet. If the dependency did not hold the transaction open across the slot wait, heartbeats would not stall; the slot-leak bug would remain.
**Checks.** Saturate complete slots, start `/complete`, and assert a concurrent heartbeat commits without waiting out the slot timeout. Cancel a waiter after the counter increments and assert `in_flight_counts()` returns to baseline. After a 503, assert the job is still `running` with the same `claim_token_hash` and a future `leased_until`, and that the next `/complete` is not 410.
xai / grok-4.7-efficient / high / high effort answer
The queue does not recover a job whose claim response is lost and whose worker keeps polling without a stable Idempotency-Key. The stale-lease self-heal requeues and re-claims that job in the same transaction with no retry ceiling, so the lease never expires and the attempt budget never trips.
**Conclusion.** The lost-response path documented at `worker_queue.py:142-156` becomes an unbounded reclaim loop. A claim can commit and still never deliver `claim_token`. The worker cannot heartbeat, complete, or release. The next `/claim` for that `worker_id` finds the live lease (`worker_queue.py:3028-3044`). Within 150 seconds it returns 409 (`worker_queue.py:3057-3067`). After 150 seconds the stale branch sets the row back to `pending` and clears the lease columns, but it does not read `attempt_count` and does not call `_max_attempts_for` or `_graceful_release_absolute_ceiling` (`worker_queue.py:3068-3086`). The same transaction then `SELECT … FOR UPDATE SKIP LOCKED` and re-claims that row: `attempt_count` increments and `leased_until` / `heartbeat_at` are refreshed (`worker_queue.py:3119-3167`, `3240-3248`). PostgreSQL does not skip a row this transaction already holds, and the pending update is invisible to other workers until commit, so the healed job is not offered to anyone else in between.
Each cycle also calls `record_claim_for_municipality` after commit (`worker_queue.py:3538-3551`) and keeps one API-key concurrency slot occupied (`leased_until > now` at `worker_queue.py:3009-3016`). `/fail` and `/release` both stop at a ceiling (`worker_queue.py:8164-8176`, `8684-8734`). `/release` even documents that a claim/release cycle with no charged failure must have an absolute ceiling or it loops forever (`worker_queue.py:8593-8604`). Stale reclaim is that same shape and has no ceiling. While this worker polls, the supplied code never terminal-fails the job and never lets the lease expire, so an expiry-based reaper cannot see it either.
A stable Idempotency-Key within 600 seconds does recover: replay rotates the token and does not increment `attempt_count` (`worker_queue.py:3046-3056`, `3217-3231`, `305-317`). Workers that omit the header are explicitly on the old path (`worker_queue.py:2941-2943`).
**Smallest safe change.** In the stale branch, before resetting the row to `pending`, if `attempt_count >= _graceful_release_absolute_ceiling(job.job_type)`, terminal-fail it with the same lease clear, footage-reuse restore, and media stamp `/release` already uses at the ceiling (`worker_queue.py:8726-8783`), audit, commit, and return `None`. Do not fall through into a new claim. Use the graceful absolute ceiling, not `_max_attempts_for` alone, so a few lost responses are not treated as real processing failures. No new column or response shape.
**Secondary capacity leak.** `acquire_complete_slots` increments `_global_in_flight` / `_muni_in_flight` inside the `asyncio.wait_for` task (`worker_complete_slots.py:78-88`) and decrements only after `wait_for` returns (`worker_complete_slots.py:99-109`). The timeout path raises and does not decrement (`worker_complete_slots.py:92-96`). If cancellation lands after the increment, during `Condition.__aexit__`, the slot stays taken and a cancelled lock release can wedge later acquires. Increment only after `wait_for` succeeds, and decrement in a `finally` that runs if and only if that increment happened.
**Discarded.** Idempotent `/complete`, `/fail`, and `/release` guards do stop completed-to-pending resurrection. `SKIP LOCKED` does stop two workers taking the same pending row. Claim-rate counts are not reversed on later release; that matches "successful claims," not a leak. The API-key cap is checked before replay/stale-heal (`worker_queue.py:2999-3026`), so a full cap delays self-heal, but the count itself drops when `leased_until` passes; that is delayed recovery, not the unbounded loop. Holding the job row lock across `/complete` storage I/O can stall heartbeats, but a finished or rolled-back request releases it.
**Missing.** `max_attempts_for` and the lease reaper live outside this packet (`app.constants.worker_job_types`, `scheduler.py`). If the worker stops polling, this code will not select a `running` row whose lease has already expired (`worker_queue.py:3119-3135`). Recovery then depends entirely on that reaper. Stale heal is also same-`worker_id` only; a restart that changes `worker_id` cannot clear the orphan here.
**Checks.** Drop the claim response and poll `/claim` with no Idempotency-Key: 409 until 150 seconds, then reclaim with `attempt_count` increased and `leased_until` refreshed; at the absolute ceiling the job must be `failed`, lease columns cleared, media not left `processing`, and a later claim must not re-lease it. Control: the same loss with a stable Idempotency-Key inside 600 seconds replays once, does not increment `attempt_count`, and does not terminal-fail. Separately, cancel `acquire_complete_slots` after a slot is taken and assert `in_flight_counts()` returns to zero.
Confidence: high on the stale-reclaim loop and that this code does not recover it while that worker polls. Medium on how often the complete-slot cancel window hits; the missing compensating decrement is structural.
Primary judge's stated reason
Weak, forced preference for A: its primary trace and revalidation-aware recommendation offer slightly better guidance for completion backpressure without requiring an unstated recurring transport failure. This is not an established material quality gap; B provides valuable complementary stale-reclaim coverage, and an independent review could prefer that emphasis.
This reason is the judge's assessment. No independent factual-defect finding is asserted by this record.
Battle wave: bc72a6bd-1168-4bad-b5a9-fbf90203e5d7. Pair: brp1_89e75fb1c5f24dc21827bf2383a5df0354f54e0027398ca3595c706868b80c2b. A separate independent review is required before calling a concern a verified factual defect. Judge disagreement is not recorded here.