Repository navigation
feat(worker): At most one work item per storage config runs at a time (#337) - #356
Merged
Merged
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…#337) The claim passes over a storage config that already has a Running item, and a partial unique index on running items' StorageConfigId rejects a racing second claim, which then returns nothing until the next poll. Unscoped items are not serialised. An attempt whose heartbeats have not reached the database for half a lease cancels its handler on a timer of its own and writes nothing, so it has stopped before another Worker can recover its lease and claim work for the same config. Each heartbeat call is limited to one interval, and WorkLeaseSeconds must now exceed four heartbeats. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The lease is extended from the moment a heartbeat is sent, so the self-stop now restarts from there rather than from its answer, keeping the full half-lease margin. The end of a run waits for a heartbeat in flight again, bounded by its one-interval limit, so a Lost answer is never dropped. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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 #337. Design: note, as amended by the decision.
Summary
At most one work item per storage config is
Running, across all Workers. Unscoped items are not serialised.IX_WorkItems_StorageConfigIdis now declared explicitly, because EF otherwise drops it in favour of the partial index.WorkerSettings:WorkLeaseSeconds / 2must exceed2 × WorkHeartbeatSeconds(was: lease > heartbeat). With each beat limited to one interval, two answered beats can be two intervals apart; a shorter half-lease would self-stop against a slow but healthy database. Defaults (60 / 2) pass.docs/architecture/work-queue.mdandschema.sqlupdated.chorecommits refresh test projects'packages.lock.jsonleft stale by Bump the nuget group with 17 updates #353.Evidence
ClaimAsync_AnotherClaimOfTheSameConfigCommitsFirst_…(another transaction's uncommitted claim of config C; the claim must block on the index, verified throughpg_stat_activity) failed withNOT EXISTSalone: the claim took C's second item without blocking.After: blocks on the index and returns
nullafter the commit. Integration suite 80/80.FailAsync.After:
WorkExecutorTests(Timeline): handler cancelled at half a lease and not before; a successful (or slow) beat restarts it from its send time; a heartbeat that never answers still self-stops and is given up after one interval; a self-stopped attempt writes nothing, even if its handler finishes. 33/33, stable over 20 runs.scripts/mutation-changed.sh: Anichron.Core 100.00 %, Anichron.Worker 100.00 %.Merge Danger
Door: two-way
The index can be dropped in a later migration; the executor change reverts cleanly.
Blast Radius: Worker
A database outage longer than half a lease now restarts running work (a long first crawl included) and counts a stall; the
WorkMaxStallsth such outage fails the item (accepted in decision 4). Workers configured with a lease ≤ 4 heartbeats now fail at startup.🤖 Generated with Claude Code