# Which invariants prevent speculative branch reconciliation from corrupting shared external state when rollback is only partially observable **Date of Record:** 2026 November 16 **Scope:** Applies to multi-agent systems that fan out speculative branches against a shared, externally observable resource (a database, a file tree, an outbound API, a message queue) and reconcile branches by "rolling back" losing branches. Does not apply to purely functional branches whose entire effect set is captured in an in-memory transaction log that can be discarded atomically. ## Core Distinction The distinction that matters is between **rollback that is a state transition** and **rollback that is an inverse operation**. A speculative branch that only mutated local, versioned state can be rolled back by *transitioning* to a prior version — the rollback is total, atomic, and observable. A speculative branch that emitted an external effect (a POST, an `fsync`, a `SEND` on a queue, an append to a shared log) can only be rolled back by executing a *compensating inverse* — and inverses are partial, non-atomic, and frequently unobservable. Most multi-agent rollback designs assume the first model and are deployed against the second. The failure is non-obvious because the system *appears* to reconcile correctly: the losing branch is marked `rolled_back`, the winner commits, and the run reports success. The corruption lives in the gap between "we issued the inverse" and "the inverse actually took effect at the external resource." That gap is the boundary condition this record addresses. The specific invariant at risk is **effect monotonicity**: no external effect produced by a losing branch may remain visible after reconciliation completes. Systems routinely violate it while reporting clean reconciliation, because they conflate *rollback issued* with *rollback confirmed*. ## What Was Observed A three-way speculative fan-out was launched over a shared object store. Branch A and Branch B both wrote a derived artifact to the same key path; Branch C read it. Branch B lost reconciliation. The reconciler issued `DELETE key` as the compensating inverse and marked B rolled back. Two facts were not modeled: 1. The delete was issued *asynchronously* and its completion was not awaited before the winner's commit was published. 2. Branch C had already read the pre-delete value and cached it into its own committed output. The result: the winner's commit referenced a version of the artifact that B had overwritten and that was then deleted; C's committed output embedded the stale B value. Reconciliation reported `{A: committed, B: rolled_back, C: committed}` with zero errors. The corruption was only detected downstream when a consumer of C's output failed a checksum against the winner's artifact. The rollback had been *issued* but never *confirmed*, and the read-before-rollback in C was never re-validated. The non-obvious part is not that async deletes race. It is that **a losing branch's effects can be read by a winning branch before the inverse completes**, so reconciliation must treat reads as effects too. The system had modeled writes as the only thing needing compensation. ## Condition of Validity The naive reconciliation protocol — "issue inverse, mark rolled back, commit winner" — is valid only under all three of the following: - **Inverse totality:** the compensating operation restores the external resource to a state indistinguishable from pre-branch, for every effect the branch emitted. - **Inverse synchrony:** the inverse is confirmed complete (acknowledged by the external resource) before any winner commit is published and before any surviving branch's output is treated as final. - **Read isolation:** no surviving branch observed any value written by a losing branch, or if it did, that branch is itself demoted to losing and reconciled. If any condition fails, the protocol silently violates effect monotonicity. In practice the third condition fails most often and is checked least often, because read effects are invisible in most effect-tracking middleware that only intercepts writes. ## Decision Boundary When a speculative branch has emitted effects that are not totally invertible, or whose inverse cannot be synchronously confirmed, **do not reconcile by rollback**. Instead, promote the branch to a *committed-with-compensation* state and require an explicit, ordered compensation pass that (a) awaits each inverse, (b) records the confirmed post-state, and (c) re-validates every surviving branch that read the compensated range, demoting any that observed a now-invalid value. If the external resource offers no confirmation primitive for the inverse, treat the branch as un-rollbackable and serialize it: it must be the last branch to commit, or it must be excluded from speculation entirely. The boundary is: *speculate freely over state you can version; serialize over state you can only compensate.* ## Operational Effect Adopting the confirmed-inverse + read-demotion discipline converts a class of silent, downstream-detected corruption into an upfront reconciliation cost: surviving branches that touched a compensated range must be re-validated, which can cascade demotions and, in the worst case, collapse a fan-out to a serial chain. That cost is the price of effect monotonicity. Systems that skip it retain the appearance of parallelism and reconciliation while leaking losing-branch effects into committed outputs — a failure that is invisible at reconcile time and only surfaces as inconsistent derived state, often far from the branch that caused it. ```python class UnconfirmedRollbackError(RuntimeError): """Raised when a losing branch's inverse could not be confirmed before commit.""" pass class EffectMonotonicityError(RuntimeError): """Raised when a surviving branch observed a value from a rolled-back branch.""" pass def reconcile(branches, external, winner_id): losing = [b for b in branches if b.id != winner_id] # Phase 1: confirm every inverse before any commit is published. for b in losing: if not b.effects_totally_invertible(): raise UnconfirmedRollbackError( f"branch {b.id} has non-invertible effects; must be serialized, not rolled back" ) for effect in b.effects: ack = external.apply_inverse(effect) # must be synchronous if not ack.confirmed: raise UnconfirmedRollbackError( f"inverse for {effect.key} on branch {b.id} not confirmed: {ack.reason}" ) # Phase 2: re-validate surviving branches against compensated ranges. compensated = {e.key for b in losing for e in b.effects} for b in branches: if b.id == winner_id: continue overlap = compensated & b.read_keys if overlap: raise EffectMonotonicityError( f"branch {b.id} read compensated keys {sorted(overlap)}; " f"demote to losing and re-run" ) # Phase 3: only now is the winner's commit safe to publish. return external.publish_commit(winner_id) ```