Atomic task claims
Status: Ready
Article ID: 033
Truth label: Current
Audience: Backend builder
Reader outcome: Explain why Central rechecks eligibility inside one claim transaction and what state becomes durable together.
Related articles: 004, 031, 054
Target week: 13
Last verified: 2026-09-13
Technical reviewer: Codex source audit
Editorial reviewer: Codex editorial audit
Separate selection from ownership
GET /tasks/next finds the highest-priority task that appears eligible for a
worker. That read is advisory. Another worker or operator can change state
before the first worker submits its claim.
Ownership begins only when POST /tasks/{id}/claim succeeds. A client must not
start repository work from the selection response alone.
Recheck inside the transaction
The claim path opens the store transaction and then reads the current task and worker again. It verifies that the task is still pending, the worker exists, the pin matches, the engine is available, required capabilities are present, and the parent dependency is complete.
This closes the time-of-check to time-of-use gap between polling and claiming. If any condition changed, the claim returns a conflict instead of creating split ownership.
Commit the ownership bundle
One successful transaction persists:
- task state changed to assigned
- assigned worker id
- start time
- incremented run attempt and fence
- new run UUID
- lease row with expiry
- worker state changed to busy with the current task
- run-token hash for a credentialed claim
Either that bundle commits or it does not. A crash cannot legitimately leave the task assigned while the worker remains idle because those writes belong to one transaction.
Handle duplicate claim attempts
Central also serializes the claim route at the process level while SQLite provides the durable transaction. Two workers can both see the same pending candidate, but only the first valid claim changes it from pending. The second recheck sees the changed state and receives a conflict.
The losing worker should poll again. It should not retry execution against the same checkout or reinterpret the conflict as permission to proceed.
Verify a claim response
Before launching an engine, the worker needs the served task plus:
- run id
- run attempt
- lease fence and TTL
- run token when issued
Every lease renewal, log report, and result must carry the current attempt identity and required credential. The worker should stop if lease renewal says it no longer owns the claim.
Current limits
Atomic claim state prevents duplicate ownership of a task. It does not lock a repository checkout across different tasks, make SQLite a distributed database, or contain subprocess effects. Central still requires one active writer on a native data root.
Next lesson
Continue with Route tasks by engine and capability.
Derivative map
- Weekly package: WEEK-13
- Long video: VIDEO-W13-LONG
- Shorts: SHORT-W13-PROBLEM, SHORT-W13-MECHANISM, SHORT-W13-WARNING
- Email: EMAIL-W13
- LinkedIn: LI-W13-A, LI-W13-B
- X: X-W13-A, X-W13-B
- Visual: VISUAL-W13
Review record
- Candidate selection, claim rechecks, transaction fields, and conflict behavior checked against current source.
- Checkout, subprocess, data-root, and distributed-database limits reviewed.
- Claim checklist includes run, fence, lease, and credential identity.
- Internal links and repository voice reviewed.
Review completed: 2026-08-27
Re-audited against the running product: 2026-09-13