fix: hand work back properly, and let go of what is gone - #138
Merged
Conversation
Three ways the queue mishandled a claim. **Retry actually retries (#126).** The route called `release(..., PENDING, error=None)`, which left `attempts` at the ceiling and wiped `last_error`. So retrying an exhausted item put it back to pending, the next claim scan retired it again before any worker saw it, and the reason it failed was destroyed on the way -- while the call reported `{"ok": true}`. `requeue` resets the counter and keeps the error. **A dead worker's claim is reclaimed (#104).** The lease is deliberately slow so a merely slow worker is not evicted, but after a pool restart the old worker is provably gone: its pid is not running. Waiting out its lease left an item stuck alongside newly dispatched work, with no session and nothing saying why. `reclaim_dead_workers` runs before a pool starts, and only for claims owned by this host -- a pid on another machine says nothing about whether it is alive. **A corrected graph stops work in flight (#107).** `claim` checked dependencies once; an operator correcting a plan minutes later did not stop an item that was no longer eligible from passing review, commit and push. The check is repeated at the last cheap point before review spends money, and the item goes back to pending with its branch intact. Nothing is killed mid-item.
thedancingdeveloper
force-pushed
the
fix/queue-lifecycle
branch
from
August 3, 2026 22:51
05d2809 to
cc097a2
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #126. Closes #104. Closes #107.
#126 — retry was a no-op on the state most likely to prompt it
POST /api/work/{id}/retrycalledrelease(item_id, PENDING, error=None).Two consequences neither intended nor visible:
attemptsuntouched, so an item atmax_attemptswas retired again by thenext claim scan before any worker saw it. Observed live:
exhausted → pending → exhaustedin seconds, with nothing having run.error=Nonewipedlast_error— the only record of why it failed, and whatthe retirement message appends to itself. So the retry downgraded a
diagnosable failure to
gave up after N attemptswith no cause.WorkQueue.requeueresets the counter and keeps the error.#104 — a claim held by a process that no longer exists
The lease is slow on purpose: a slow worker must not be evicted. But a worker
killed with its lease running leaves an item
claimedby a pid that is gone,unavailable to healthy workers, while new items dispatch around it.
reclaim_dead_workersruns at pool start and releases those claims. Boundedcarefully:
os.kill(pid, 0), wherePermissionErrorcounts as alive;OSErroris treated as alive, because releasing a liveworker's item is far worse than waiting out a lease.
Tests cover the dead pid, a live pid, and another host.
#107 — a corrected graph did not stop work already in flight
claimchecks dependencies once. Correcting a plan while an item is runningis a normal operator action, and the item went on through review, commit and
push on the strength of a check made minutes earlier.
unmet_dependenciesis now re-checked at the last cheap point before thereviewer is paid, and an invalidated item is emitted as
dependency_invalidatedand returned to pending with its branch intact. Noagent is killed mid-item, per the standing rule.
Suite, ruff and
mypy .green.