Linora

0410. Sync settlement: rebase on every removed op, retire older batches, stale dedupe verdicts

Status: Accepted (2026-11-28, DC2). Refines 0401; relies on the ordering in 0202.

Context

On HEAD (wave 2), the convergence sim had extra server rejections on 10 of 1,000 seeds and one real divergence (seed 181: a replica ended with a stale fill). The 0401 follow-up called the residue “rare undo/restore interleavings”. There were three causes:

  1. Reverts captured over values that later stopped being canonical. A plain SET has no revert, but a later pending DELETE’s RESTORE block copies the node with the SET’s value. Settling the SET without a rebase (it was rejected, or already contained in the snapshot a reload rebuilt from) left that stale value in the block. The next rebase restored it.
  2. Older batches re-applied after their ACK was lost. A reload re-applies every in-flight batch on the fresh snapshot, including ones the server had already sequenced inside it. Later ops were then predicted over a doubly applied state.
  3. Dedupe ACKs of all-rejected batches carry a verdict from an earlier server state. No broadcast places such a batch, so the client compared the verdict with its current state.

Decision

  1. Settling removes ops only through a full rebase. When any op the replica shows is rejected, or turns out to be already in the base snapshot (seq <= baseSeq), the session rebases. Every revert is then recaptured from canonical values. If an out-of-order ACK leaves an accepted key overridden while pending reverts exist, the page reloads.
  2. Retire older batches. A client’s batches reach the server in clientSeq order, and the server never processes a clientSeq below the highest it processed (0202). So when batch j settles (ACK or own broadcast in a tail), every older batch still in flight was processed before it and lost its ACK with a connection. Anything it accepted is already canonical, because it would otherwise have come earlier in the tail. Such batches are dropped (with a rebase), and their commits resolve with the rejections that were predicted. This also ends hangs when the dedupe cache no longer holds an ACK.
  3. Stale verdicts are counted apart. Each pending op records every prediction made since its batch was first sent. A rejection on a possible dedupe ACK is a stale verdict (stats.staleVerdicts) rather than an extra rejection when:
    • the batch was sent before the current subscription, and
    • the client predicted that verdict at some point in the window, or a reload skipped part of the window (no states were observed there). It is rolled back like any rejection, and the final state equals the no-disconnect case.
  4. Bulk ops (ADR 0103), within the same model:
    • pending TRANSFORM / SET_GEOMETRY ops apply alone with their exact SET_GEOMETRY revert;
    • a remote batch with a bulk op, or a remote geometry SET on a node one of ours lists, triggers a rebase;
    • a SET’s shadow under a pending bulk op comes from that op’s revert;
    • an ACK settles each key by replaying the batch’s accepted writes in op order (absolute SETs and creates, relative TRANSFORM, absolute SET_GEOMETRY);
    • direct value fixes skip nodes that a later pending bulk op moves.
  5. Busy / rate_limited for j resends only j after retryAfterMs; j+1.. follow j’s ACK. Resending the whole tail multiplied server work under overload (R1’s load test).

Alternatives

Consequences