Skip to content

leaseTransition

leaseTransition(state, event): LeaseTransition

Defined in: packages/core/src/state-machine/index.ts:417

The single-writer lease protocol.

Invariants (checked exhaustively in machines.test.ts, by the reference model in invariants.property.test.ts and by TLC in specs/SessionStore.tla):

  1. A live lease (until > now) has exactly one owner.
  2. acquire by a different owner never succeeds while another live lease exists.
  3. renew never changes the owner and never resurrects an expired lease.
  4. Only the owner can release.
  5. TTL is measured from the caller’s now; an expired lease is free.

The legal source states come from leaseMachine; the guards and next values are the pure may* and heldAfter* functions above, shared with the model tests and the reference property model.

{ _tag: "free"; } | { _tag: "held"; owner: string; until: number; }

{ _tag: "acquire"; now: number; owner: string; ttlMs: number; } | { _tag: "renew"; now: number; owner: string; ttlMs: number; } | { _tag: "release"; owner: string; } | { _tag: "expire"; now: number; }

LeaseTransition