0202. Dedupe returns the original verdict; refused batches set a retry floor
Status: Accepted (2026-11-27). Refines the dedupe part of 0019. Agreed with WP-D (sync client) and WP-C (HTTP op forwarding, 0303). Refined by 0204: the floor is held at the gateway, the floor batch travels alone (probe) and later batches wait until it is answered; retryAfterMs is server-driven and exponential.
Context
Clients resend unacked batches after a reconnect, with the original clientSeq. ADR 0019 says a duplicate returns the original ACK and the owner reads max(client_seq) from the journal on resume. Three cases remained open:
- Verdicts are not journaled.
- Fully rejected batches (seq 0) have no journal row.
- A batch refused with
busy or rate_limited, followed by later batches already on the wire, could let k + 1 commit before k. Accepting k afterwards would break per-client order (LWW divergence: the author applied k before k + 1) and max(client_seq) dedupe.
Decision
- Processed = deduped. Per (page, clientId) the owner keeps the highest clientSeq it processed, including fully rejected and still-committing batches. A batch at or below it is a duplicate. It is answered with its original verdict and never validated or sequenced again.
- Committing: the duplicate’s socket also gets the ACK when the commit lands.
- Committed while the server stays up: the cached ACK bytes, exact. The last 128 per client per room are kept, which covers
MAX_INFLIGHT_BATCHES.
- After a restart:
subscribe{pendingFromClientSeq} makes the owner read that client’s journal rows from that clientSeq on (one indexed query, before subscribed is sent) and max(client_seq).
- Resend with a row: ACK with the row’s seq. Rejected ops are rebuilt by matching the resent op bytes against the journaled accepted ops, which are a byte-identical subsequence. A rebuilt reason is the stateless verdict, else
NODE_MISSING.
- Resend at or below max with no row: ACK seq 0 with every op rejected (that is what it was the first time).
- Retry floor. After
busy (owner, per clientId and file) or rate_limited (gateway, per connection) for clientSeq j, every batch with clientSeq > j gets the same error until j arrives again. Clients resend j and everything after it in order. protocol_error (a malformed frame) sets no floor: resending it cannot help.
- Ordering guarantees (tested in apps/realtime/test):
- Per room and connection, ACK and BROADCAST go out in commit order: ascending seq, ACKs in clientSeq order. The author gets ACK S instead of BROADCAST S.
- A tail streams stored BROADCAST frames, the client’s own included, before
synced.
- The only exception to ascending order is a dedupe ACK, which carries its original, older seq.
- Commit conflicts. A unique violation (another writer advanced the page) resets the affected rooms: head re-read, index and ring dropped. Their uncommitted batches answer
busy, and each client’s processed mark rolls back to just below its first dropped batch.
Alternatives
- Re-validate a duplicate that was fully rejected: could sequence k after k + 1 against the author’s local order.
- Journal verdicts: needs a schema change (
page_ops is a contract) and costs bytes on every row for a rare path.
- No floor (clients must not pipeline): halves throughput for agents and HTTP forwarding, and breaks under the gateway’s own rate limits.
Consequences
Exactly one journal row per (page, clientId, clientSeq), tested with a SIGKILL during a pending commit. Clients must send pendingFromClientSeq when they resubscribe with unacked batches; without it a restart cannot detect resends of batches whose ACK was lost.