In what scenarios must an instance abort a speculative branch when its rollback journal is not causally closed across peer agents

**Date of Record:** 2026 December 1 **Scope:** Applies to multi-agent systems where a coordinator forks speculative execution branches across sibling agents that mutate shared external state (filesystems, databases, ticketing systems) and reconcile them via rollback journals. Does not apply to pure-read speculative fan-out or to single-agent tree-of-thought rollback where no external side effects escape the agent's private sandbox.

Core Distinction

The failure mode is not "rollback failed." It is **rollback succeeded locally but was not causally closed globally**. A speculative branch agent (call it the *speculator*) records its external mutations in a journal so it can undo them if the coordinator rejects the branch. The invariant most implementations assume is: *if the journal replays cleanly in reverse, the branch is rolled back.* That invariant is false in any system where a sibling agent read the speculator's side effects and committed a *derived* mutation elsewhere. The speculator's journal is causally open: it describes its own writes but not the downstream writes those reads induced in peers. Reversing the journal erases the cause while leaving the effect, producing a state that never existed in any serial execution — an orphaned derived write.

The sharp distinction: **compensable** vs. **causally closed**. A journal is compensable if every entry can be inverted. It is causally closed only if no peer agent observed an intermediate state and persisted a consequence of it. Rollback correctness requires both; most systems verify only the first.

What Was Observed

A coordinator forked three speculators (A, B, C) over a shared inventory service. A's branch decremented stock for SKU-4471 from 40 to 38 and journaled the two decrements. Mid-branch, A's token budget forced a checkpoint; while A was paused, B (a sibling speculator on a different hypothesis) read SKU-4471, saw 38, and committed a reorder-threshold trigger that wrote a purchase order for 50 units — a derived mutation keyed on the observed value.

The coordinator then rejected A's branch on a downstream verification mismatch and issued rollback. A replayed its journal in reverse: stock returned to 40. B's purchase order remained, now justified by a stock level (38) that no longer existed. The reconciliation pass flagged an "unexpected PO with no low-stock evidence" and, because the reconciler treated unexplained derived writes as corruption, **halted the entire swarm** rather than discarding the PO.

The trace: A's journal had two entries, both invertible, both replayed successfully. Rollback reported `OK`. The orphaned PO was created 340ms after A's second write and 1.2s before rollback — well inside the window where A's effects were visible to peers. No agent recorded the read-dependency edge `B.read(SKU-4471) → A.write(SKU-4471)`. The journal was a write-log, not a happens-before graph.

Condition of Validity

The "replay the journal to roll back" strategy is valid **only** when the speculator's external writes were never observed by any concurrent agent before rollback completed — i.e., the branch executed under an isolation guarantee (snapshot isolation, or a lease that blocks peer reads of the touched keys). Absent that guarantee, rollback is valid only if the journal is augmented with outbound read-dependency edges and the coordinator can either (a) cascade-compensate every derived write reachable from the speculator's writes, or (b) refuse to fork speculators over keys that any sibling can read.

The precise precondition: *for every write W in speculator S's journal, the set of peers that read the key of W during the branch's visibility window must be empty, OR every derived write by those peers must itself be journaled with a back-edge to W and be compensable.* If neither holds, the branch is **not rollback-safe** and must not be forked speculatively — it must run under exclusive lock.

Decision Boundary

The boundary is drawn at the moment a speculator's write becomes *peer-observable* while its branch is still *uncommitted*. Before that instant, rollback is a local inverse. After it, rollback is a distributed compensation problem that requires the coordinator to walk the read-dependency graph.

Operationally: a coordinator must, at fork time, classify each key a speculator may write as either `ISOLATED` (peers blocked from reading until commit/abort) or `SHARED` (peers may read intermediate values). If a speculator touches a `SHARED` key, the coordinator must either upgrade to exclusive execution or require the speculator to emit read-dependency edges and the reconciler to perform cascading compensation. A speculator that cannot prove causal closure on a `SHARED` key must abort the branch *before* its first write — not after, when the orphaned derived writes are already committed and the reconciler must guess whether they are corruption or legitimate.

The most dangerous sub-case: the reconciler cannot distinguish an orphaned derived write from a legitimate one, because both look like "a write with no matching low-level cause." Treating orphans as corruption halts the swarm; treating them as legitimate silently commits state justified by a rolled-back world. Neither is safe — which is why the boundary must be enforced at fork, not at reconcile.

Operational Effect

Enforcing causal closure at fork converts an unbounded reconciliation problem into a bounded admission check. The cost is reduced speculation parallelism over hot keys (speculators serialize on `SHARED` keys), but the benefit is that rollback is always a local inverse and the reconciler never faces an ambiguous orphan. Systems that skip this check pay in one of two currencies: swarm-wide halts on false-positive corruption, or silent divergence where committed state references values that no serial execution ever produced. The invariant to enforce: **a speculative branch may write a `SHARED` key only if it holds an exclusive lease on that key for the branch's lifetime, or if every peer read of that key is journaled with a back-edge and is compensable.** Anything else is a branch that will roll back cleanly and still be wrong.

class CausallyOpenRollbackError(RuntimeError):
    """Raised when a speculative branch's journal is compensable but not causally closed."""
    pass


class SpeculatorJournal:
    def __init__(self, speculator_id: str):
        self.speculator_id = speculator_id
        self.writes = []          # (key, old_value, new_value)
        self.read_edges = []      # (peer_id, key) observed reads of our writes

    def record_write(self, key: str, old, new, key_class: str):
        self.writes.append({"key": key, "old": old, "new": new, "class": key_class})

    def record_peer_read(self, peer_id: str, key: str):
        self.read_edges.append((peer_id, key))

    def assert_rollback_safe(self):
        """A branch may roll back only if every SHARED write was never observed,
        or every observing peer's derived writes are journaled and compensable."""
        for w in self.writes:
            if w["class"] != "SHARED":
                continue
            observers = [peer for (peer, k) in self.read_edges if k == w["key"]]
            if observers:
                raise CausallyOpenRollbackError(
                    f"speculator {self.speculator_id} wrote SHARED key {w['key']!r} "
                    f"observed by peers {observers} before commit; journal is "
                    f"compensable but not causally closed — abort branch before first write"
                )


def fork_speculative_branch(journal: SpeculatorJournal, planned_writes):
    for key, old, new, key_class in planned_writes:
        journal.record_write(key, old, new, key_class)
        # Admission check runs on the first SHARED write, before side effect lands.
        journal.assert_rollback_safe()
    return journal