---
title: "Append epoch fencing - Write-Ahead Log"
url: "https://nsta1.github.io/Orleans.Lattice/docs/lattice/wal/append-epoch-fencing.html"
source: "https://github.com/NSTA1/Orleans.Lattice/blob/release/10.5/docs/lattice/wal.md?plain=1#L1473-L1838"
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"
---
# Append epoch fencing

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

Orleans promises one activation per grain, but during a membership change a
leaf can briefly run twice. A WAL partition therefore fences appends by **leaf
activation epoch** ([epic #5605](https://github.com/NSTA1/Orleans.Lattice/issues/5605)),
so a stale duplicate activation can never append after a newer one has claimed.
The design note is `spec/wal/design/LiveAdvanceDesign.md`. The fence is what lets
a leaf advance its checkpoint over its own writes without a replay; see
[Live checkpoint advance](live-checkpoint-advance.md).

**The claim.** Before an activation's first append to a partition, it claims an epoch:

1. **Epoch row.** The activation writes the epoch its leaf's epoch row held, plus
   one, as a strict conditional write. Only claims write that row, so any
   conflict means another activation claimed; this one is stale and deactivates.
2. **Entry write.** At the partition, the claim is written to the partition's
   durable entry for the leaf as a conditional max-merge, so the entry never
   moves down. A claim at or below the entry, or at or below the partition's
   **retired floor**, is refused.
3. **Raise.** Under the lock that assigns offsets, the partition raises its
   in-memory entry and returns its next offset as the **claim head**: everything
   allocated before the claim lies below it.

On any refusal the activation persists an epoch above the refused value and claims
again, conditionally on the epoch row it last wrote: if that row moved, another
activation claimed and this one was superseded. After eight refused rounds, or a
claim that fails for any other reason (a storage fault, a timeout), the append goes
unstamped and the activation keeps appending unstamped for 30 seconds before it
tries again, so a faulting store costs one claim attempt per window, not one per
write.

**Stamped appends.** Every append then carries the leaf's id and epoch as a call
argument, never in the stored record. The partition checks it in the same locked
step that assigns the offset: an epoch below the leaf's entry is rejected and
allocated nothing. An entry the partition has not loaded since it activated (after
a restart, or a WAL move's cutover) rejects the append until the leaf re-presents
its claim, which reloads the entry. The retired floor is checked at the claim, not
at the append: it is one value per partition while epochs are per leaf, so checking
it at every append would let one leaf's retirement supersede every live leaf below
it ([#5635](https://github.com/NSTA1/Orleans.Lattice/issues/5635)). A retired leaf's
own appends meet its deleted entry instead. A multi-entry stamped batch holds its
leaf's claims back until every entry has an offset, so it is admitted whole or
rejected at its first entry, never split by a claim.

**Rejections never reach a caller.** A rejected activation deactivates, and the
caller of the leaf write - the shard root's leaf-call step for every `ILattice`
write, saga prepare, replication apply, view and restore, and the leaf-to-leaf,
bulk and compaction seams - retries against the live activation until the
operation's existing deadline: its cancellation token, or else the silo's
configured Orleans response timeout. A rejection is not a provider failure, so it
never feeds the WAL saturation signal. When that deadline expires the caller sees exactly
what it sees today: a `TimeoutException` or an `OperationCanceledException`.
The refusal itself is the leaf's existing retired-leaf refusal, marked as a
superseded activation in two trailing fields. A shard root on an older build, which
can reach a newer leaf while the gate races a rolling upgrade or rollback, does not
read those fields: it sees the retired-leaf refusal it already retries until its
deadline, and never a type it cannot resolve. A re-presented claim that is rejected
as unloaded eight times in a row is not a supersession: the append goes unstamped
and the activation stays.

**Durable rows.** The epoch row, each partition's entries, its retired floor and
its routing-generation table are rows of their own under reserved grain types
(`_lattice_leaf-append-epoch`, `_lattice_wal-append-epoch`,
`_lattice_wal-append-epoch-floor`, `_lattice_wal-routing-generations`), written
through the tree's grain storage provider. No existing state type gains a field.
A partition's routing generations are one row with a slot per shard-level initiator
(each shard root, and the tree's range-delete fence)
([#5987](https://github.com/NSTA1/Orleans.Lattice/issues/5987)). Every write to it is a
conditional read-modify-write that raises one slot and leaves the others as read, so
two initiators raising their slots at once both survive, and the partition loads every
slot with one read. That read is refreshed by every claim's read of the row and re-read
once it is five seconds old, so a raise by a duplicate activation of the partition
reaches it within a bounded time. Every raise rewrites the whole row; raises are rare (an arm or a
close), and at the largest tree a slot per shard (4,096 shards) still fits one Azure
Table entity.
The rows are keyed by tree and partition, not by WAL provider, so a WAL move
carries them unchanged. When a leaf is cleared (purge, reclaim, orphan repair) or
the WAL GC retires an orphaned leaf's materialiser pin, each partition raises its
retired floor to at least the higher of the leaf's entry and its epoch row before
deleting the entry ([#5641](https://github.com/NSTA1/Orleans.Lattice/issues/5641)).
The clear deletes the epoch row, so a leaf re-created under the same id starts its
epochs again from one; covering the row as well as the entry means neither a
surviving duplicate nor one that has written its row but not yet its entry can share
an epoch with it. An activation that keeps serving after its own clear claims afresh
as the re-created leaf. For the GC, the partition reads the leaf's epoch row itself,
and does nothing more for a leaf with no row - one that never claimed, or whose
clear already retired it.

**The orphaned-row sweep** ([#5634](https://github.com/NSTA1/Orleans.Lattice/issues/5634)).
A clear on a silo running an older build, during a rollback or a rejoin after the
gate opened, deletes none of these rows and removes the leaf's materialiser pins, so
the GC never finds the leaf again. The rows are inert, since only that leaf's claims
read them, but storage cannot enumerate them. Each partition therefore keeps an
**append-epoch directory** (`_lattice_wal-append-epoch-dir`): 64 hash buckets, each a
chain of pages of at most 384 leaves, small enough for any provider's row limits in
binary or JSON. A partition lists a leaf before it first writes the leaf's entry and
delists it after retiring the entry. A background sweep, registered with the WAL GC,
walks every tree's directories once every 6 hours across the cluster; a silo claims a
tree's sweep through a conditional write to its row (`_lattice_wal-append-fence-sweep`).
For each leaf listed for more than 24 hours whose row is absent or has no tree id, the
test the GC uses for an orphaned pin, the sweep runs the leaf's clear sequence above:
retire at every partition with the epoch row's value, then delete the row
conditionally. It examines at most 1,024 leaves per tree per sweep, resuming where the
previous sweep stopped, so live leaves never hold an orphan back. A silo's first sweep
comes 5 to 15 minutes after it starts, so frequent restarts cannot starve it. The fence's safety
does not rest on that test: retiring a leaf that is still live only costs its
activation a deactivation and a re-claim above the raised floor, and its writes are
retried at their seams.

**Unstamped appends are always admitted.** An append through the existing,
unstamped methods - an append from a silo running an older build, one from a silo
whose view of the gate is closed, or a write that is unstamped by design (see
[Hand-off fences](hand-off-fences.md)) - is never rejected. The partition records the
highest such offset and reports it in every stamped response, so a later checkpoint
advance can never skip it; an activation reports its own unstamped appends to
itself. A saga coordinator's `TxCommit` or `TxAbort` record carries the
**coordinator-terminal** stamp class instead: it is admitted with no entry check and
does not raise the reported offset, because such a record carries no row data and a
leaf holds its advance while the prepare it resolves is pending. A record of any
other kind sent with the class is admitted unstamped and reported, so the class
cannot bypass a fence.

**Rolling upgrades.** Leaves claim and stamp only while every active silo's grain
manifest advertises the append-fence capability. The gate is not ratcheted: if a
silo running an older build joins, or rejoins in a rollback, it closes again by
itself and leaves appends unstamped. If a newer silo reaches an older one before its
gate has observed the join, the older silo refuses the unknown method while
deserialising the request; only that definite failure is re-issued unstamped.
Any other failure keeps today's retry semantics.

**Cost.** Per stamped append: one dictionary lookup and two comparisons, under the
lock the append already holds. Per leaf append, stamped or not, the leaf reads the
silo's cached gate verdict without a lock, comparing two versions. Per activation:
one epoch-row read and write, then one claim call, one entry-row read and one
entry-row write per partition it writes. The first write after each leaf activation
therefore waits for about four sequential storage round trips before its append, a
latency change for cold leaves. Per leaf clear: one epoch-row read, then for a leaf
that has claimed, one retirement call per WAL partition (a floor and an entry read,
a floor write and an entry delete) and the epoch row's delete. A tree purge pays
that per leaf. Per orphaned pin the WAL GC retires: one retirement call, which
reads the leaf's epoch row at the partition and stops there when it has none.
The directory adds a read of the leaf's bucket chain (normally one page) and a page
write each time a partition first writes a leaf's entry, and each time it retires
one, so a clear also reads the chain at each partition the leaf never wrote. Per tree
every 6 hours, the sweep reads every directory page of every partition (at least 64
reads per partition), then one leaf row per leaf it examines, up to 1,024.

The fence's counters are `orleans.lattice.wal.append_fence.claims`,
`.rejections`, `.seam_retries`, `.unstamped_reports` and `.sweeps`; see
[Metrics](../metrics.md).

## Deferred claims: the pre-arm class

Claiming at every partition a leaf writes is paid at every leaf birth and every
activation, but the claim is needed only by a leaf that advances its checkpoint
live. While every active silo also advertises the pre-arm capability, a leaf
therefore defers its claim until it **arms** a partition
([#5833](https://github.com/NSTA1/Orleans.Lattice/issues/5833)). If a silo without
that capability joins, the gate closes again and leaves claim eagerly as above.

- **Pre-arm appends.** Until it arms a partition, an activation appends there under
  the pre-arm class: the stamp names the leaf and a random token per activation,
  and no epoch. The partition checks no entry and writes no row, so a new or
  reactivated leaf pays no claim, epoch row or directory write. The routing
  generation is still checked, as for any stamped append. A write that carries no
  routing generation is never pre-arm: it goes unstamped and raises the shared
  watermark.
- **Attribution.** For each leaf, the partition keeps in memory the two activations
  with the highest offsets it allocated to that leaf's records, stamped or pre-arm.
  A pre-arm record never raises the partition's shared unstamped watermark, so
  unarmed leaves do not hold armed ones back. Instead each stamped append's
  response reports the highest offset any *other* activation of the same leaf
  allocated, so a duplicate activation's record is read before the leaf advances
  over its own. After a restart everything below the recovered head counts as
  foreign. Past 16,384 leaves the older half of the table, by highest offset, is
  evicted, and each evicted leaf raises the floor of its own hash bucket, one of
  1,024 per WAL shard activation (8 KB, reset with the activation, never persisted).
  A leaf's foreign high is read against its own bucket's floor only, so an eviction
  holds back only the leaves that share an evicted leaf's bucket, and only to that
  bucket's newest evicted record ([#5851](https://github.com/NSTA1/Orleans.Lattice/issues/5851)).
- **The arm.** A leaf arms only when its pin holds the partition's WAL floor: inside a
  starvation drive (the WAL GC found it holding the floor), or on its snapshot recheck
  tick when it has live data and no proven checkpoint on any partition. It never arms
  on a write or a routine checkpoint. A split sibling inherits its donor's checkpoints,
  so it is not in that state and does not arm. They are capped at the donor's
  frontier unless the split's consistent cut shows that frontier is past every other
  author's record (see "The claimless advance" below). The
  leaf writes its epoch row once, then claims at every partition it is arming in one
  parallel round, only while no hand-off is open on it. Each claim also returns the
  leaf's foreign high, which the leaf must have replayed past before it advances live;
  its own pre-arm records it applied itself.
- **Deferred hand-off closes.** A split or a consolidation no longer claims at every
  partition when it closes. A split's donor closes its sibling's window itself (see
  "The claimless advance" below), and the shard root only raises its routing
  generation as it links the split. For a consolidation, the shard root, in its own
  turn as it folds the leaf, raises its routing generation without claiming it at
  any partition, and records the close on the receiving leaf's marker with every
  head deferred. A deferred head holds that leaf. Its arm then re-claims the generation
  at the partition, so any write admitted before the raise is either below the
  re-claim's head or refused, and records that head. Resizes, bulk switches and
  range deletes still close eagerly.

**Cost with the pre-arm class.** Per leaf birth or activation: nothing until it
arms. Per stamped or pre-arm append: one further dictionary lookup under the same
lock. Per split or consolidation: one shard-marker write and the receiver's marker
read and write. Per arm: the epoch row read and write, one claim per armed
partition, and one generation-row write per partition only for the first arm there
after a deferred close.

The pre-arm class adds two counters to the fence's set:
`orleans.lattice.wal.append_fence.arm_failures` counts leaf arms that failed at a
WAL partition (the partition stays pre-arm and advances by replay until a later arm
lands), and `orleans.lattice.wal.append_fence.reclaim_allowance` counts a pre-arm
split donor's one extra fresh claim per close (see
[Hand-off fences](hand-off-fences.md)), tagged `outcome` = `spent_stale_epoch`,
`spent_row_conflict` or `superseded_after_close`; see [Metrics](../metrics.md).

## The claimless advance

Under the pre-arm class a leaf can also advance its checkpoint live **without
arming** ([#5837](https://github.com/NSTA1/Orleans.Lattice/issues/5837)). Every
response to a stamped append reports a bound that covers every record below the
leaf's own append that it did not write: another activation's, an unstamped one, or
a donor's it has not yet been released from. Once the leaf has read past that bound
and every close head on its markers, it may advance there with no claim. A partition
whose latest report did not cover every donor close pending on the leaf has no
claimless view, and the leaf advances there by replay instead.

- **Splits close their own window.** The donor closes its sibling's birth window
  itself once its narrowed span is durable. It first waits for every append it
  started before the narrow and fences its duplicate activations. Then, in one
  marker write, it records a head one above its own highest moved-key record since
  the split's heads (or the heads, when it wrote none), and a deferred bound: the
  donor leaf, its own activation token, and the routing generation its writes were
  admitted under. If an append touching the moved range failed without reporting
  its offset, the head is the allocator head read after the wait instead. A resumed
  close (a recovered split, or the re-drive when the shard root acknowledges the
  link) has no such record. It closes at one above the highest offset any activation
  of the donor allocated, never below the partition's restart or eviction floor. Its
  bound names the shard's current routing generation. A close that fails keeps the
  donor's link obligation, so the split re-surfaces and the link re-drives it; the
  shard root never reads or closes the sibling's marker.
- **The donor's stale high.** The donor's bound stays pending until the sibling's
  own link is witnessed. The shard root records the witness on the sibling's marker
  only after that link's raise of the routing generation is durable. A raise for any
  other link never resolves the bound, and if the raise or the witness write fails,
  the bound stays pending and the division re-surfaces. The witness is kept on the
  sibling's marker as well as on the close, so a donor close written after the link
  (a re-driven or recovered close) has its bound resolved at once.
- **Carrying the close.** The witness ends only the bound. The sibling's stamps
  keep carrying the close at each WAL partition until the sibling arms there,
  re-claiming the close's shard at a generation at or above the witness. One marker
  write then raises the close's head at that partition to the head the re-claim
  returned and marks the partition resolved; a failed write leaves it carried. A
  re-claim below the witness, or a witness from another shard root, resolves
  nothing. From the first coverage-lag tick after the witness, the tick arms a
  carried partition only while the carry **binds** there
  ([#5851](https://github.com/NSTA1/Orleans.Lattice/issues/5851)): the leaf has an
  own applied append above its checkpoint that the tick's advance could not pass,
  and the bound its latest stamped response reported, which covers every close
  carried there, lies above that checkpoint. A partition an arm has already claimed,
  whose resolve write failed, binds too while it holds such an append, whatever its
  bound. The tick checks this in memory first, so a
  sibling with nothing binding reads nothing, and again on its own fresh marker
  read, which alone triggers the re-claim. A carry that binds nothing is left in
  place, so every stamp keeps the close. Each partition is armed once for each
  witness, and again after a failed attempt; it never re-reads the marker for a
  close it cannot resolve. While the close is carried, each WAL partition reports
  the donor's **stale high** for it. That is
  the highest offset of a donor record from any activation other than the closing
  one, whatever routing generation admitted it: a link elsewhere in the shard can
  raise the generation while the close is pending, and a stale duplicate's write
  admitted under the raised one still sits above the close head. Its own forwards are excluded only when they moved keys to this
  sibling. A stamp carries at most two pending closes; while more are pending, the
  leaf does not advance claimlessly.
- **Forwards.** A write a leaf forwards to another leaf before that leaf is linked
  is attributed to every forwarder on its chain as well, up to three hops. A write
  forwarded further is appended unstamped. The first forwarder's own forwards are
  left out of the bound reported to it once its narrow is durable; a write that
  reached a leaf through a later hop of a chain is never left out. That stops on any
  ETag conflict on its state, and a new activation never assumes it.
- **Transfers.** The rows a split donor moves into its sibling are appended under
  the routing generation the sibling's span was established under, attributed to
  the sibling, so they never raise the shared watermark. A transfer that is not
  wholly inside the sibling's span is appended unstamped as before. One refused
  because its generation was re-claimed re-reads the shard's current generation, as
  an admission would: from the shard's marker, read fresh, with no hand-off open
  over the span, and with descent routing both its lowest and its highest key to
  the sibling or, before its link, both to its donor. It then retries routed once,
  and only a failed refresh appends it unstamped.
- **Reachability.** A sibling born by a split is proven reachable at its birth.
  While its donor's bound is pending, a sibling that descent does not yet reach is
  neither proven nor latched unstamped; its decision is deferred until the link.
  Meanwhile it stamps its routed writes pre-arm, so it never raises the shared
  watermark; it never claims or arms, and it proves again after a backoff. That
  holds even for a sibling proven at its birth: it is deferred, and proven again
  once its own link is witnessed and it is reachable. Reachable alone (linked, with
  the witness not yet durable) is not enough. A leaf proven without reading its
  marker proves again before its first claim under the eager gate, and no leaf
  claims or arms while a donor close is pending on it. Once its link is witnessed, a leaf that
  descent does not reach has had its keys moved, and it latches. Orphan repair
  always latches.
- **The split's read position.** Each partition returns its readable head with the
  bounds the donor must have read past, all read in one turn. If the donor's
  frontier is at or above every bound, its sibling starts at the head rather than
  at the donor's frontier. The unstamped bound in that read is filtered by key
  ([#5851](https://github.com/NSTA1/Orleans.Lattice/issues/5851)). The donor
  passes the range it owns, read in the same turn: the whole pre-split range, and
  after a fold the widened one. The partition keeps its 256 most recent
  single-key unstamped records (a set, delete or tombstone) by key, in memory
  only. It returns the highest of those keyed inside the range, or its floor if
  that is higher. The floor is the restart head, raised by every record that
  may touch other keys (a range delete, a transaction terminal, or a record
  naming matched keys) and by every record pushed out of the table. So an
  unstamped write elsewhere in the partition no longer holds the split back. The
  shared watermark every stamped response reports is unchanged. An activation that
  has not yet read its markers reads them once before it takes its first cut, so
  the cut's view of the donor carries every close pending on it; a close recorded
  after that read still caps the cut.
- **Catching up.** Only a replay reads past a foreign or unstamped record, and a
  pre-arm leaf that is neither starved nor stalled does not replay. So when the
  claimless advance, or a split's read position, is held only by a reported bound,
  the leaf's next coverage-lag tick runs the existing replay drive, which reads
  past it. A leaf owing such a read stays resident until it has read past the bound,
  released once it has read nothing further for 30 minutes of drives the replay gate let in (a refused, deferred or yielded drive does not count), because the debt is held only in memory and the drive yields
  while the replay gate is contended; a leaf that idled out owing it left the read that
  next activated it to pay it ([#6166](https://github.com/NSTA1/Orleans.Lattice/issues/6166)).
  A hold by concrete close heads is caught up the same way
  ([#5851](https://github.com/NSTA1/Orleans.Lattice/issues/5851)): the claimless
  advance reads to the close head minus one once its reported bound is passed, and
  a split's read position to the higher of that and the cut's foreign high, which
  includes the stale highs of the closes the donor carries, once the shared
  unstamped watermark is passed. A close head is a target only when no close
  bearing on the leaf is deferred at any partition and no donor bound is pending: a
  deferred head is the arm's to resolve, never a replay's. The replay leaves the
  checkpoint at its own contiguous read position, never at the target. A drive runs
  once for each partition and target, again only when the target rises, and never
  on a write. A drive that is refused or deferred, or that otherwise does not run
  its replay, leaves the target owed for the next tick.
- **Fetching a missing report.** A leaf's claimless view at a partition is the
  report its latest stamped append returned. An idle leaf whose latest report
  predates a close it now carries has no covering report, and writes nothing that
  would bring one. So on the coverage-lag tick, when that missing report is the only
  hold (no hand-off open, the partition not latched stale, and the checkpoint at or
  past every close head minus one and below the leaf's own high), the leaf fetches,
  read-only, the report a pre-arm append at that partition would carry, records it as
  that append's response, and advances to its own high when the fetched bound allows
  it, never past it
  ([#5851](https://github.com/NSTA1/Orleans.Lattice/issues/5851)). The fetch never
  runs on a write, inside a starvation drive, or at a partition the activation has
  claimed. A WAL shard on an older build that does not know the call turns the fetch
  off for the rest of the activation; any other failure is retried on the next tick.

**Cost of the claimless advance.** Per stamped or pre-arm append: one comparison
for the reader's narrow, a request-context read for a forward chain, and a counter
increment and decrement for the split's wait, with no allocation and no grain call.
A pending close adds one stale-high lookup per close carried. Per forward: one
small array per hop. Per split: one marker write closes the window, and the read of
the heads also returns the bounds; filtering the unstamped bound by key
scans the 256-entry table once per partition. A transfer refused stale costs one view read and
up to four descents (two keys, against the sibling and then its donor) before it retries. A report fetch is one
read-only, interleaving WAL shard call per held partition per tick, answered from memory. The carried-close re-claim
reads nothing on a tick where no carried close binds. Each reported bound or close head that
holds a leaf costs one replay drive on a tick, through the replay permit. A leaf
allocates its two per-partition bound arrays once, on the first such hold.

Previous: [Trim and GC](trim-and-gc.md). Next: [Hand-off fences](hand-off-fences.md). Contents: [Write-Ahead Log](../wal.md).
