Lease acquisition, renewal, and expiry¶
A node keeps its own record of every assignment it is working on. The control plane's lease on the assignment ledger is the authority over who may work on an assignment. The node's local lease is the state that makes its own workers exclusive with each other and makes a crash recoverable. This page covers that record, its three states, the time it is held for, and the refusals each transition produces.
The ledger lease and the claim protocol are on Assignment claim protocol.
The record¶
{
"assignment_id": "asg-71c4...",
"run_id": "run-3f09...",
"session_id": "ses-8ad2...",
"worker_id": "local-worker",
"attempt": 1,
"status": "claimed",
"lease_expires_at": 1771459230.0,
"claim_count": 1,
"created_at_epoch": 1771459200.0,
"updated_at_epoch": 1771459200.0
}
The records live in one state file in the process working area, keyed by assignment id, beside the execution dedupe records. Every read and write takes an exclusive lock on a sibling lock file, so two workers in one process see one view. See Durable node state layout.
The three states¶
flowchart LR
N(["No record"])
C["claimed<br/>lease_expires_at in the future"]
R["released"]
E["expired"]
N -->|"claim"| C
C -->|"claim by the same worker"| C
C -->|"renew"| C
C -->|"release"| R
C -->|"expiry swept"| E
E -->|"claim"| C
R -->|"claim"| C
C -->|"recovered at startup"| E
claimed is the only state that holds an assignment. Both released and
expired are claimable again, so a retried or recovered assignment is taken by
the same node with the record left in place.
recovered at startup is the sweep a new process runs over claims left by the
one it replaced.
Claiming¶
The default lease is held for 30 seconds, and a caller may ask for a different duration. A claim against an existing record takes one of three paths:
| The existing record | Outcome |
|---|---|
claimed, unexpired, held by a different worker |
Refused with assignment already claimed by another worker |
claimed, unexpired, held by the same worker |
The claim stands, with its claim count unchanged |
| Released, expired, or absent | Claimed, with the claim count raised by one |
The second path makes a claim idempotent for its holder, so a worker that claims the same assignment twice within one lease holds it once. The claim count is the count of distinct holds, so a first hold and a recovered one stay distinguishable in the record.
The record's created_at_epoch is preserved across re-claims, so the age of the
hold on an assignment survives the renewals and recoveries inside it.
Renewing¶
A renewal extends the expiry from the present moment. It requires a record in
claimed whose expiry has not passed:
| Condition | Refusal |
|---|---|
| No record for that assignment id | assignment lease not found |
The record is released or expired |
assignment lease is not in claimed state |
| The expiry has already passed | assignment lease is expired and cannot be renewed |
An expired lease is re-claimed. A re-claim raises the claim count and a renewal does not, so the record keeps the difference between a continuous hold and a hold that lapsed.
Expiry¶
Each cycle sweeps the records: every lease in claimed whose expiry has passed
moves to expired, and the sweep returns how many it moved. The expiry is the
node's own statement that it is no longer working on that assignment, and it lets another worker in the same process pick it up.
The control plane runs the same clock independently against its ledger lease. A node that stops renewing loses the ledger lease too, and the assignment is dispatched again. See Assignments and leases during a break.
Releasing¶
A release moves the record to released and sets its expiry to zero. A release
for an assignment with no record returns a result naming the assignment with a
status of missing, so finalizing an assignment whose record has already gone
completes and reports that status.
Related¶
- Lease dedupe and finalize for startup recovery and the finalize path.
- Lease acquisition, dedupe, and finalize for the two records of one hold in the assignment pipeline.
- Leases held at crash time for what a crash leaves behind.