Table of Contents

Saturation back-pressure - LatticeSaturatedException

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 saturation-back-pressure-latticesaturatedexception.md, and llms.txt lists every page.

Part of Lattice Public API Reference.

Public typed exception thrown when an operation is refused because the tree's storage layer is back-pressured - most commonly by the WAL writer admission gate and the atomic-write saga coordinator, when the per-tree IWalSaturationSignal reported WalSaturationState.Saturated for longer than the caller's configured wait budget. Distinct from LatticeShuttingDownException: saturation is a recoverable steady-state regime (offered load is exceeding the storage layer's sustained drain rate), not a one-way silo shutdown. Seven seams raise it - the WAL writer admission gate, the atomic-write saga coordinator, the snapshot-cursor open path, the per-silo replay-permit admission gate, the SetManyAsync shard fan-out, the SetManyAsync whole-call envelope, and the transaction-registry row-size admission bound - and the SaturationSource property names which one, because their triggers and their safe recovery differ. The typed slot lets callers that care about the saturation regime explicitly distinguish it from genuine InvalidOperationException failures. It derives from InvalidOperationException for backwards compatibility, but that inheritance is a hazard rather than a convenience, and this exception is the worked example: a broad catch (InvalidOperationException) elsewhere in the routing layer once absorbed this back-pressure signal, discarded the whole routing cache and re-fanned-out every shard, amplifying load on a tree that was already saturated in proportion to the shard count. The type implements ILatticeDomainFault, so a broad handler declines it with catch (InvalidOperationException ex) when (ex is not ILatticeDomainFault); catching it by name and backing off remains the correct handling.

Surfaces from seven distinct saturation failure shapes that share the same operational meaning ("this tree's storage layer is back-pressured; the operation was refused"):

  • Writer-side admission refusal. The WAL commit-log writer consults the saturation verdict for the target partition before each per-partition admission acquire. On Saturated, the writer waits up to LatticeOptions.WalAdmissionSaturationWaitBudget (default 5 seconds) for that partition to leave Saturated (to return to Healthy when WalSaturationAcuteOnly = false) and, if the regime persists, throws this exception so callers observe the back-pressure in budget time instead of parking on the admission semaphore for up to WalAppendDispatchTimeout (default 30 seconds). Reported as LatticeSaturationSource.WalAdmission.

    The gate is additionally bounded per top-level call by LatticeOptions.WalAdmissionSaturationCallBudget. The per-append budget bounds one wait; it does not bound a call, because the write path holds three nested retry layers (the stale-routing retry, the shard-activation retry, and the per-leaf batch-dispatch retry) and each re-dispatch opened a fresh one, so a single call could accumulate a multiple of the configured budget while every individual wait stayed correctly bounded. The gate now takes the smaller of the call's remaining allowance and the per-append budget, and refuses without waiting once the allowance is spent. It defaults to 15 seconds from Orleans.Lattice 10.0 (#3390); set Timeout.InfiniteTimeSpan to leave only the per-append budget in force, in which case the multiplication measured in #3348 is unmitigated.

  • Saga-coordinator quiesce refusal. The atomic-write saga's quiesce-on-saturated preflight runs before each batched dispatch and parks the saga on WaitForHealthyAsync up to the lesser of a fixed 30-second saga quiesce cap and the tree's WalAppendDispatchTimeout. On budget expiry with the tree still Saturated, the saga's fast-path refuses with this exception rather than re-dispatching the same RowKeys into a still-throttled storage account (the canonical 409-Conflict amplification regime); the saga's persisted state stays at Execute with the current NextIndex so the caller's next retry on the same operationId resumes from where the refusal stopped. The preflight looks the signal up under the tree id the saga addressed, so on an aliased tree it reads Healthy and does not engage (see Resolution and scope). Reported as LatticeSaturationSource.AtomicWriteSaga.

  • Snapshot-cursor open shed. Opening a snapshot cursor is expensive, so an open whose starting position routes to a WAL partition that already reads Saturated is shed immediately - before routing resolution and the capture fan-out - rather than amplifying its own collapse. Unlike the two gates above there is no wait budget: the shed is immediate. Only Saturated sheds, so a Throttled tree stays browsable, and a saturated sibling partition does not shed an open whose own partition is not saturated (#3395). Gated by the default-on ShedSnapshotOpensWhenSaturated option. Like the saga preflight, the shed looks the signal up under the tree id the open addressed, so it does not engage on an aliased tree (see Resolution and scope). Reported as LatticeSaturationSource.SnapshotCursorOpen.

  • Replay-permit admission refusal. The per-silo WAL replay-permit gate refuses an activation when a non-empty queue has a fresh smoothed wait at or above LatticeOptions.WalReplayPermitMaxQueueWait, independently of depth, or when the queue is at or above its circulating-permit depth bound and no queued activation has acquired a permit for that long (tagged no_progress when no permit holder has read a WAL slice in that time either, holders_slow when one has). Empty queues and stale means do not trigger the time-based arm. Setting either admission option to zero disables these refusals. A refused Interactive replay keeps its gate position while its callers are refused (issue #6006): the caller still receives this exception at once, and a retry while the replay is parked is refused at once too. This seam does not consult IWalSaturationSignal: it is driven by replay-permit wait and depth evidence, so it can fire on a tree whose signal reads Healthy. Reported as LatticeSaturationSource.ReplayPermitAdmission. Background starvation drives - the WAL GC sweep's blocked-leaf drives and a leaf's own coverage-lag timer drives - are refused under the same source when the gate's share for them has no free permit: they never queue, they share at most half the replay permits still in circulation (the resolved ceiling less every permit the memory, service-rate or storage-pressure back-pressure is withholding; at least one), and while that share holds more than one slot a timer drive never takes its last free slot, which is kept for WAL GC sweep drives (a single-slot share is shared, and the timer yields it while a refused sweep drive is outstanding). Those refusals stay inside the silo (the sweep records an admission_refused outcome and the refused leaf backs off) and never reach an ILattice caller.

  • Batch fan-out budget expiry. SetManyAsync splits a batch across the shards its keys route to and awaits every branch. A batch therefore pays its slowest branch, so as the shard count rises the call tracks the branch p99 rather than the branch median - the collapse measured in #3348, where widening from four silos to eight improved the branch median 7.7x to 386 ms while the branch p99 degraded 11x to 94 s. The fan-out can now be bounded by LatticeOptions.SetManyFanOutBudget, which defaults to 30 seconds from Orleans.Lattice 10.0 (Timeout.InfiniteTimeSpan disables it): once the budget expires with branches still outstanding, the call is refused with this exception - whose message names the shard branches still outstanding - instead of blocking indefinitely, which is what makes the fan-out shed load rather than queue it. Like the other seams this reports back-pressure to the caller only - it is not a rollback. SetManyAsync is not atomic across shards, so branches that already committed stay committed and outstanding branches run to completion; only the moment the caller is told changes. Reported as LatticeSaturationSource.SetManyFanOut.

  • Batch envelope budget expiry. The fan-out budget above bounds one stage. SetManyAsync runs four in sequence - gate (registering the tree's compaction reminder and arming its autonomic loops), route, bucket, fanout - and a call can breach the caller's deadline by summing them while no single stage breaches. #2685 measured exactly that: a gate of 4,108.96 ms (12,085x its 0.34 ms healthy baseline, an uncached arming path running on every write) plus a fanout of 26,709.17 ms, totalling 30,818 ms against a 30,000 ms Orleans response timeout. A fan-out budget never fires at 26.7 s, so the caller received an anonymous TimeoutException naming no stage. LatticeOptions.SetManyEnvelopeBudget bounds the running total instead, defaults to Timeout.InfiniteTimeSpan so the bound is opt-in, composes with the fan-out budget (the fan-out waits for the narrower of the two), and also bounds single-shard batches, which the fan-out budget deliberately skips. The refusal carries a per-stage breakdown, so the next occurrence names the stage that moved rather than the stage that is largest. Like the other seams it is not a rollback: already-committed branches stay committed and outstanding ones run to completion. Reported as LatticeSaturationSource.SetManyEnvelope.

  • Transaction-registry capacity refusal. Each shard of a tree's transaction registry (TxRegistryShardCount, default 1) persists its whole state as one grain-state row, and each completed saga leaves a tombstone in its shard's row for TxDecisionRetention. Before a new atomic-write saga does any work, its shard estimates its row size and refuses the saga when that estimate is at or above LatticeOptions.TxRegistryAdmissionBudgetBytes (default 768 KiB) even after purging expired tombstones. This keeps the row under the storage provider's per-row limit. In-flight sagas, status reads and recovery are never refused. A refused saga discards the transaction id it drew, so a retry mints a fresh id and, when TxRegistryShardCount is above 1, may land on a shard with room; a single shard's capacity returns only as its tombstones age out, so on an unsharded tree back off for seconds, not milliseconds. A single-tree write is never retried by the library. A cross-tree write has already recorded its preparing phase and armed its one-minute keepalive reminder before it dispatches the sub-sagas, so the caller still receives the refusal, but the keepalive re-dispatches the prepare phase about once a minute until the sub-sagas are admitted, and a retry with the same operationId re-attaches to that saga. Reported as LatticeSaturationSource.TxRegistryCapacity (#3475).

Carries the originating tree id in the TreeId property so caller-side diagnostics can attribute the back-pressure to the specific tree without parsing the exception message. When the writer-side admission gate refused, the property names the tree whose admission semaphore observed the saturation; when the saga refused, the property names the saga's tree (or, when an underlying writer-side LatticeSaturatedException was wrapped through SetManyAsync's leaf fan-out, the extracted tree id of the writer-side refusal).

Also carries SaturationSource, a LatticeSaturationSource value naming which of the seven seams refused, or Unspecified when the refusal was not attributed - an exception built through a constructor that takes no source, or deserialised from a host that predates source attribution - which a handler should treat as not automatically retryable. Because the seams differ in what is safe to do next, a handler that retries must branch on this property rather than on the exception type alone.

Caller contract: treat as back-pressure and retry after backing off. Typical recovery is 1-10 seconds (until the underlying storage account or per-partition WAL admission gate drains). Long-lived consumers should also reduce offered load on the affected tree until the per-tree signal returns to Healthy. Unlike LatticeShuttingDownException, retries against the same silo activation can succeed once the regime clears.

Part of that contract is now honoured inside the library. The shard-dispatch envelope retries a ReplayPermitAdmission refusal on a jittered 2 s / 4 s ladder, so a refused leaf activation is shed and re-attempted instead of failing the caller (#3294). It retries only that member: re-attempting a WalAdmission refusal at that seam would re-issue the batch across every shard of an already-saturated tree, the amplification #3348 removed one layer above. That is why the discriminator is load-bearing rather than diagnostic decoration. Note the retry does not suppress orleans.lattice.leaf.activation.failures{reason=refused_replay_admission}: the activation still fails and is still counted, and the dispatch envelope recovers above it.

Partial admission of a batch (#5970). SetManyAsync is not atomic, so a refusal can leave part of a batch applied. A refused batch now says which part. UnappliedKeys on the refusal is a superset of the batch's keys that may not have landed, each listed once, so a caller can retry only those keys rather than the whole batch. The shard-dispatch retry above uses the list in the same way: within its attempts it re-sends only the keys the refused attempt listed, so leaves that already landed are not rewritten. Retrying the whole batch remains correct.

The list is a superset on every path:

  • At the shard. A leaf that returned success applied its whole slice, and every key of a refused leaf is listed. So a key is left out only when its leaf returned success.
  • Across shards. The list is taken when the first refusal surfaces, without waiting for any other branch. A shard that returned success is left out. A refused shard contributes the keys it listed, or its whole bucket if it listed none. A shard still in flight contributes its whole bucket, and so does every shard when the fan-out or envelope budget runs out.
  • Events. The Set events of the keys left out are published before the refusal reaches the caller, since a caller retrying only the listed keys never re-sends them. They persisted, so a subscriber still only sees a Set for a key that persisted. A caller that retries the whole batch writes those keys again and publishes a second Set for each of them (see Events).
  • Branches still in flight. As before, a branch still in flight when the refusal surfaced is not cancelled, so its writes can land after the caller's retry and win over it. If the order of two writes to a key matters, re-read the key after the retry rather than assuming the retry's value stands.

UnappliedKeys is null, meaning unknown and retry the whole batch, when the outcome cannot be attributed key by key:

  • any branch faulted with anything other than a saturation refusal, or was cancelled;
  • a shard had an adaptive split in progress, slots moved away, or an online-resize mirror, because a key that landed still owes its forward there;
  • the batch was an atomic-write saga's prepared dispatch;
  • a host in the path predates the property;
  • the list would exceed LatticeSaturatedException.MaxUnappliedKeys (16,384) keys or MaxUnappliedKeyChars (1,048,576) characters.

A list is never truncated, because a truncated list would not be a superset. Keys never appear in the exception's message or string form, which give only the count. The gRPC, MCP and API facades do not yet map the list.

static async Task SetAllAsync(ILattice tree, List<KeyValuePair<string, byte[]>> batch)
{
    var pending = batch;
    while (true)
    {
        try
        {
            await tree.SetManyAsync(pending);
            return;
        }
        catch (LatticeSaturatedException refused)
        {
            if (refused.UnappliedKeys is { } unapplied)
            {
                var retry = new HashSet<string>(unapplied, StringComparer.Ordinal);
                pending = pending.FindAll(entry => retry.Contains(entry.Key));
            }

            await Task.Delay(TimeSpan.FromSeconds(2));
        }
    }
}
var entries = new List<KeyValuePair<string, byte[]>>
{
    new("k1", new byte[] { 0x01 }),
    new("k2", new byte[] { 0x02 }),
};

try
{
    await lattice.SetManyAsync(entries);
}
catch (LatticeSaturatedException ex)
{
    // The per-tree saturation signal stayed Saturated past the
    // admission budget. The entries did not commit. Back off
    // (typical 1-10s), then retry. The TreeId property attributes
    // the back-pressure to the specific tree.
    Console.WriteLine($"tree {ex.TreeId} is saturated; backing off");
    await Task.Delay(TimeSpan.FromSeconds(2));
    // retry...
}

The writer-side admission refusal is also recorded on the orleans.lattice.wal.writer.append.admission_saturation_refusals counter (tagged tree, partition) so operators can dashboard the back-pressure rate separately from the dispatch-timeout counter (orleans.lattice.wal.writer.append.admission_timeouts) and the drain-release counter (orleans.lattice.wal.writer.append.drain.releases). Every refusal from any of the seven seams is also counted on orleans.lattice.saturation.refusals, tagged tree, source (the snake_case SaturationSource, for example wal_admission or set_many_fan_out) and tenant, together with a background starvation drive's refused replay permit, which the library absorbs rather than throws - so a refusal rate can be attributed to the seam that raised it. A replay_permit_admission refusal also carries an arm tag naming the predicate that refused (wait_exceeded, no_progress, holders_slow, or gc_share), and the tree value is the id held at the refusing seam, so on an aliased tree a wal_admission or replay_permit_admission refusal is counted under the physical copy's id. Each refusing seam records its own refusal, so the count is not one per caller-visible exception: a refusal raised by a write inside an atomic-write saga (a wal_admission refusal, for example) is counted under its own source and again under atomic_write_saga, and a saga refusal because its own quiesce budget elapsed is counted twice under atomic_write_saga. See Metrics.