---
title: "Hand-off fences - Write-Ahead Log"
url: "https://nsta1.github.io/Orleans.Lattice/docs/lattice/wal/hand-off-fences.html"
source: "https://github.com/NSTA1/Orleans.Lattice/blob/release/10.5/docs/lattice/wal.md?plain=1#L1839-L2219"
agent_spec: "https://nsta1.github.io/Orleans.Lattice/docs/agents/concepts.yaml"
package: "Orleans.Lattice"
version: "10.5.0"
documents: "Orleans.Lattice 10.5.0 (release line 10.5)"
built: "2026-12-05"
all-pages: "https://nsta1.github.io/Orleans.Lattice/llms.txt"
bundle: "https://nsta1.github.io/Orleans.Lattice/docs/lattice/llms-full.txt"
---
# Hand-off fences

Part of [Write-Ahead Log](../wal.md).

The epoch fence above stops a stale duplicate of a leaf. The **hand-off fences**
stop a different author: one that appends a record a leaf will own, while handing
keys to it ([epic #5605](https://github.com/NSTA1/Orleans.Lattice/issues/5605), the
design note's section 2). A leaf reads the markers before it advances its checkpoint
over its own writes ([Live checkpoint advance](live-checkpoint-advance.md)); a hand-off
in flight holds that advance, and the leaf's checkpoint advances by replay meanwhile.

Every hand-off follows one protocol:

1. **Open.** The initiator records an open marker on the owner before it admits a
   write the owner will own.
2. **Close by fence.** Once the initiator has stopped admitting writes for the
   range, it re-claims its own epoch (a leaf initiator) or its routing generation (a
   shard-level initiator) at every WAL partition, and records the claim heads in the
   owner's marker. Every write admitted before the close was either allocated below
   those heads, or carries the old epoch or generation and is rejected when it
   arrives. A wait cannot replace this: a call can time out while its append is
   still delivered later.
3. **Re-arm by replay.** An owner holds while any marker overlapping it is open, and
   may re-arm only after replaying to a close's heads.

A marker is a row of its own under a reserved grain type: `_lattice_leaf-handoff`
for a leaf, `_lattice_shard-handoff` for a shard root. A missing marker, or one whose
state is not yet initialised, never reads as closed: it holds the owner. A marker is
recorded only while the append-fence gate is open, and every resume path of an
in-flight hand-off opens its marker before its next admission, so a hand-off begun
by an older build, or while the gate was closed, opens one when it resumes.

| Hand-off | Initiator | Marker | Fence at close |
|----------|-----------|--------|----------------|
| Leaf split | The donor leaf | The sibling's, opened at its birth | Once the donor's narrowed span is durable, the leaf's epoch row is raised above every epoch issued and the raised epoch is claimed at every partition; in pre-arm mode the donor does this in its own close, which records its deferred bound, and the shard root's link only raises its routing generation |
| Leaf reclaim | The absorbed neighbour | The survivor's, opened before its range widens | The neighbour's entries are retired at every partition, and the allocator heads are read after the retirement |
| Adaptive split, consolidation fold | The donor shard root | The target shard root's, opened when the migration begins | The donor raises its routing generation, after the reject phase and the drain, and re-claims it at every partition |
| Range delete | The tree's range-delete fence | Every shard root's, range-scoped | The fence raises the tree's range-delete generation and re-claims it at every partition |
| Bulk load, bulk append | The shard root | Its own, `bulk:{operationId}`, opened before the first leaf is created: over the whole shard for a load, from the first appended separator for an append | Once the new leaves are routable, the shard root raises its routing generation and re-claims it at every partition |

**Writes are stamped at admission.** A shard root captures its routing generation
in the same step as its phase check and passes it to the leaf through a new,
stamped leaf write method; the leaf appends under its own epoch and that generation.
A write that reaches a leaf through an existing leaf method carries no generation -
an older shard root admitted it - so it is appended **unstamped** and reported,
never under the leaf's epoch alone. A write rejected because a close re-claimed its
generation is retried from the shard root: the phase check runs again, which
re-routes a key whose slot moved to another shard, and the write is re-admitted under
the current generation. If the partition refused the write at a generation above the
one the shard root holds - its marker row was lost or restored from an older copy -
the shard root raises its generation above that refusal before re-admitting, so a
marker behind the WAL's rows never refuses every write until the deadline. Whoever
calls the WAL append stamps with its own epoch, so a
split's transfers and a relocation, which the receiving leaf appends and applies
itself, are that leaf's own appends.

A WAL partition that receives a stamped write under a generation it has not loaded
(a fresh tree, or the partition restarted or moved) claims that generation itself,
exactly as the writer's re-presented claim would, and then checks the write again
from the start; a close that re-claimed a higher generation in between still rejects
it. Claims of one initiator at a partition run one at a time, so a fresh tree's
concurrent first writes create each generation slot once, and a claim of a generation
the partition already holds needs no storage operation (#5831). A new tree's first
touch reads each partition's generation table and floors once, and each shard root's
routing floor and hand-off marker once, so its fence cost grows with shard roots plus
partitions, not their product (#5987).

**A split close does not supersede the donor.** The donor's epoch raise rejects its
own appends stamped before it. Those are **self-fenced**: refused for the caller to
re-admit under the current epoch, where the narrowed span forwards a moved key to
the sibling, without the donor deactivating. The refusal has the same wire shape as
a superseded activation's, which every caller and an older shard root already retry.
The close's epoch raise and a raise after a floor refusal are one write: whichever
starts second joins the first, so the two never conflict on the activation's own row.

The close's heads bound every append the donor makes under its old epoch
([#5664](https://github.com/NSTA1/Orleans.Lattice/issues/5664)):

- **Admission decides the stamp.** A write is admitted against the donor's hand-off
  closes, before its span check. If a close happens before the write reaches the WAL,
  the write is self-fenced and re-admitted, rather than stamped with the raised epoch.
- **Every partition is claimed.** The close claims the raised epoch at every
  partition, including one whose claim a WAL shard restart reset and one the
  activation never wrote, so a duplicate is refused there too. The raise is held in
  the leaf's own entry at each partition, never in the partition's shared retired
  floor, which every other leaf's claims are checked against.
- **No fence, no close.** If the activation's view of the gate is closed after it has
  stamped, the close cannot raise its epoch. The marker stays open until a later
  close can.

**A duplicate of the donor is fenced too**
([#5841](https://github.com/NSTA1/Orleans.Lattice/issues/5841)). Another activation of
the donor that loaded its state before the split still holds the old span. It could
claim, or arm, after the split, then append an epoch-only write of a moved key that
nothing routes to the sibling. Two ordered pairs prevent it:

- **The split writes, then reads.** Only once its narrowed state is durable does the
  split read the leaf's epoch row. If any activation has ever claimed, the split
  raises the row conditionally on what it read and claims the raised epoch at every
  partition. A duplicate that claimed before that read is refused at its next append,
  whether or not the splitting activation itself ever claimed.
- **A claim writes, then reads.** A claim writes the epoch row first, then reads the
  leaf's own state row fresh. If that row's ETag is not the one the activation holds,
  the activation is stale: it claims nowhere, and every append waiting on the claim
  is refused. The read is serialised with the activation's own persists, so its own
  write in flight never reads as another's.

Between them, either the split sees the duplicate's claim, or the duplicate sees the
narrowing. That needs the storage provider to give strong read-after-write across
clients for both rows: a write that has completed is visible to any later read. The
Azure Table and in-memory providers give it; a provider with session or eventual
consistency does not.

In pre-arm mode the live donor drops its epoch at the split's counted close, locally and
with no I/O, just before its own close raises the row (#5837, rule S). If it had
claimed, it adopts the raised epoch and its claims from that fence; otherwise its next
appends go pre-arm, which the routing generation fences, and its next arm claims afresh,
through the same write-then-read claim. A stamped append it had in flight at the dropped
epoch is refused and retried, not treated as a supersession. If the donor re-arms before
the link, a refusal at its new epoch, or a conflict on its next row write, gets one more
such fresh claim per close. Without one, the live donor would deactivate on every split.
The same rule stops a leaf from deactivating itself after it raises its epoch above
a retired floor ([#5643](https://github.com/NSTA1/Orleans.Lattice/issues/5643)).

**Range deletes are fenced at the tree.** A range-delete record is replayed by every
overlapping leaf of every shard, so the fence belongs to the tree. Before any shard
appends, the range delete opens an **intent** at the tree's range-delete fence grain,
which records the range and a deadline (the silo's response timeout less a margin),
opens a range-scoped marker on every shard root, and hands out the tree's current
range-delete generation. Every shard's walk is stamped with it, so the close's one
re-claim per partition fences every walk at once. The intent closes when every walk
has returned; a per-tree reminder closes one whose deadline passed, so a fan-out
whose caller died is closed all the same. A walk rejected after a close re-stamps
only while its **own** intent is still open, and otherwise goes on unstamped. The
intent is marked closing, durably, before the close's first re-claim, and the open
check is answered by the same non-reentrant grain, so it can never hand out the
post-close generation to a walk the close has already fenced. A range-delete walk
that reaches a shard root through the existing method - replication apply, a resize
or reshard shadow forward, a fan-out begun while the gate was closed, an older
caller - is appended unstamped, by design. The record, its result and its feed are
unchanged; range-delete records are fenced, never clipped.

**The bulk birth hint.** A bulk load or bulk append records a **birth hint** - one below
a head of every WAL partition read before its first leaf is born - in the shard's marker row,
in the same write that opens its marker and before it creates its first leaf; a resume
of the same operation reuses the stored hint. Each chunk of a streaming import - a
**run** - reads the heads afresh, or takes the heads of the fence it folds (below): a
lower hint is never above a record the leaf has not applied, but it lengthens the
replay, and a hint reused across a run would make each later chunk's leaves replay
everything the run had appended before it
([#6160](https://github.com/NSTA1/Orleans.Lattice/issues/6160)). Once the switch has moved into its new leaves every row the shard held
in their range before it - the old rightmost leaf's rows for an append, the rows a
batch write stored on the replaced root for a load (see
[Bulk Loading](../bulk-loading.md#rows-the-append-meets)) - each new leaf's projection
checkpoint is set to the hint, so a cold activation replays the log from there rather
than from its start. Every row such a leaf owns was then appended after the hint. When
that cannot be shown - the old rightmost leaf is hosted by an older build or the gate
was closed, so its rows were not moved, or a load crashed after publishing its root -
the hint is not applied and the new leaves replay from the log's start, as before. A
bulk load's leaves take the hint as they are born, capped as described below, rather
than once the switch completes, so no leaf holding loaded rows meets a checkpoint tick
with no checkpoint (#6160); an append's leaves take it only after the narrow has moved
the old leaf's rows, since a narrow that fails moves none. A
load into a never-written shard opens no switch and stores no hint, but it reads the
same heads before its first leaf is born and sets each leaf's checkpoint to them once
its root is published
([#6152](https://github.com/NSTA1/Orleans.Lattice/issues/6152)): a write reaches a
leaf only after the shard has a root, so no row of that shard lies below them. A
bulk load then closes its switch by fence, removing the hint in the same write. A bulk
append leaves its switch open for the run, which only holds its leaves on the
replay-based advance longer: a close per chunk would cost a claim per partition and
two marker writes, and reject every concurrent stamped write of the shard once, per
chunk. The completed switches of a shard are closed together, by one fence and one
marker write, when eight have accumulated (folded into the next chunk's open write,
whose hint then becomes the fence's heads), when no chunk has reached the shard for
five seconds, or by the next bulk load; a fresh activation folds them into its first
chunk. A switch that an append opened and then abandoned before it recorded its graft
is closed the same way, without its hint. A bulk load also waits, before it reads the
root it replaced, for the batch writes admitted before it published its own; a run's
fence waits likewise, which only lowers the number of writes it rejects.

**Writes in flight at a read position.** A leaf write checks its span, appends its WAL
record and only then stores its row, so a head read while such a write is between its
append and its store lies above a record the leaf has not applied. Were the activation
to die there, a new leaf born at that head and the narrowed donor, whose span no longer
covers the key, would both skip it. So the old rightmost leaf, before it narrows to a
bulk append's low bound, and a dividing leaf, after it reads the heads that become its
sibling's read position and before its intent is persisted, both wait for the writes
they admitted earlier to finish ([#5706](https://github.com/NSTA1/Orleans.Lattice/issues/5706)).
The wait is bounded. A narrow that times out narrows nothing, and the append links its
leaves without narrowing and applies no hint, exactly as 10.2.0 does, so a slow write
never fails a bulk chunk; a leaf an earlier attempt already narrowed forwards its later
out-of-span writes and does not wait. A
division that times out is declined (split_attempts outcome commits_in_flight)
and retried by the next write. A division resumed from its persisted intent cannot
wait - a write blocked on the gate it holds would be among those it waits for - so it
gives neither leaf a read position and the sibling replays its range from the log's
start. The marker's close heads do not cover this: they gate the live advance's arming,
not the read position a new leaf replays from.

**Records another author appended.** The drain covers the old leaf's own writes only.
A record of the moved range that another author appended - another shard's
range-delete walk, a duplicate activation of the old leaf, a 10.2.0 silo during an
upgrade - and that the old leaf has not replayed lies above how far it has replayed,
and below the heads. So a new leaf never starts reading higher than that: per WAL
partition, an appended leaf applies the lower of the birth hint and the old rightmost
leaf's checkpoint, read in the same step that narrows it, and a split sibling the lower
of the heads and its donor's checkpoint, read before the division's intent is persisted
([#5752](https://github.com/NSTA1/Orleans.Lattice/issues/5752)), and a bulk load's leaves
the lower of the birth hint and the lowest checkpoint of the leaves of the root the load
replaced, each read in the same call that copies that leaf's rows into the loaded tree
([#5766](https://github.com/NSTA1/Orleans.Lattice/issues/5766)); a load that replaced no
root, or whose replaced leaf is hosted by an older build, applies no hint. Because that
cap holds a new leaf at wherever the old leaf last replayed, which for a leaf serving
only live writes can be far behind the head, the old rightmost leaf of an append is
driven to the head before the append reads its tail, and each replaced leaf of a load
before it reports its checkpoint (#6160). The drive is best effort: a leaf that cannot
be driven keeps its lower checkpoint, which is only a longer replay. The checkpoint is
inclusive - a leaf replays every record above it - so it is taken as it is: one above
it is exactly the first record the old leaf had not applied. Before the narrow the old
leaf still declares the whole range, so its replay applies such records rather than
stepping past them; after it, a replay steps past them, which is why a graft resumed
on a leaf an earlier attempt already narrowed applies no hint. A lower read position
only lengthens the new leaf's first replay.

The old leaf's frontier is its in-memory projection checkpoint. Its replay moves it -
to the end of its activation replay, then by any later replay - and the live advance
moves it over the leaf's own writes only while armed, behind the append fences; a write
applied in memory never moves it on its own. A checkpoint hint also moves it: a split
sibling's or bulk-born leaf's read position, and a split donor's own advance, each
capped as described here - the donor advances to the same capped heads its sibling
starts from, which is a no-op wherever it has a frontier
([#5756](https://github.com/NSTA1/Orleans.Lattice/issues/5756)). So the frontier is
contiguous: every record at or below it has been applied. A partition on which the old
leaf has scanned nothing (it activated on an empty partition and has not replayed
since, or was born from such a leaf) has no frontier, reported as -1. There an appended
leaf applies no hint, as in 10.2.0. A split sibling and its donor instead take one below
the head, as in 10.2.0: a sibling with no read position would replay the whole log and
seed its birth pin on the sentinel that blocks the tree's WAL trim. That is the
residue: a split on a partition its donor has never scanned can still skip another
author's record, appended to the range after the donor activated, and a later cap at
either leaf's frontier inherits it. The live advance closes it once it keeps frontiers
current.

A donor that no longer advances to the heads may reactivate onto a snapshot captured
before it split, which still holds the rows the split moved to its sibling. Replay
never removes a key outside the declared span, so rehydration drops every row at or
above a completed split's key that the leaf no longer declares; the sibling holds all of
them. A row below that key - one a later bulk narrow stranded, owed to the graft's
relocation - is kept.

**A hinted leaf captures before it persists**
([#5877](https://github.com/NSTA1/Orleans.Lattice/issues/5877)). A split sibling's birth
hint, or a bulk switch's, can give a leaf its first checkpoint at a partition that no
durable snapshot covers. Persisted as it is, that checkpoint would sit above the leaf's
coverage, and a kill or a failed capture before the next capture would leave the next
activation to repair at activation or replay cold. So every flush of such a checkpoint -
the coalescing flush, the coverage-lag tick's bank step, an explicit flush and the
graceful-deactivation flush - first captures the leaf's cache, claiming the hinted
checkpoint. A partition still uncovered after that capture is held back from the write
and stays pending, so its persisted checkpoint stays at -1. A failed capture is retried
once per coverage-lag tick or at deactivation, never once per flush, and is not charged
to the zero-coverage repair budget. A partition a snapshot already covers pays nothing
new, and a leaf's own split advance and its live advance keep their existing path.

**A head is one past a checkpoint.** A WAL head is exclusive - the next offset the log
will assign - while a leaf's checkpoint is inclusive - the last offset it has applied, and
it replays every record above it. So every head a split or a bulk operation reads becomes
a read position one below it, for the split sibling, the split donor's own advance, the
sibling's birth pin and the bulk birth hint alike
([#5760](https://github.com/NSTA1/Orleans.Lattice/issues/5760)). Taken as it is, a head
would skip the record first allocated at it, which, written by another author, no leaf
would then apply; one below re-applies at most one record, which last-writer-wins makes
idempotent. A read position of 0 therefore means offset 0 is applied and is stamped and
pinned as a real offset; only a negative one means nothing applied.

**Coordinator terminals** carry the coordinator-terminal stamp class described in
[Append epoch fencing](append-epoch-fencing.md), so a saga does not raise the reported
unstamped offset of every partition it touched.

**Rolling upgrades.** Every new call - a stamped leaf or shard-root method, a marker
call, the range-delete fence - is made only while the gate is open. A callee on an
older build that answers with the definite "method unknown" failure is re-issued
through the existing, unstamped method; any other failure keeps today's semantics.

**Cost.** No allocation or grain call is added to a write: the routing stamp is a
call argument, and the leaf's dispatch helpers are pooled. Per shard root: one
marker-row write the first time it admits a write with the gate open. Per split:
one marker write at the sibling's birth, one epoch-row write and one claim call per
partition the donor had claimed, and one marker write at the close. Per reclaim: a
marker write, a retirement call per partition and a marker write. Per slot
migration: a marker call to the target at each phase, one generation re-claim per
partition at the close. Per range delete: one fence-grain call to open and one to
close, one marker write per shard to open and one to close, one generation re-claim
per partition, and the reminder only while an intent is open. Every overlapping
leaf of the tree is held for the delete's duration. Per purge: a read and a
conditional delete per fence row, and a floor write per step. Per WAL partition
activation: one floor-row read at its first routing-generation claim. Per shard root
of a re-created tree: one floor-row read before its marker first reads initialised,
and, when the floor is above 0, one fence-grain call and one claim per partition.
Per bulk load: one read of each partition's head and one marker write to open, one
checkpoint-hint call per new leaf, and one generation raise, one generation re-claim
per partition and one marker write to close. Per bulk-append chunk that creates leaves:
one marker write to open and one checkpoint-hint call per new leaf; the heads are read
once per run, and the close - one generation raise, one re-claim per partition and one
marker write - is paid once per eight chunks and once at the run's end. The old
leaf's replay frontier rides the narrow's existing reply, and the read gates of
relocated rows cost one marker call per saga per appended leaf, only when those rows
carry saga state. The in-flight
drain adds two counter updates to each leaf write, on fields the activation already
owns, and no allocation or call.

**Purging a tree's fence rows.** The per-tree rows - each shard root's
`_lattice_shard-handoff` marker, each partition's `_lattice_wal-routing-generations`
table with its slots for the shard roots and the range-delete fence, and the range-delete fence
grain's own state - are retired when the tree is purged
([#5668](https://github.com/NSTA1/Orleans.Lattice/issues/5668)), before the purge
removes the tree's registry entry, which is what frees the id for re-use. A soft
delete retires nothing, so a recovered tree keeps every row.

The purge first reads every row. It then raises every initiator's routing floor
(`_lattice_tree-routing-floor`, one floor per shard root and one for the range-delete
fence) to the highest generation any row holds, in one write, before it deletes
anything. It then retires the fence's state, the markers, and each partition's
entries, in that order. A row that moved since the read is covered again before its
delete. A failed step keeps the registry removal owed, and the purge's re-drive runs
the retirement again. A partition hosted by a 10.2.0 silo answers the retirement
call with the definite "method unknown" failure, and its rows are deleted straight
from storage.

The floors keep a purged incarnation's generations from recurring:

- A WAL partition refuses a routing-generation claim at or below its initiator's
  floor. This check is load-bearing, not an optimisation: it is the one seam every
  generation passes before a stamped append under it is admitted.
- A write a shard root admitted under a generation at or below that initiator's
  floor is never re-stamped
  ([#5705](https://github.com/NSTA1/Orleans.Lattice/issues/5705)). Its seam retry
  surfaces the deleted-tree outcome rather than raising the generation above the
  floor or re-admitting under the re-created tree's. A shard root that saw its marker
  and then finds it gone under a floor covering it never re-creates it.
- A re-created tree seeds every first generation, its shard roots' and its
  range-delete fence's, at its initiator's floor plus one.
- A re-created shard root's first initialisation is a fence. Before its marker reads
  initialised, it has the range-delete fence claim its seeded generation at every
  partition, claims its own, and records the heads as a close. So a write the purged
  incarnation appended between the purge's log trim and the retirement lies below
  heads the new leaves must replay past before the live advance re-arms them. A tree
  id never purged has floor 0 and claims nothing extra.

**A purge that finished on a 10.2.0 silo** retires nothing, so its markers survive.
A shard root that re-seeds the purged root catches up before it lifts the purge
tombstone. A marker that holds a generation or reads initialised was left by the
earlier incarnation, since only that shard root sets either, and only after it has
seeded. The shard root raises its own floor over that generation and resets the
marker, so it seeds above the floor through the first-initialisation fence. It
raises only its own floor: shards of the re-created tree re-seed one at a time while
the tree is live, and raising any other initiator's floor could cover a generation
that initiator already holds.

Three residues remain, all bounded:

- **One floor row per purged tree id.** It must outlive every row it covers.
- **Rows a purge never retires.** That is a purge that finishes on a 10.2.0 silo, a
  system tree's purge, or the purge of a retired physical copy whose id stays
  registered as a live logical tree. Neither of the last two ids is freed for a
  re-created tree. Each is bounded by the tree's shards times its partitions. The
  fence's per-leaf rows are swept separately
  ([#5634](https://github.com/NSTA1/Orleans.Lattice/issues/5634)).
- **Mixed-version re-creation.** After a purge that finished on a 10.2.0 silo, two
  cases are not caught up: a shard root whose re-seed itself ran on a 10.2.0 silo,
  and the range-delete fence's state the earlier incarnation left. A re-created
  incarnation can then reuse a generation that a straddling write or range-delete
  walk of the purged incarnation still holds. To do harm, that straddler's seam
  retry must outlast its operation's deadline across:
  1. the gate closing for the 10.2.0 silo;
  2. the purge settling on that silo;
  3. the id's re-creation;
  4. the gate reopening once the upgrade completes.
  Do not purge trees while a rolling upgrade from 10.2.0 is in progress.
The hand-off counters are `orleans.lattice.wal.append_fence.handoff_markers`,
`.unstamped_appends` and `.self_fenced`; see [Metrics](../metrics.md).

Previous: [Append epoch fencing](append-epoch-fencing.md). Next: [Live checkpoint advance](live-checkpoint-advance.md). Contents: [Write-Ahead Log](../wal.md).
