Skip to content

Lease acquisition, dedupe, and finalize

An assignment a node works on is held in two places: the control plane's ledger, which decides who owns it, and a local claim the node keeps while it works. This page is the local claim: when it is taken, what refuses it, how a new process clears claims left behind, and what finalize releases, so a node's own record of what it holds can be read against the ledger's.

For the ledger lease, its 30 second life and its fence, see Assignment claim protocol and The assignment ledger.

Two records of one hold

flowchart LR
  subgraph CP["CONTROL PLANE"]
    direction TB
    LED[("Ledger lease<br/>owner, fence, expiry")]
  end
  subgraph XD["XRATUD, one process"]
    direction TB
    LC[("Local claim<br/>worker, attempt, expiry")]
    EX[("Execution record<br/>started, then terminal")]
    LC --- EX
  end
  LED -->|"fence travels on the assignment"| XD

The ledger lease is the one that decides ownership, and every report is checked against its fence. The local claim and the execution record sit beside each other in the process's lease state and belong to that process: they keep one worker from taking an assignment another holds, and one execution from running twice, for as long as the process runs.

The local claim

Preparation takes the local claim before anything else touches the assignment. The claim is recorded under the node label as its worker, for the assignment's attempt, with a time to live of twice the heartbeat interval and never less than 5 seconds: 30 seconds with the default 15 second heartbeat.

The claim finds Outcome
No record, or one that is released or expired A new claim, and the claim count advances
A live claim by the same worker The claim is extended with the same count
A live claim by another worker Refused: assignment already claimed by another worker

A claim moves through three states:

stateDiagram-v2
  [*] --> claimed
  claimed --> claimed: renewed while unexpired
  claimed --> released: finalize
  claimed --> expired: past its expiry, or recovered at process start
  released --> claimed: claimed again
  expired --> claimed: claimed again

A claim is renewed only while it is claimed and unexpired. Renewing a released or expired claim is refused, so a claim that lapsed has to be taken again rather than silently extended.

Recovery, once per process

The first cycle of a process runs claim recovery once. Every claim recorded as claimed by this node's worker is marked expired, and every other claim past its expiry is expired too. A recovery that changed anything logs one warning with both counts:

recovered stale worker claims during startup
recovered_claims, expired_due_claims

A new process starts with empty lease state, so recovery usually has nothing to do. The work those claims covered is decided by the ledger: its leases lapse when nobody renews them, and the assignment is claimed again with a new fence.

Dedupe before execution

After the claim, preparation opens the assignment's execution record. A record already terminal means this execution has finished before, and the assignment is reported as a replay instead of running. See Idempotency and dedupe contracts.

Finalize

Every assignment that reached a route is finalized, whether the route succeeded, failed, or raised. Finalize does two things:

  1. If the route started a runtime and returned its handle, the runtime is stopped. A stop that fails is logged as runtime stop failed with the error, and finalize continues.
  2. The local claim is released.

An assignment deduplicated as a replay returns before it reaches a route, so its local claim is left to expire with its time to live.