The design: 3. The bulk birth hint to 5. Rejections are retried where they are raised

This page is part of the documentation for Orleans.Lattice 10.5.0 (release line 10.5), built 2026-12-05. It is also published as markdown, with every table and list, at the-design-2.md, and llms.txt lists every page.

Part of The design, in Live checkpoint advance: fenced redesign.

3. The bulk birth hint

A bulk load or append captures per-partition WAL heads before its first leaf is born, before any write it can race. The leaves it creates take those heads as their birth hint. The hint is the read position they start from, as a split sibling starts from its donor's heads (WalHeadsAtBirth). With the open marker, re-arming then means a short, bounded replay from the hint to the close heads of the switch's fence. That replay imports any write that reached the old leaf in the window, before the advance proceeds as for any leaf.

The hint is needed by every arming, not only by the live advance: it is the leaf's birth read position. Starting the leaf at the head when it is created instead fails without any live advance (ReadPositionHonestBulkWithoutHint).

A run shares a hint (#5702). A chunk's hint may be any head read before its first leaf is born: a lower hint is never above an unapplied record, it only lengthens the replay. So consecutive append chunks on a shard reuse the previous chunk's hint, or the heads of the fence they fold, and read the partitions' heads only at the start of a run. A resumed operation's stored hint always wins (S7, below).

The hint is capped at the old leaf's applied frontier (#5752). Rows the old leaf O holds are relocated into the bulk-born leaf, and O's own admitted mutations are drained before its bound narrows, but a record of the range that another author appended below the heads, and that O has not yet applied, would be applied by neither leaf: O stops declaring the range at the narrow, and the new leaf would start above it. So the hint is capped, per partition, at O's applied frontier: the highest offset f such that O's activation has applied every record of its range at or below f. That is O's in-memory frontier, not its persisted checkpoint. A hot leaf's persisted checkpoint can sit at -1, and capping at it turns every switch into a full-log replay and a tree-wide block pin. The frontier is:

  • set by the activation's replay barrier to the head the barrier replayed to, minus one, once that replay completes. An offset is assigned only at admission, so every record below the head read at that moment is already admitted;
  • advanced by later replay, and by the live advance only when armed (ReadPositionHonest);
  • never raised by an own append applied in memory. Taking the highest applied offset instead would skip a foreign record between the frontier and that append.

O's frontier is read no later than the copy of O's rows that the switch hands to the new leaf, so that the copy holds every record at or below it. A frontier read after the copy could exceed it. If O's activation has no frontier, because its replay barrier has not completed, no hint is applied, and the switch takes 10.2.0's path. The cap's offsets are inclusive and start at 0, so -1 (or an absent value), and never 0, means "none applied". A hint of 0 means record 0 is applied.

The units matter, because the two are stated differently:

  • In checkpoint terms (production): a leaf's checkpoint is inclusive, and it replays the offsets above it, while a captured head is exclusive, the next offset to assign. So a head becomes a birth checkpoint as head - 1 (stamping the head verbatim skips the record at exactly that offset, #5760), and the cap is min(head - 1, frontier of O). Adding one to O's frontier would skip exactly the first record O never applied.
  • In head terms (the WalBulkSwitch model): a head is exclusive, the next offset to assign, and the born leaf's read position is the hint minus one. The same cap is min(heads, rpO + 1), where rpO is the last offset O replayed. It is O's in-memory frontier: ReplayO advances it, and the same step adds the record to the rows that the copy hands back. The model does not persist it.

A lower hint is never above an unapplied record; it only lengthens the new leaf's replay, and with the live advance O's frontier sits near the head.

The hint survives a crash (S7). The hint is written to the shard root's _lattice_shard-handoff row, keyed by the bulk operation id, in the serial turn that captures it and before any leaf is created. A crash between the capture and the switch resumes the same operation id with deterministic leaf ids, and the resume reuses the stored hint; a later one would skip the window the hint exists to cover. PendingBulkGraft stays in ShardRootState unchanged. The hint row is deleted when the switch's token closes.

Deferred, batched close (#5702). A bulk append no longer closes its own bulk:{op} token. A shard's completed bulk tokens (open, not the current operation's, not a pending graft's) are closed together by one routing-generation fence and one marker write: when eight have accumulated (folded into the next chunk's open write), after five seconds with no chunk (a grain timer), or by a bulk load, which still closes at its end. A fresh shard-root activation folds any stale tokens into its first chunk, which also closes an abandoned switch. The open tokens hold the leaves they cover on the replay-based advance for longer, which is safe, only slower. The token and range interface is unchanged.

Existing rows: relocate, never refuse (#5610). Today a bulk append grafts its leaves without checking the keys the rightmost leaf already holds, so a point write into the bulk range between chunks becomes unroutable. #5614's inflated counts are probably the same graft. In the same serial shard-root turn that captures the hint, the graft finds the rows the bulk range already holds and relocates them into the new bulk leaf at its birth, exactly as a split relocates its moved rows, narrowing the old leaf. It never refuses the chunk: a chunk that succeeds today keeps succeeding. Skipping the relocation fails (ReadPositionHonestBulkAppendDropsExistingRows).

Narrow and link in one persist (#5654). The graft narrows the old rightmost leaf's high bound and links it to the first appended leaf in one persist (NarrowHighKeyAsync(highKeyExclusive, nextSibling)). Narrowing first and linking later leaves a window in which the old leaf declares a narrower range but has no NextSibling, because it was the shard's rightmost leaf. A point or batch write at or above the new bound that still routes to the old leaf, the #5610 shape, then finds no forward target in span admission (SpanFailOpenReason.NoSibling) and is stored on the old leaf outside its declared range. Once the appended leaves are routable, the key routes to a leaf that does not hold it: the write is acknowledged and its WAL record reaches replicas and views, but the origin misses it until the appended leaf replays. With the bound and the link set together, every key at or above the bound forwards to the appended leaf from the moment the bound narrows. SetNextSiblingAsync stays, as an idempotent re-assertion for a resumed graft. The model's Create relocates the rows and re-points the owner in one step, so it has no such window; the bulk member's detector, a write interleaved between narrow and link that must be readable on the origin with the span fail-open counter at 0, pins it.

Which value wins (S5): last-writer-wins by HLC stamp; the later-stamped write wins. What 10.2.0 does with a key both a bulk chunk and another write hold:

  • Bulk entries carry real versions. BulkAppendAsync stamps its entries with HybridLogicalClock.Tick (ShardRootGrain.BulkLoad.cs:440, :460, :493), which reads the wall clock (Primitives/HybridLogicalClock.cs:26-39), so a bulk entry is versioned at the time its chunk was stamped, like any write. It is written through MergeEntriesAsync (BPlusLeafGrain.cs:3703), which appends a merge record to the WAL and resolves last-writer-wins by version. A point write is versioned by its leaf's clock (BPlusLeafGrain.cs:687). So on every reader that applies both, the later-stamped write wins.
  • Keys that fill the existing rightmost leaf's free space (ShardRootGrain.BulkLoad.cs:454-465) are merged into the leaf that already holds the other row: the later-stamped value wins, immediately and permanently.
  • Keys placed in new bulk leaves. Replicas and views apply both records and return the later-stamped value. The origin returns the bulk value while the other row is stranded on the old leaf, and flips when a rangeless bulk leaf replays, because it owns every key of its shard during replay (ShardRootGrain.BulkLoad.cs:290).

So 10.2.0 already resolves a contested key last-writer-wins by stamp on every reader except the origin before a replay. The divergence the fix removes is that narrower set: on the origin, a key only the pre-existing rows hold is unreadable, a stranded write stamped later than the bulk entry is hidden behind the bulk value, and the stranded rows are still counted (#5614's duplicates). The relocation makes the origin resolve every key as its replicas and views do: the later-stamped value is returned, keys only the pre-existing rows hold become readable again, and counts and scans become exact. This is a compatible bug fix (change 4): it fixes the origin-versus-replica divergence and needs no authorisation. The model states it as ContestedKeyAgrees: the owner resolves the contested key to the value a WAL reader resolves at the same position. A bulk entry is versioned on the shard root's clock when its chunk is appended, so its order against a concurrent write is arbitrary; the model fixes it between the writes before the bulk began and those after, and the reviewer's runs with every other placement are clean too. ContestedKeyAgreesStrandedValueKept, where the owner keeps a stranded or skipped value over a later-stamped write made before the switch (10.2.0's stranded origin read), fails in seven states.

Re-delivery (#5474, member 3). A run of a chunk below the right edge may be skipped as a re-delivery only when every key it carries at or below the right edge is already held with an identical value and identical metadata (value bytes, TTL, tombstone): nothing the run would write differs from what every reader already resolves. Every other below-edge run is relocated and merged last-writer-wins as above, the later stamp winning; a run is never skipped in part.

Key presence alone cannot tell a re-delivery from a fresh chunk that overwrites existing keys: a refresh that re-imports an updated dataset into a populated tree, an import resumed into a tree that has since taken writes, or a writer that touched every below-edge key of the next chunk. Skipping such a run by presence would write no WAL record, return success, and leave every reader, origin, replicas and views, on the older value, with a held tombstone keeping a re-inserted key deleted. In 10.2.0 the same chunk was filled or grafted with fresh stamps, so replicas and views resolved it to the later bulk value. That would be a replica-visible behaviour change (revision 8's rule, found in the review of member 3's #5646). Under the value-and-metadata rule:

  • a genuine re-delivery with nothing changed since is all-equal, and is skipped;
  • a refresh with new values is merged, and the later stamp wins, as in 10.2.0;
  • a re-delivery after a later overwrite re-stamps the bulk value over it, consistently on every reader, which is what 10.2.0 did on replicas.

A skipped run's visible values are the same everywhere, so skipping cannot make the origin and its replicas disagree. No state and no wire format changes. The model has one bulk entry per key and no re-delivery step, so it does not encode the skip rule; the bulk member's detector does: a point writer holding every below-edge key of the next chunk (the reviewer's widened BulkAppend_after_point_writes_above_the_maximum_keeps_every_key_readable_last_writer_wins) must leave the later-stamped bulk value readable on every reader.

Rejected: a stable "bulk value wins". Dropping the other row on the owner is unsound: replicas and views still apply it at its real version, so origin and replicas would disagree for good. The only replay-consistent form is to stamp the contested bulk entries above every earlier version, with the relocation narrowing the old leaf and reading its clock in one step. That flips every key whose other write is stamped later than the bulk entry, on every reader, from that write's value to the bulk value: a documented-behaviour change on paths where 10.2.0 is already stable. The user may still choose it later; it would need that authorisation. #5610 and #5614 are fixed together in the bulk member, which confirms whether they share a cause. Bulk leaves also get the key ranges PlanBulkLoadLeaves already computes. A rangeless bulk leaf owns every key of its shard during replay, which duplicates sibling bulk leaves' rows into it.

4. Fail safe everywhere, and mixed versions

The fence gate works like the clock floor's gate. Each silo whose build supports the claim, the stamped methods and the markers advertises a marker grain interface, IWalAppendFenceCapable, in its grain manifest. A ClusterManifestWalAppendFenceGate is open only while every active silo advertises it. A member whose manifest has not arrived counts as not capable, so the gate fails closed during a rolling upgrade and opens by itself once the last old silo has left. The precedent is IWalClockFloorCapable and ClusterManifestWalClockFloorGate (#4586). The gate is not ratcheted: if a 10.2.0 silo joins, or rejoins in a rollback, it closes again by itself.

Unstamped appends are always admitted. An append through an existing, unstamped method comes from a 10.2.0 silo, from any silo while its view of the gate is closed, or from a path the census classifies as unstamped. The WAL shard never rejects it. Instead it records the append's offset as the partition's highest unstamped offset, and returns that value in the response of every stamped append. An activation arms only once it has read past every unstamped offset reported to it:

  • An unstamped append allocated before one of the activation's own appends is reported by that append's response.
  • One allocated after the activation's last own append lies above the advance's target, so the advance cannot pass it.

The watermark is in memory. A shard restart sets it to the recovered allocator head minus one, treating everything before the restart as possibly unstamped.

So an unstamped append is never rejected (OldNeverRejected, broken by OldNeverRejectedRejectedOnceFenced) and never skipped (ReadPositionHonestUnstampedNotReported, ReadPositionHonestRestartForgetsUnstamped).

An own unstamped append reports itself (S2). When an activation's view of the gate closes, its own appends go unstamped, and no stamped response reports them. If its view reopens while it is armed, its next advance would cover them. So an activation raises its reported watermark to the offset of each of its own unstamped appends, as if the shard had reported it. Dropping the self-report fails in 13 states (ReadPositionHonestNoSelfReport); the configuration WalLiveAdvanceGateFlip.cfg lets an activation's appends go stamped or unstamped at any time.

Racing the gate (S4). A new silo may call a stamped method on a grain activated on a 10.2.0 silo before its gate has observed that silo join. What a 10.2.0 silo does with an unknown invokable, and what the caller sees, has no precedent: ClusterManifestWalClockFloorGate is consulted locally by the WAL shard and never calls a new method on an older silo. So:

  • Member 1 pins the failure with a mixed-version test (a 10.2.0 silo's grain receiving the new method), and records the exact exception type and shape.
  • The caller re-issues the write through the unstamped method only on that definite "method unknown" failure, and closes its own view of the gate.
  • Any other failure, above all a timeout, is ambiguous (the append may have been allocated) and follows today's retry semantics unchanged.

The leaf takes the replay-based advance on a partition whenever it cannot prove exclusive authorship:

  • Its own claim. No claim yet on the partition, or the claim failed, conflicted or was refused.
  • Replay. It has not replayed to the claim head, to the last close's heads, or past the highest unstamped offset reported to it or appended by it.
  • Hand-offs. Its marker state is not initialised; a leaf marker is open; or the shard-level marker read has an open range overlapping the leaf, failed, or is not fresh.
  • Its own writes. An own append is unapplied, or an own append failed (the tracker is off for the activation).
  • Sagas. A saga prepare is pending.
  • Partition state. The partition is latched stale.
  • Overlap cannot be excluded. Another live leaf may own the same keys:
    • ShardIndex is null (a slot-less legacy leaf owns every shard's entries in replay);
    • the leaf is rangeless but has siblings (a legacy bulk leaf: "Bulk-load leaves carry no ownership range");
    • the leaf is suspected to be an orphan: orphan repair is pending for it, or it is not reachable by descent. An orphan sharing a live leaf's bounds materialises a full copy of that leaf's range. The descent check is the orphan signal, and it subsumes a scan-chain flag: an orphan that shares a live leaf's bounds is never the leaf descent reaches (#5704, #5709).
  • Storage. The grain storage provider does not enforce ETags (GrainStorageFencingProbe reports so). The claim's conditional writes prove nothing without them.
  • Rollout. The fence gate is closed. Nothing claims, the shards keep no entries, and every advance is replay-based.

An unreachable leaf never stamps (#5709). The overlap rule above holds the orphan's advance. The reverse direction needs its own rule. An unreachable orphan O can share bounds with a reachable leaf L, and it is still doubly linked into the sibling chain, so a span forward from its predecessor, or a stale route, can deliver a write for L's keys into O. O's append of it would be stamped with O's own epoch under O's own entry, so no fence rejects it, and L's live advance would pass it unread: the record reaches replicas and views, but reads through L never see it. Orphan repair cannot be relied on to close this. It runs only when an operator invokes it, and it clears an orphan only after proving, key by key, that every row the orphan holds is readable from the reachable owner; otherwise it refuses and leaves the orphan untouched. It never folds rows into L. So the rule is at the source:

  1. Claim-time reachability. Before an activation's first claim of its append epoch, the leaf proves it is reachable by descent, with the same interleaving shard-root check the live-advance view makes, once per activation. An unreachable leaf does not claim, and appends through the unstamped WAL method, as with a closed gate view. An unstamped append is always reported and raises the partition's unstamped watermark, so any leaf sharing the partition replays past it before it arms, and L's replay applies O's record by key range. That covers an orphan anywhere in the chain, with no persisted audit result.
  2. Born under an open hand-off marker. A split sibling claims eagerly at its birth, before its parent learns of it, and is legitimately unreachable until then. It keeps its claim: it admits only keys the donor has already narrowed away, because the donor forwards a key only once it is outside the donor's span.
  3. Tick re-check. If an advance tick's descent finds the leaf unreachable while no marker is open on it, the leaf stops stamping for the rest of the activation.

Losing reachability after the claim is covered without the tick. A leaf that proved itself reachable and claimed can leave descent only through a topology change, and each correct one fences it independently of the re-check:

  • Leaf reclaim. The absorbed neighbour's entry is retired under the epoch floor in the retire step, before it is unlinked, so every stamped append it makes afterwards is refused at the WAL (section 1, "Retiring entries"); its writes re-route through the survivor, whose marker is open while its range widens.
  • Split. The donor stays reachable. The leaf that is unreachable is the sibling, from its birth until its parent learns of it, and it is born under the split's open marker, which holds every owner the split reaches until the donor's fence closes it; an interrupted split's resume re-opens the marker first (rule 1). Unlinking it again requires a reclaim, above.

So the tick's re-check guards only a defect that unlinks a claimed leaf outside these paths, and the window between such a defect and the next tick is the residue. In the model an orphan's append is OldAlloc (unstamped, reported), and dropping the report is ReadPositionHonestUnstampedNotReported, the same counterexample.

5. Rejections are retried where they are raised

A stale-epoch or fence rejection is not a fault that repeats by itself. A re-issued write is admitted under the current epoch and generation, and only another claim or another close can reject it again. Both are finite within any interval: a claim needs a new activation, and a close needs a hand-off. So the design retries a rejection at the seam that raised it, for as long as the operation's existing deadline allows (its cancellation token, or the response timeout of the call that carries it), not for a fixed number of attempts. When that deadline expires, the caller receives exactly what it receives today when the deadline expires. Nothing new is surfaced: the fence's outcomes and the LeafRetiredException that carries a supersession are internal, never cross a public API boundary, and are never an inner exception of anything public.

Convergence: each retry either succeeds or meets a claim or close that happened after its admission. Under unbounded claim or close churn on one key, the retry runs to the deadline, which is the same outcome as today's timeout under unbounded churn. In the model a retried foreign write is a fresh ForeignAdmit under the current epoch, and a stale activation's retry is the live activation's own append.

Every caller of the leaf write surface, and where its retry runs:

Caller Exposure without the seam retry Seam retry
LatticeGrain writes through ShardActivationRetry (34 call sites) None; the envelope already retries transient faults, but only 3 times The rejection is retried below the envelope, at the shard root's leaf-call step, until the deadline; the envelope never sees it
DeleteAsync, single-key ApplyCrdtDeltaAsync (RunMutationAsync, RetryOnStaleRoutingAsync) The internal exception would reach the caller Same leaf-call step; a stale generation re-routes through the existing stale-routing path
Saga prepares (AtomicWriteGrain, cross-tree transactions) A rejected prepare becomes a nack, and the saga rolls back with InvalidOperationException where 10.2.0 commits The participant retries the prepare under its current stamp until the prepare's deadline; a fence rejection is never a nack
Replication apply (DeadLetterTrackingReplicationApplier.ApplyTrackedAsync) Counted toward the dead-letter budget, a failed peer contact recorded Retried below the applier, so a rejection never reaches its accounting
Views, tag index, resize mirror, backup restore, schema remediation A transient failure in their own retry loops Same leaf-call step; their loops see success or today's deadline outcome
Leaf-to-leaf paths (relocation, prepared-key re-routing, split transfers), shadow forwards, the adaptive split drain, bulk seeding A failed hand-off step, re-driven by recovery The initiating step retries under its current stamp; recovery is unchanged
A leaf's own appends (compaction reap, replayed terminals) A failed internal append A stale activation stops (it is superseded); the live activation redoes the work

Where each kind of rejection is retried (S1):

  • A stale leaf epoch. The rejected activation deactivates, and the retry is a fresh call to the same grain id, which reaches the live activation. A leaf-epoch rejection at a split close is retried at the leaf, whose span admission forwards a key the split moved.
  • A stale shard routing generation (an adaptive split, a fold or a bulk switch closed). This is always retried from the shard root, never re-stamped at the leaf. The retry re-runs ThrowIfRejectedForKey, which raises StaleShardRoutingException for a slot that moved to another shard, and the existing stale-routing retry sends it there; otherwise it re-admits under the current generation. A leaf that re-stamped the write would append it on the old shard, where the shard map gives it to no leaf, while the new owner's marker is already closed: acknowledged data never applied.
  • A stale tree range-delete generation. Retried by the shard root's walk step, as under "A walk outliving its intent" in section 2.