---
title: "TLA+ specification of shard ownership"
url: "https://nsta1.github.io/Orleans.Lattice/spec/shard-ownership/README.html"
source: "https://github.com/NSTA1/Orleans.Lattice/blob/release/10.5/spec/shard-ownership/README.md"
documents: "Orleans.Lattice 10.5.0 (release line 10.5)"
built: "2026-12-05"
all-pages: "https://nsta1.github.io/Orleans.Lattice/llms.txt"
---
# TLA+ specification of shard ownership

Part of [TLA+ specifications](../README.md).

This directory holds the formal coverage of key ownership in Orleans.Lattice
across an adaptive shard split, an online shard fold, an online reshard that
grows or shrinks, and an online resize with its fence, alias flip, undo and
purge. Routing caches can be stale, an atomic-write
saga is bound to one physical copy, ordinary writes and reads run alongside,
and the transaction registry retires what it knows. It is the deliverable of
#4434 under epic #4430.

It is one area indexed in [`spec/README.md`](../README.md), which describes the
layout every module follows, how to run TLC and why TLC runs in CI. This README
covers only what is particular to shard ownership. The area is specified by
five modules. Its core is **two modules**, and the seam between them is part of
what this README documents. A third, `ShardOwnershipCrdt`, checks the same
ownership moves for a CRDT-mode key, whose copies must be joined rather than
overwritten (see
[`RefinementCrdt.md`](RefinementCrdt.md)). A fourth, `ShardOwnershipCutover`,
checks a saga bound to the previous copy across a local shadow-cutover restore
and its revert, the alias move the other modules do not make (see
[`RefinementCutover.md`](RefinementCutover.md)). A fifth, `ShardOwnershipFold`,
checks a slot that a shard fold returns to the shard an earlier split took it
from, and that the fold of an aliased tree commits onto the logical tree's row
(see [`RefinementFold.md`](RefinementFold.md)).

## Files

| File | What it is |
|------|-----------|
| [`ShardOwnership.tla`](https://github.com/NSTA1/Orleans.Lattice/blob/release/10.5/spec/shard-ownership/ShardOwnership.tla) | Ownership: who serves a key across split, fold, reshard, resize and undo, with stale routers and the saga's binding and re-binding. |
| [`ShardOwnership.cfg`](https://github.com/NSTA1/Orleans.Lattice/blob/release/10.5/spec/shard-ownership/ShardOwnership.cfg) | Its TLC model: the bounded instance and the invariants and properties it checks. |
| [`ShardOwnership.manifest.json`](https://github.com/NSTA1/Orleans.Lattice/blob/release/10.5/spec/shard-ownership/ShardOwnership.manifest.json) | Its manifest (see [Counts](#counts)). |
| [`mutations/`](mutations/README.md) | Its mutation catalogue. See [`mutations/README.md`](mutations/README.md), which covers both catalogues. |
| [`Refinement.md`](Refinement.md) | Its refinement note. |
| [`ShardOwnershipRetention.tla`](https://github.com/NSTA1/Orleans.Lattice/blob/release/10.5/spec/shard-ownership/ShardOwnershipRetention.tla) | Retention: what the registry's mask and retirement, a late forwarded prepare and a leaf reactivation do to a saga bound across a split and a resize. |
| [`ShardOwnershipRetention.cfg`](https://github.com/NSTA1/Orleans.Lattice/blob/release/10.5/spec/shard-ownership/ShardOwnershipRetention.cfg) | Its TLC model. |
| [`ShardOwnershipRetention.manifest.json`](https://github.com/NSTA1/Orleans.Lattice/blob/release/10.5/spec/shard-ownership/ShardOwnershipRetention.manifest.json) | Its manifest. |
| [`mutations-retention/`](mutations-retention/README.md) | Its mutation catalogue. |
| [`RefinementRetention.md`](RefinementRetention.md) | Its refinement note. |
| [`ShardOwnershipCrdt.tla`](https://github.com/NSTA1/Orleans.Lattice/blob/release/10.5/spec/shard-ownership/ShardOwnershipCrdt.tla) | CRDT ownership: that a leaf split, a shard split and an online resize join a CRDT-mode key's copies, so no acknowledged contribution is lost. |
| [`ShardOwnershipCrdt.cfg`](https://github.com/NSTA1/Orleans.Lattice/blob/release/10.5/spec/shard-ownership/ShardOwnershipCrdt.cfg) | Its TLC model. |
| [`ShardOwnershipCrdt.manifest.json`](https://github.com/NSTA1/Orleans.Lattice/blob/release/10.5/spec/shard-ownership/ShardOwnershipCrdt.manifest.json) | Its manifest. |
| [`mutations-crdt/`](mutations-crdt/README.md) | Its mutation catalogue. |
| [`RefinementCrdt.md`](RefinementCrdt.md) | Its refinement note. |
| [`ShardOwnershipCutover.tla`](https://github.com/NSTA1/Orleans.Lattice/blob/release/10.5/spec/shard-ownership/ShardOwnershipCutover.tla) | Cutover: an atomic-write saga bound to the previous copy across a shadow-cutover restore and its revert, with stale routers, a straggling prepare, and the retained redirects. |
| [`ShardOwnershipCutover.cfg`](https://github.com/NSTA1/Orleans.Lattice/blob/release/10.5/spec/shard-ownership/ShardOwnershipCutover.cfg) | Its TLC model. |
| [`ShardOwnershipCutover.manifest.json`](https://github.com/NSTA1/Orleans.Lattice/blob/release/10.5/spec/shard-ownership/ShardOwnershipCutover.manifest.json) | Its manifest. |
| [`mutations-cutover/`](mutations-cutover/README.md) | Its mutation catalogue. |
| [`RefinementCutover.md`](RefinementCutover.md) | Its refinement note. |
| [`ShardOwnershipFold.tla`](https://github.com/NSTA1/Orleans.Lattice/blob/release/10.5/spec/shard-ownership/ShardOwnershipFold.tla) | Fold: a slot a split moved away and a shard fold moves back, onto a survivor that still holds the slot sealed and still holds its old rows, with the fold's sweep, reclaim, cancel and retirement, the registry row its coordinator is keyed by, a saga, a later write or delete, and tombstone compaction. |
| [`ShardOwnershipFold.cfg`](https://github.com/NSTA1/Orleans.Lattice/blob/release/10.5/spec/shard-ownership/ShardOwnershipFold.cfg) | Its TLC model. |
| [`ShardOwnershipFold.manifest.json`](https://github.com/NSTA1/Orleans.Lattice/blob/release/10.5/spec/shard-ownership/ShardOwnershipFold.manifest.json) | Its manifest. |
| [`mutations-fold/`](mutations-fold/README.md) | Its mutation catalogue. |
| [`RefinementFold.md`](RefinementFold.md) | Its refinement note. |
| `README.md` | This file. |

## Two modules and the seam between them

### Why two

The area was first written as one module. Once the registry's retention, the
saga's abort path and leaf reactivation were added to it, it reached 693,228
distinct states, and checking its liveness properties took over eight minutes on
two TLC workers. `TlcModelCheckTests` then gave each TLC run five minutes (a
per-run limit since removed; see [CI budget](../README.md#ci-budget)) and runs a
control arm per mutation, so one module of that size would have cost CI the
better part of an hour and still breached that limit. It was split along
the line where its concerns stop interacting, not shrunk.

### What each owns

| | `ShardOwnership` | `ShardOwnershipRetention` |
|---|---|---|
| Adaptive split (sweep, freeze, commit) | yes | yes |
| Online shard fold (through the split's sweep, freeze and commit) | yes | no |
| Online reshard | yes | no |
| Resize: snapshot, fence, flip, retire, purge | yes | yes |
| A refused flip | yes | no |
| Undo before the flip | yes | no |
| Undo after the flip | yes | yes |
| Stale routers that write | yes | no (writes use the current pair) |
| Stale routers that read | yes | yes |
| Saga bind, prepare, decide, abort, broadcast, complete | yes | yes |
| Saga re-binds | yes | no (a saga that cannot commit aborts, fairly) |
| Registry declines to report the decision (Indeterminate) | no | yes |
| Registry retires the saga's row | no | yes |
| A delayed shadow-forwarded prepare | no | yes |
| A leaf reactivation (terminal memory and shadow markers lost) | no | yes |
| Write stamps that disagree with real time, and migrated rows (#4522, #4564) | yes | no (values are stamps in commit order) |
| The applied-terminal witness, carried by a leaf split of the split destination (#4545) | no | yes |
| The saga's participant row and the forgotten-saga refusal (#4632) | no | yes |
| `UniqueOwner`, `SagaBatchOnOneCopy`, `ReshardCompletes`, `RoutingConverges` | yes | no |
| `NoKeyLost`, `NoResurrection`, `AtomicOnOwner`, `OwnerMonotonic` | yes | yes |
| `SplitCompletes`, `ResizeCompletes`, `SagaCompletes` | yes | yes |
| `NoStrandedBucket`, `ReadableOnceComplete`, `NoLiveBucketAfterForget` | no | yes |

The retention module keeps the ownership machinery its concerns act through, a
saga bound across one split and one resize with its undo, so every
counterexample found when they were one module is still reachable in a single
module. The mutation catalogues show it: each mutation was re-proved red, with
a clean control, in the module it now lives in.

### What composing them costs, and what it shows

The behaviours the split puts in neither module on its own are a retention
event **together with** something only `ShardOwnership` has: a stale router
writing, a saga re-binding, a reshard-driven split, a refused flip, an undo
before the flip, a write stamp that disagrees with real time, or a migrated row.
They are checked by composing the modules, rather than argued.
The review (#4435, finding F7) first built the compositions from
`ShardOwnershipRetention.tla`. Its confirmation pass re-measured them on the
current modules, after #4574, #4609 and #4670 had changed both, with tla2tools
v1.7.4 on two TLC workers, liveness checked at the end:

| Composition | Added to the retention module | Result |
|---|---|---|
| (a) | stale writers: `SagaPrepare(k, p)` and `LaterWrite(p)` over every published pair | clean, 142,980 distinct states, depth 24, 1 min 55 s: **identical to the module alone**, so stale writers add no reachable behaviour in this instance |
| (b) | (a), plus `SagaRebindOnRefusal` and `SagaRebindBeforeDecision` (weakly fair) and `UndoBeforeFlip` | clean, 205,504 distinct states, depth 25, 3 min 59 s |
| (c) | (b), plus the reshard (`rs`; `ReshardStart`, `ReshardFinish` fair, the split's `rs = "migrating"` arm, weakly fair, and the resize's reshard interlock) and `ResizeFlipRefused` (`refusals`) | clean, 680,740 distinct states, depth 29, 12 min 53 s |
| (d) | (c), plus `ShardOwnership`'s write stamps and migrated-row flag: its versions, `Rank`, `Stamp` and `LWW` (every row merge last-writer-wins on stamps, every read judged by rank), `BVal`, and `KnowsP` and `WVal` stamping the later write, and `mig` with its updates in the sweep, the final drain, the purge, the terminal and the later write. The leaf read gate consults a shadow marker only for a migrated row and verifies it against the row's stamp, as production does | clean, 813,771 distinct states, depth 29, 19 min 08 s |

(a) and (b) were run under the retention cfg: `TypeOK`, `NoKeyLost`,
`NoResurrection`, `AtomicOnOwner`, `OwnerMonotonic`, `ReadableOnceComplete`,
`NoLiveBucketAfterForget`, `SplitCompletes`, `ResizeCompletes`, `SagaCompletes`
and `NoStrandedBucket`. (c) was also checked against the four properties only
`ShardOwnership` states, all fifteen in one run: `UniqueOwner`,
`SagaBatchOnOneCopy` (read over buckets, since a retention `"mark"` is a shadow
marker, not a bucket), `ReshardCompletes` and `RoutingConverges`. (d) was checked
under (c)'s configuration, all fifteen properties in one run.

(c) adds every **action** `ShardOwnership` has that the retention module lacks.
(d) adds the rest of its state: the write stamps that disagree with real time
and the migrated-row flag (#4522, #4564), which the retention module lacks
because its values are stamps in commit order. So a stamp or import defect
**together with** a retention event is checked too. (d) ports
`ShardOwnership`'s definitions verbatim rather than restating them. It changes
one retention definition to match production: `LeafGated`, the read gate on
the split destination, requires a migrated row (production consults a shadow
marker only for an `IsMigrated` row: `BPlusLeafGrain`'s
`lww.IsMigrated && TryGetShadowedSagas`). It also compares the row's stamp, not
its rank, with the saga's prepare stamp
(`ShadowedMigrationReadGuard.RowIncorporatesMarkedPrepare`). The retention
module alone gates every row there. That hides more reads, and a hidden read
excuses the safety properties. (d) shows this loses nothing in this instance,
in both directions: every safety property holds under production's narrower
gate, and a probe that restores the wider gate in (d) still satisfies
`ReadableOnceComplete` (814,034 distinct states).

(d) is not vacuous. Fourteen mutations were applied to it, each checked
against its own target alone, and thirteen went red:

- The seven stamp and import defects: `NoKeyLostLaterWriteBelowP`,
  `NoKeyLostMigrationImportDropped`, `NoKeyLostFreshStampDrainOverMigratedRow`,
  `NoKeyLostFreshStampBackstop`, `NoKeyLostRetainedFreshStampBackstop`,
  `NoKeyLostResizeMirrorUnmarkedPrepare` and `NoKeyLostSnapshotResolvesAtFreshStamp`.
- The five retention mutations on the marker gate: the four
  `ReadableOnceComplete` ones and `OwnerMonotonicSweepIndeterminateLeavesMarker`.
  So requiring a migrated row did not disarm the gate.
- One defect only the composition can state: a sweep that resolves an
  Indeterminate answer by installing the backstop at a fresh dominating stamp.
  Under the registry's mask, it overwrites a later write mirrored to the
  destination.

The fourteenth is the wider-gate probe above, which is meant to stay clean.

So in this instance nothing else is lost by the split. The composition is not a
CI gate because (d) takes over nineteen minutes on two workers, and every
mutation would pay it twice. It is the measured cost of
composing the two modules, and the reason they are separate; anyone changing
either module's shared machinery should re-run (d). The compositions are
mechanical, and each is built from the previous one:

- **(a)**: in `Next`, replace `\E k \in Keys : SagaPrepare(k, CurrentPair)` with
  `\E k \in Keys, p \in published : SagaPrepare(k, p)`, and `LaterWrite(CurrentPair)`
  with `\E p \in published : LaterWrite(p)`.
- **(b)**: add `SagaRebindOnRefusal`, `SagaRebindBeforeDecision` and
  `UndoBeforeFlip` from `ShardOwnership.tla`, each with the retention variables
  it leaves alone in its `UNCHANGED` tuple, to `Next`, and add `WF_svars` of
  each re-bind to `Spec`.
- **(c)**: add variables `rs` (`"idle"`) and `refusals` (`1`) to `vars`, `svars`,
  `Init`, `TypeOK` and every existing `UNCHANGED` tuple. Add `rs = "migrating" \/`
  to `SplitBegin`'s resize guard and `rs # "migrating"` to `ResizeBegin`, and add
  `ReshardStart`, `ReshardFinish` and `ResizeFlipRefused` from
  `ShardOwnership.tla` with `WF_svars(rs = "migrating" /\ SplitBegin)` and
  `WF_svars(ReshardFinish)`. Then add the four `ShardOwnership`-only
  properties to the module and the cfg.
- **(d)**: from `ShardOwnership.tla`, copy the version definitions (`Vals`
  with `LaterLowV`, `SagaUV` and `FreshV`, `Rank`, `Stamp` and `LWW`) over the
  retention module's, and `BVal`, `KnowsP` and `WVal` ahead of the read gate.
  Add variable `mig` (all `FALSE`) to `vars`, `svars`, `Init`, `TypeOK` and
  every `UNCHANGED` tuple. Then give the sweep's committed arm, the final drain,
  `ResizePurge`, `SagaTerminal` and `LaterWrite` `ShardOwnership`'s `mig'`
  update, taking `mig` out of their `UNCHANGED` tuples. Replace `Max` with `LWW`
  in every row merge (`ackOn` and `vis` keep `Max`: they hold ranks). Take
  `TermRow`'s arms, the final drain's `LET` and `LaterWrite`'s `WVal` stamp from
  `ShardOwnership.tla`, and wrap `ReadVia` and `OwnerValue` in `Rank`. In
  `LeafGated`, replace `row[c][s][k] < SagaV` with
  `mig[c][s][k] /\ Stamp(row[c][s][k]) < Stamp(SagaV)`.

### Budget

Each module's full configuration, liveness included, runs well within the TLC
budget; the figures are under
[Last checked](#last-checked). Three choices in the retention module are
budget-driven and argued where they are made: `Reactivate` is offered on the
split destination only, `NoStrandedBucket` is one leads-to rather than one per
bucket, and `RegistryMask` is enabled only once there is a decision to mask.
Each loses no behaviour the instance can distinguish.

## What is modelled

- **The split** (`SplitBegin`, `SplitSweep`, `SplitFreeze`, `SplitCommit`,
  `SplitAbandon`): an adaptive split of `k2`'s slot from `s1` to `s2` on the
  copy the tree resolves to, with its shadow-write window, retroactive sweep,
  Reject freeze and final drain before the map moves. It may run on the resized
  copy once the resize completed, while the old copy still mirrors into it: the
  mirror chases a refusal to the slot's current owner, a mirrored terminal
  reaches the split closure, and an undo abandons the split (#4478).
- **The fold** (`FoldBegin`; ownership module only): an online shard fold of
  `k2`'s slot from donor `s1` onto survivor `s2`, from over-split healing or a
  shrinking reshard. It opens the donor's window through the split's primitive,
  under the resize's migration hold, and then takes the split's own sweep,
  freeze and commit (#5125).
- **The reshard** (`ReshardStart`, `ReshardFinish`; ownership module only): a
  reshard that drives the split or the fold, interlocked with resize in both
  directions.
- **The resize** (`ResizeBegin`, `SnapCopy`, `ResizeFence`, `ResizeFlip`,
  `ResizeFlipRefused`, `ResizeRetire`, `ResizePurge`): an online resize from the
  old copy `T` to the resized copy `R`, index-for-index, fenced before a
  single-write flip, soft-deleted, then purged.
- **The undo** (`UndoBeforeFlip`, `UndoArm`, `UndoSwap`, `UndoClear`): before
  the flip it discards `R`; after it, it arms `R` to redirect, swaps back, and
  lifts `T`'s fence, in that order (#4453).
- **Routing** (`published`): any pair the registry ever published may be held by
  some router at any time.
- **The saga** (`SagaStart` through `SagaComplete`, `SagaAbort`): an atomic
  write of `k1` and `k2` bound to one physical copy, with its prepares, its
  re-binds, its decision and its terminal broadcast.
- **Retention** (retention module only): `RegistryMask`, `RegistryForget`,
  `DeliverLate` and `Reactivate`, and a leaf split of the split destination's
  leaf (`LeafSplit`) that moves a shadow marker to a fresh sibling (#4545).
- **A later write** (`LaterWrite`) of `k2`, which gives `NoResurrection` a newer
  value to protect.
- **Stamps and migrated rows** (ownership module only): a row holds a version of
  a write, whose real-time rank and HLC stamp are kept apart, and a flag for a
  row last written by a cross-shard migration. The base stamps every version in
  real-time order; mutations use the separation to reproduce the stamp and
  import defects (#4522, #4564).

- **CRDT keys** (CRDT module only): a staged CRDT mutation in a saga, a
  non-atomic CRDT write, a leaf split that strands the saga's bucket, and one
  shard split or online resize whose forward, drains and terminal must join the
  key's copies.
- **A shadow-cutover restore and its revert** (cutover module only): the swap,
  the retained redirect, the swap back and the redirect fix-up, as the
  environment of a saga bound to the previous copy that re-binds, records the
  copy it leaves, and discards its prepares there before it decides (#4689). A
  routed prepare can straggle and land late.
- **A fold back** (fold module only): a shard fold (`FoldBegin`, `MigSweep`,
  `MigFreeze`, `MigCommit`, `MigFinish`, `FoldCancel`) of the split's
  destination back onto its source, whose survivor still holds the slot sealed
  and still holds the rows it had when the split moved the slot away. The
  fold's drain resolves those rows by last-writer-wins, and a row whose key the
  donor no longer holds is tombstoned before the survivor reclaims the slot
  (#5130); tombstone compaction (`Compact`) and a later delete give it a key to
  lose.

Each module modelled the **intended** design while production had an open
defect, with a mutation that reproduced production. Every such defect is now
fixed, and each mutation stays as a regression check; the refinement notes list
them with their issues.

## Properties checked

| Property | Kind | Module | Meaning |
|----------|------|--------|---------|
| `TypeOK` | invariant | all | State stays well-typed. |
| `UniqueOwner` | invariant | ownership, fold | Every routing pair any router may hold is refused for a key or reaches that key's one owner. |
| `NoKeyLost` | invariant | both, fold | The owner holds every value acknowledged to a writer (or, under retention, the gate declines to answer). |
| `NoResurrection` | invariant | both, fold | No read through any pair returns a value older than one already acknowledged. |
| `SagaBatchOnOneCopy` | invariant | ownership | A committed saga holds buckets only on its bound copy and the copy that copy mirrors into. |
| `AtomicOnOwner` | invariant | both, fold | Until the later write, a fresh reader sees the batch on both keys or on neither. |
| `OwnerMonotonic` | invariant over a ghost history | both, fold | A fresh reader's value never moves backwards, except across the undo's swap, which discards the resized copy's writes by contract. |
| `SplitCompletes` | liveness | both | A split that opened its window finishes. |
| `ReshardCompletes` | liveness | ownership | A reshard that started reaches its target. |
| `ResizeCompletes` | liveness | both | A resize that started is purged or undone. |
| `SagaCompletes` | liveness | both, fold | A saga that started completes. |
| `RoutingConverges` | liveness | ownership, fold | Eventually the registry's own pair serves every key. |
| `ReadableOnceComplete` | invariant | retention | Once a saga has completed, and while its row is neither retired nor masked, no read at the owner is gated (#4545). |
| `NoLiveBucketAfterForget` | invariant | retention | No copy that can still become the tree keeps a bucket of a saga whose registry row is retired (#4619). |
| `NoLostContribution` | invariant | crdt | The owner's copy of a CRDT key holds every contribution acknowledged to a writer. |
| `NoStrandedBucket` | liveness | retention | A decided saga's bucket on a copy that can still become the tree is eventually consumed, unless the registry retired the row first. |
| `AtomicAcrossCutover` | invariant | cutover | No reader, fresh or stale, is served a copy holding a saga's batch on one key and not the other, across a shadow-cutover restore and its revert (#4689). |
| `CommittedBatchOnBoundCopy` | invariant | cutover | Once committed, a saga holds prepared buckets only on its bound copy: every copy it re-bound away from was discarded. |
| `SagaSettles` | liveness | cutover | A saga settles however a restore and its revert interleave with it. |
| `MigrationCompletes` | liveness | fold | A split or a fold that opened its window finishes. |

Every liveness property can fail on a protocol defect under the fairness the
spec asserts, shown by a mutation that leaves that fairness intact. Many of
those mutations are a step that records nothing (`SplitCompletesSweepStalls`),
but some are real protocol defects: `SplitCompletesUndoWithoutAbandon` is a
split of the resized copy an undo retargets, never abandoned, with every
fairness condition kept; `SagaCompletesDiscardedCopyRefusesTerminal`,
`SagaCompletesPurgedCopyRefusesTerminal` and
`NoStrandedBucketTerminalNotMirrored` are a broadcast production did not
finish before its fix.

### Classification

Per #2321's taxonomy, every property above is **reachable**: each has a mutation
that perturbs an action the specification already has and makes it fire, and
none needs an action added. None is unreached, bounded-out or inexpressible in
that sense.

The gaps the refinement notes list are classified there. A second saga
contending for a key, a second split, and a split of the resized copy while the
resize is still in flight are **bounded out** by the instance. The abandon of a
split an alias move retargets (`AbandonRetargetedSplitAsync`) is modelled for
the move an undo of a resize makes (`SplitAbandon`, #4478). A shadow-cutover
restore and its revert are modelled against a bound saga by the cutover module;
an explicit `SetTreeAliasAsync` and schema remediation, which move the alias the
same way with no shadow to revert to, are not modelled.

## The bounded instance

Both configurations fix two physical copies (`T`, the original; `R`, the resize
destination), two shards per copy, and two keys: `k1`, whose slot never moves,
and `k2`, whose slot an adaptive split moves from `s1` to `s2`. One split, one
resize, one saga writing `k1` and `k2`, and one later write of `k2`; the
ownership module adds one reshard and one refused flip, the retention module one
delayed forward, one mask toggle at a time, one retirement and one reactivation.
The fold module fixes one copy, the same two shards and keys, one split, one
fold back with one cancel, one saga, one later write or delete of `k2`, and
tombstone compaction; `UniqueOwner`, `NoKeyLost`, `NoResurrection`,
`AtomicOnOwner`, `OwnerMonotonic`, `SagaCompletes` and `RoutingConverges` are
checked there across the round trip.

## Defects this area found

Each was found by TLC against the intended design, filed, and kept as a
standing mutation. The refinement notes record which are fixed.

| Issue | Defect | Mutation |
|-------|--------|----------|
| #4452 | A split in flight across a resize: the resize neither captures nor fences the split target, and an undo restores a pre-split map (fixed, #4466; relaxed for a split by #4478, which made the mirror and the terminal follow it) | `UniqueOwnerSplitDuringResize`, `NoKeyLostResizeDuringSplit`, `NoKeyLostRetainedSplitDuringResize`, `NoKeyLostSplitInSoftDeleteWindow` |
| #4453 | The undo cleared the old copy's fence before the swap and armed the resized copy after it (fixed, #4457) | `UniqueOwnerUndoClearsBeforeSwap` |
| #4454 | The mid-dispatch re-bind ignores the bound copy's mirror (fixed, #4521) | `SagaBatchOnOneCopyRebindIgnoresMirror` |
| #4455 | The online snapshot does not copy prepared buckets (fixed, #4506) | `OwnerMonotonicSnapshotSkipsBuckets`, `OwnerMonotonicRetainedSnapshotDropsBuckets` |
| #4473 | The split's sweep treats Indeterminate as InFlight (fixed, #4561) | `OwnerMonotonicSweepIndeterminateLeavesMarker` |
| #5125 | A shard fold opens the split's window without the split's retroactive sweep, so a batch prepared on the donor before the fold reads torn once it commits (found by `ReshardTopologyTests` in CI, outside this area, which did not then model a fold; fixed, #5126) | `AtomicOnOwnerFoldSkipsSweep`, `AtomicOnOwnerFoldBeginSkipsSweep` |
| #4474 | A saga bound to the copy an undo discarded never completes: the discarded copy refuses its terminals and the broadcast does not follow the refusal. Following it to the old copy, the naive fix, lands part of the batch there (fixed, #4516) | `SagaCompletesDiscardedCopyRefusesTerminal`, `AtomicOnOwnerDiscardedCopyTerminalRedirects` |
| #4475 | A saga bound to a purged old copy never completes (fixed, #4531 and #4581) | `SagaCompletesPurgedCopyRefusesTerminal` |
| #4522 | A saga value installed at a stamp other than its own prepare stamp overwrites a later acknowledged write: the backstop's and the drain's fresh stamps, the resize mirror's re-minted prepare, and the snapshot's fresh-stamp resolution (found while confirming #4475's design; fixed, #4566, #4610 and #4629) | `NoKeyLostFreshStampBackstop`, `NoKeyLostRetainedFreshStampBackstop`, `NoKeyLostFreshStampDrainOverMigratedRow`, `NoKeyLostResizeMirrorUnmarkedPrepare`, `NoKeyLostSnapshotResolvesAtFreshStamp` |
| #4564 | A cross-shard migration import is dropped over a non-migrated destination row, so a later write the split carries is lost (found while confirming #4522's design; fixed, #4600) | `NoKeyLostMigrationImportDropped` |
| #4545 | A shadow marker installed after its terminal is copied by a leaf split to a sibling that never sees the terminal, gating the key after the saga completed (found by 10238ade's CI triage; fixed, #4608 and #4644) | `ReadableOnceCompleteDeadMarkerTransferred`, `ReadableOnceCompleteMarkerWithoutSelfCheck`, `ReadableOnceCompleteWitnessNotCarried`, `ReadableOnceCompleteWitnessNotDurable` |
| #4503 | A router that cached the old copy reads empty and loses writes once that copy is purged (found by review #4435, which showed the purge's timing assumption false; fixed, #4528) | `NoResurrectionPurgedCopyServesEmpty`, `NoKeyLostPurgedCopyAcceptsWrites`, `NoResurrectionRetainedPurgedCopyServesEmpty` |
| #4611 | A CRDT prepare applied by the terminal's backstop is installed last-writer-wins, losing contributions the row gained after staging (found while extending this area to CRDT keys; fixed, #4617) | `NoLostContributionBackstopInstallsLastWriterWins` |
| #4613 | A split's import of a CRDT row is dropped over the destination's own fold, and CRDT writes were not forwarded during the split (fixed, #4626) | `NoLostContributionSplitImportDropsOverOwnRow` |
| #4618 | A resize neither mirrors a CRDT write nor joins the rows it merges into the resized copy (fixed, #4665) | `NoLostContributionResizeWriteNotMirrored`, `NoLostContributionResizeDrainLastWriterWins` |
| #4689 | A saga re-bound across a shadow-cutover restore leaves its prepares on the previous copy, which a stale reader before the redirect, or any reader after a revert, is served torn (found by the cutover module; fixed) | `AtomicAcrossCutoverDecideSkipsDiscard`, `AtomicAcrossCutoverRebindForgetsLeftCopy`, `CommittedBatchOnBoundCopyRebindBeforeDecisionForgets` |
| #4619 | A late forward of a saga whose registry row was retired is bucketed on a leaf that lost its memory of the terminal, stranded for good (found while answering #4619's question; fixed, #4638) | `NoLiveBucketAfterForgetLateForwardBucketed`, `NoLiveBucketAfterForgetForwardRecreatesRow`, `AtomicOnOwnerParticipantRowBestEffort` |
| #5130 | A fold back onto the shard a split took the slot from dropped its drain over the rows the survivor kept behind its seal, reverting every write and delete made since the split, and revived a key whose delete compaction had reaped (found while extending this area to the fold; fixed, #5131) | `NoKeyLostFoldImportDroppedOverSealedRow`, `NoKeyLostFoldSkipsReapReconciliation` |
| #6083 | Automatic healing keyed its folds by the physical copy an aliased tree resolves to, so each fold committed onto the copy's own registry row and the logical map kept routing the folded slots to the retired donor (found in a deployment after a shadow-cutover restore, outside this area, which did not then model which row a fold commits onto; fixed) | `UniqueOwnerFoldKeyedByAliasTarget` |
| #6089 | The #6083 fix committed every fold onto the logical row only, so a router addressed by the alias target's own id - a view maintainer bound to the physical copy - kept routing the folded slots to the retired donor (found in the same deployment; fixed) | `RoutingConvergesFoldSkipsCopyMirror` |

#4445 (a late forwarded orphan read past the terminal) was fixed elsewhere
(#4461); its mutation is `NoResurrectionLatePrepareActivationMemory`, and the
module showed the stale read needs no reactivation at all.

## How to run TLC

From this directory, with the toolchain described in
[how to run TLC](../README.md#how-to-run-tlc):

```bash
java -cp /path/to/tla2tools.jar tlc2.TLC -workers 2 -lncheck final -config ShardOwnership.cfg ShardOwnership.tla
java -cp /path/to/tla2tools.jar tlc2.TLC -workers 2 -lncheck final -config ShardOwnershipRetention.cfg ShardOwnershipRetention.tla
java -cp /path/to/tla2tools.jar tlc2.TLC -workers 2 -config ShardOwnershipCrdt.cfg ShardOwnershipCrdt.tla
java -cp /path/to/tla2tools.jar tlc2.TLC -workers 2 -lncheck final -config ShardOwnershipCutover.cfg ShardOwnershipCutover.tla
java -cp /path/to/tla2tools.jar tlc2.TLC -workers 2 -lncheck final -config ShardOwnershipFold.cfg ShardOwnershipFold.tla
```

`-lncheck final` defers the liveness check to the end of the search, which is
how the CI gate runs it. A clean run ends with
`Model checking completed. No error has been found.` and reports the
distinct-state count in [Counts](#counts).

## Last checked

The modules were checked with tla2tools v1.7.4 on a Temurin 17 JDK, liveness
checked at the end, deadlock checking on, on a 16-core workstation, with two
TLC workers for `ShardOwnership` and four for the other four (wall clock
includes JVM start-up):

```
ShardOwnership:          100,666 distinct states, depth 26, clean, 1 min 32 s
ShardOwnershipRetention: 142,980 distinct states, depth 24, clean, 1 min 18 s
ShardOwnershipCrdt:        1,573 distinct states, depth 11, clean, 2 s
ShardOwnershipCutover:     2,088 distinct states, depth 15, clean, 1 s
ShardOwnershipFold:        4,128 distinct states, depth 23, clean, 3 s
```

The current specifications are model-checked in CI by
`TlcModelCheckTests.The_base_specification_holds`.

## Counts

The modules' current totals. `SpecModuleDiscoveryTests` checks this table
against the manifests, and the other Formal gates check the manifests against
the specifications, the cfgs, the mutation catalogues, the refinement notes and
TLC's own state counts.

| Module | Invariants | Properties | Actions | Mutations | Behaviour rows | Distinct states |
|--------|------------|------------|---------|-----------|----------------|-----------------|
| `ShardOwnership` | 7 | 5 | 29 | 45 | 39 | 100,666 |
| `ShardOwnershipRetention` | 7 | 4 | 27 | 36 | 36 | 142,980 |
| `ShardOwnershipCrdt` | 2 | 0 | 10 | 10 | 10 | 1,573 |
| `ShardOwnershipCutover` | 3 | 1 | 14 | 15 | 16 | 2,088 |
| `ShardOwnershipFold` | 6 | 3 | 16 | 20 | 23 | 4,128 |
