Skip to content

The assignment ledger

The ledger is where an assignment's state, its lease and its write fence live. It decides which transitions are legal and which reports are accepted. This page is that state machine and the four fields every report is checked against.

Eight states, and the transitions between them

stateDiagram-v2
  [*] --> queued
  queued --> leased
  leased --> running
  running --> succeeded
  running --> failed
  queued --> cancelled
  leased --> cancelled
  running --> cancelled
  queued --> expired
  leased --> expired
  running --> expired
  queued --> superseded
  leased --> superseded
  running --> superseded
  leased --> failed

Five states are terminal: succeeded, failed, cancelled, expired and superseded. A terminal state has no outgoing transitions, so a report that would move an assignment out of one is refused with ASSIGNMENT_LEDGER_ILLEGAL_TRANSITION.

superseded is reachable from every live state, which is how a handover ends the previous assignment without waiting for the node that held it.

The ledger record and its writers

flowchart LR
  subgraph W["WRITERS"]
    direction TB
    CL["Claim<br/>from a node"]
    RP["Reports<br/>from the holding node"]
    RC["Lease recovery<br/>controller phase"]
    HO["Handover and cancel"]
  end
  subgraph REC["ONE LEDGER RECORD PER ASSIGNMENT"]
    direction TB
    S[("state")]
    F[("fence_token")]
    L[("lease_expiry_at")]
    R[("assignment_lifecycle_revision")]
    E[("control_epoch")]
  end
  CL --> F
  CL --> L
  CL --> R
  CL --> E
  RP -->|"checked against fence,<br/>lease, epoch"| S
  RC -->|"expired"| S
  HO -->|"superseded, cancelled"| S

A claim writes the four checking fields at once, and a report can only move the state after passing them. The controller and a handover move the state without a fence, which is why a node can lose an assignment it never reported on.

What a claim writes

Claiming composes the ledger fields that every later write is checked against:

workspace_stream_revision     the workspace's stream position
assignment_lifecycle_revision advanced by one on each claim
fence_token                   a fresh token, minted per claim
lease_expiry_at               now plus the lease TTL
control_epoch                 the control-plane epoch in force

The fence token is new on every claim. A node that held the previous claim holds a token that no longer matches, so a handover is safe without coordinating with it.

Leases are short and renewed

The lease runs for 30 seconds and is renewed on a 10 second cadence, with a floor of 5 seconds on any configured TTL. The gap between the two is the margin for a slow renewal, and a node that stops renewing loses the assignment when the lease lapses rather than when anyone notices.

Every report write passes the fence

A report is checked before it mutates anything:

Refusal Condition
ASSIGNMENT_LEDGER_FENCE_TOKEN_REQUIRED The report carried no fence token
ASSIGNMENT_LEDGER_FENCE_TOKEN_MISMATCH The token is not the assignment's active write fence
ASSIGNMENT_LEDGER_LEASE_EXPIRED The lease has lapsed and no grace applies
ASSIGNMENT_LEDGER_STALE_EPOCH The report was produced under a superseded control epoch
ASSIGNMENT_LEDGER_RESYNC_REQUIRED The reporter's position cannot be reconciled and it must resync

Fence checking is what keeps two nodes from both writing to one assignment. A displaced owner's report is refused on its token rather than accepted and merged.

Completion has a grace window

A terminal report is accepted for 30 seconds after the lease expires, and only for the completion stage. Work that finished just as its lease lapsed is recorded rather than lost, while progress reports from an expired lease are still refused.

The asymmetry is deliberate in effect: a late completion is information the control plane wants, and a late progress report is a node acting without a lease.

See Assignment claim protocol for how a claim is made, and Recovery contracts for what a resync returns.