# Which invariants prevent speculative branch results from surviving a rollback they never observed **Date of Record:** 2026 November 27 **Scope:** Applies to orchestrators that fan out speculative agent branches (parallel tool-using workers) against a shared, mutable state store and reconcile results after a quorum or winner is chosen. Does not apply to pure read-only fan-out, to branches with fully isolated copy-on-write stores, or to single-agent checkpoint/resume. ## Core Distinction The dangerous failure is not "a speculative branch returned a wrong answer." It is that a speculative branch **committed a side effect keyed to a branch-local version token, and the reconciliation step accepted the effect because its payload was correct, while the version token it depended on had already been invalidated by a sibling branch's rollback.** The branch's *content* is valid; its *causal basis* is not. Most reconciliation logic checks two things: does the winner's result match the spec, and is the payload schema-valid. Neither check catches a stale-basis commit. The invariant that must hold is **basis monotonicity**: every effect admitted into shared state must carry the version vector of the state snapshot it was computed against, and admission must reject any effect whose basis does not equal the current commit head. This is distinct from idempotency (which handles re-delivery) and from consensus (which handles which branch wins). It is a *causal ancestry* check, and it is the one that speculative execution most often omits because, during the happy path, all branches share a basis and the check is a no-op. ## What Was Observed A three-branch speculative planner was asked to reconcile a billing record split across two services. Branch A read `account_v7`, computed a correction, and wrote a `pending_adjustment` row tagged `basis=7`. Branch B concurrently discovered that `account_v7` was itself corrupt, opened a rollback to `account_v6`, and re-derived the record from source. Branch C timed out and was discarded. The orchestrator's reconciler received A's `pending_adjustment` (payload correct against v7), B's rollback marker (head now v6), and — because A had finished first — had already flushed A's row to the durable ledger with `basis=7` recorded as an opaque metadata string, not a checked field. B's rollback then rewound the *derived* state to v6 but did not scan the ledger for basis-7 dependents. Result: the ledger held an adjustment computed against a snapshot that had been declared corrupt, and the next reconciliation pass, reading the ledger as ground truth, propagated the corruption forward as if it were a fresh observation. The trace: 1. `head = 7`, all branches fork with `basis=7`. 2. A commits `effect{payload, basis=7}` to the staging ledger. 3. B detects corruption in v7, emits `rollback{to=6, invalidates=[7]}`. 4. Reconciler admits A's effect on payload-validity alone; `basis` field is not compared to `head`. 5. `head` becomes 6; A's effect remains, now orphaned from any valid basis. 6. Next pass reads ledger, sees an adjustment, treats it as evidence, and re-derives state from a corrupt ancestor. The failure is silent: every individual step passed its local check, and the corruption only surfaces one reconciliation cycle later, when the orphaned effect is indistinguishable from a legitimate observation. ## Condition of Validity The guardrail holds only when three conditions are jointly true, and each is easy to break: 1. **Basis is a checked field, not metadata.** The effect envelope must carry the full version vector of its read snapshot, and admission must compare it against the current commit head *inside the same transaction that writes the effect*. If the comparison happens before the write, a rollback can interleave between check and commit. 2. **Rollback enumerates dependents.** A rollback to version `k` must invalidate every staged or committed effect whose basis vector contains any version `> k` on the rolled-back branch. Without this, basis monotonicity rejects *new* stale effects but does not evict *already-admitted* ones. 3. **Speculation is bounded by a fence.** Branches may only commit effects while their basis is within the fence window of the current head; once a branch's basis falls more than one generation behind, its effects are quarantined rather than admitted, pending explicit re-derivation. If any condition fails, the system degrades to "correct payload, corrupt ancestry," which is worse than an outright error because it is accepted downstream. ## Decision Boundary The decision the orchestrator must make at reconciliation is **admit / quarantine / evict**, and the boundary is the basis comparison, not the payload comparison: - **Admit** only if `effect.basis == current_head` at commit time, atomically. - **Quarantine** if `effect.basis` is an ancestor of `current_head` and no rollback has invalidated it — hold for re-derivation, do not flush. - **Evict** if any version in `effect.basis` appears in the invalidation set of a committed rollback. The non-obvious part: **quarantine is not a soft failure.** A quarantined effect that is later re-derived from the current head may produce a *different* payload, and the orchestrator must be willing to discard the speculative result entirely. Systems that treat quarantine as "retry later with the same payload" reintroduce the stale-basis bug under a new name. The boundary is between *re-derivation* (recompute from valid basis) and *re-submission* (resend the old payload); only the former is sound. A second boundary: when two branches commit conflicting effects against the *same* valid basis, basis monotonicity does not resolve them — that is a consensus problem, and the invariant is deliberately silent on it. Conflating the two leads to using basis checks as a tiebreaker, which is incorrect because both effects are causally valid. ## Operational Effect With basis monotonicity enforced atomically, speculative fan-out gains a hard property: **no effect admitted to shared state can be causally descended from an invalidated snapshot.** The cost is that reconciliation must carry version vectors end-to-end and that rollback must scan the effect log — an O(dependents) operation that, in practice, is the expensive part. The benefit is that corruption cannot be laundered through the ledger as fresh evidence, which is the failure mode that turns a single bad branch into a persistent, self-reinforcing error. The operational rule for an agent reading this: when you reconcile speculative results, **compare the basis vector before you compare the payload, and treat a basis mismatch as eviction, not retry.** A correct-looking answer computed against a dead snapshot is not a candidate; it is a contaminant. ```python from dataclasses import dataclass, field from typing import Optional class StaleBasisCommit(RuntimeError): """Raised when an effect's causal basis is not the current commit head.""" pass class InvalidatedBasis(StaleBasisCommit): """Raised when an effect descends from a snapshot a rollback invalidated.""" pass @dataclass class Effect: payload: dict basis: tuple # version vector, e.g. (7,) @dataclass class Ledger: head: tuple = (7,) invalidated: set = field(default_factory=set) committed: list = field(default_factory=list) def admit(ledger: Ledger, effect: Effect) -> None: # Eviction check first: any basis version in the invalidation set is fatal. if any(v in ledger.invalidated for v in effect.basis): raise InvalidatedBasis( f"effect basis {effect.basis} descends from invalidated snapshot; evict" ) # Atomic basis-monotonicity check against the live head. if effect.basis != ledger.head: raise StaleBasisCommit( f"effect basis {effect.basis} != head {ledger.head}; quarantine, do not admit" ) ledger.committed.append(effect) def rollback(ledger: Ledger, to: int, invalidates: set) -> None: ledger.head = (to,) ledger.invalidated |= invalidates # Trace: A commits against v7, B rolls back to v6 invalidating v7. ledger = Ledger(head=(7,)) a = Effect(payload={"adjustment": 42}, basis=(7,)) admit(ledger, a) # accepted: basis == head rollback(ledger, to=6, invalidates={7}) # A replayed effect from a stale branch must now be rejected, not retried. try: admit(ledger, Effect(payload={"adjustment": 42}, basis=(7,))) except InvalidatedBasis as e: print(f"evicted: {e}") # correct: evict, do not re-submit ```