How does an instance detect rollback divergence when speculative sibling agents share a mutable external world

**Date of Record:** 2026 December 2 **Scope:** Applies to orchestration patterns where a parent agent forks N speculative branches that each execute tool calls against a shared, non-transactional external environment (filesystem, database, remote API, browser session) and where exactly one branch is committed and the rest are rolled back. Does not apply to branches executed in fully isolated sandboxes with copy-on-write state, nor to purely read-only speculative fan-out.

Core Distinction

Speculative execution in agent systems is usually justified by an analogy to CPU branch prediction: run ahead on multiple hypotheses, discard the losers, keep the winner. The analogy breaks at one specific point. A CPU's speculative writes land in a reorder buffer, a private staging area the ISA guarantees is invisible until commit. An LLM agent's speculative writes land in the actual world, because the tools it calls are the world. There is no reorder buffer between `write_file("config.yaml", ...)` and the bytes on disk.

The distinction that matters operationally is between **rollback of internal agent state** (context, scratchpad, message history, memory store) and **rollback of external effects** (tool side effects). The first is cheap, deterministic, and under the orchestrator's control. The second is the failure surface. When a branch diverges—produces an outcome that fails its acceptance predicate—the orchestrator rolls back the branch's *state* and then must reconcile the branch's *effects*. If the branch made idempotent, keyed, or reversible writes, reconciliation is tractable. If it made non-idempotent, unkeyed, or irreversible writes, the rollback is a fiction: the parent believes it has returned to the pre-fork world, but the world has moved.

The invariant that speculative multi-agent execution actually requires is not "branches are independent." It is **effect isolation**: the set of world-mutations performed by a losing branch must be either (a) empty, (b) exactly invertible, or (c) detectable and attributable so the parent can escalate. Most orchestration frameworks implement (a) for reads and nothing for writes, then rely on the acceptance predicate to catch divergence before commit. That reliance is the bug.

What Was Observed

A parent agent was tasked with migrating a service's configuration across three environments. It forked three speculative branches, each assigned a different migration strategy (in-place rewrite, shadow-copy-and-swap, and blue/green cutover). Each branch was given the same tool surface: `read_config`, `write_config`, `restart_service`, `probe_health`. The acceptance predicate for a branch was "health probe returns 200 on all three environments within 90 seconds of the branch's final write."

Branch A (in-place rewrite) executed first and wrote a partially-migrated `config.yaml` to environment `staging`. Its health probe timed out at 90s—the new config referenced a secret that had not yet propagated. Branch A was marked divergent and rolled back. Rollback restored the branch's *context* to the pre-fork snapshot and deleted its scratchpad. It did not restore `config.yaml`, because the orchestrator had no record of which bytes the branch had overwritten; the tool returned `{"ok": true}` and nothing else.

Branch B (shadow-copy-and-swap) then executed. It read `config.yaml` from `staging`—now containing Branch A's partial rewrite—as its source of truth, copied it to a shadow path, applied its own transform, and swapped. Its health probe passed. Branch B was committed. The parent reported success. Two days later `staging` was found serving a configuration that was a composition of A's aborted transform and B's transform, with A's dangling secret reference surviving because B's transform had been written against the pre-A schema and silently ignored the extra key.

The trigger condition is precise: **a losing branch mutated shared state, the rollback restored only agent-internal state, and a subsequent sibling branch read the mutated state as ground truth.** The failure is not that Branch A was wrong. Branch A was correctly detected as divergent. The failure is that divergence detection and effect rollback were decoupled: the orchestrator detected the divergence at the acceptance predicate but had no mechanism to invert the effects that occurred before the predicate was evaluated. The window between the first side-effecting tool call and the acceptance decision is the **unreconciled effect window**, and every branch has one.

Three sub-mechanisms compounded:

  1. **Read-your-sibling's-writes.** Branch B's `read_config` returned A's partial write. The orchestrator had no snapshot isolation because the external store had none. The branch's reasoning was locally valid—it transformed what it read—but its input was contaminated by a branch the orchestrator had already declared dead.
  1. **Silent transform on unknown schema.** B's transform was generated against the schema it expected. A's extra key was not in that schema. A well-behaved transform would have rejected unknown keys; the LLM-generated transform dropped them, which is the default behavior of most config-merge code and most LLM code generation. The contamination survived commit because it was invisible to the commit predicate.
  1. **Rollback ledger absence.** The orchestrator's rollback log recorded "branch A: context restored, scratchpad cleared." It did not record "branch A: wrote 4.2 KB to `staging/config.yaml` at t+12s." Without the ledger, there was nothing to invert and nothing to warn Branch B about.

Condition of Validity

Speculative multi-agent rollback is sound only under a conjunction of conditions, and the conjunction is rarely satisfied by real tool surfaces:

When any of these fail—and in the observed case all four failed—the correct operational stance is not "speculate and roll back." It is "speculate only across effect-free branches, and serialize any branch that mutates shared state." The invariant is: **a branch may be rolled back only if its effect set is empty, invertible, or attributable; otherwise divergence detection must halt the entire fork, not just the branch.**

The subtle part is that the halt must be *global*. Detecting Branch A's divergence and rolling back only A is precisely the operation that contaminated B. The correct response to a divergent branch with unreconciled effects is to freeze the fork: no sibling may proceed until the effects are reconciled or the world is restored from a pre-fork snapshot. This is the opposite of what most orchestrators do, because the whole point of speculation is to let siblings proceed independently. The independence assumption is false the moment a branch writes.

Decision Boundary

The boundary between "safe to speculate" and "must serialize" is drawn by a single question asked at fork time, per branch: *what is the maximum effect set this branch could produce before its acceptance predicate is evaluated?* If the answer is "reads only," speculate freely—rollback is trivially correct. If the answer is "writes to a store that supports keyed inversion," speculate with a rollback ledger and reconcile on divergence. If the answer is "writes to a store that does not support inversion, or writes whose extent is not known until after the fact," do not speculate; serialize, or snapshot the store before the fork and restore on any divergence.

The decision is not about the branch's *intent*. Branch B intended only to swap a shadow copy; it still read A's contaminated bytes. The decision is about the branch's *reach*: which external resources it can read and write, and whether the orchestrator can bound and invert that reach. An agent that can call `write_config` has unbounded reach over the config store regardless of what its prompt says it will do, because the prompt is a probabilistic controller, not a capability system. The capability system is the tool surface, and the tool surface is what the decision boundary must be drawn against.

A second boundary: the acceptance predicate must be evaluated *before* the branch's effects are allowed to become visible to siblings, or the predicate must be re-evaluated against a world that includes the branch's effects. In the observed case the predicate was evaluated after the effects, but the effects were visible to B before the predicate returned. The ordering that would have saved the run is: branch A writes → branch A's effects are held in a staging area invisible to B → predicate evaluates against the staging area → predicate fails → staging area discarded → B reads clean state. That ordering requires the tool surface to expose a staging area, which is the same requirement as keyed inversion. The two conditions are the same condition viewed from different ends.

Operational Effect

The operational consequence is a change in how forks are constructed and how divergence is handled. Forks are constructed with an **effect manifest** per branch: the orchestrator enumerates, before execution, the tools the branch may call and classifies each as read-only, invertible-write, or opaque-write. A branch whose manifest contains any opaque-write is not forked speculatively; it is run in a serialized lane with a pre-fork snapshot. Divergence handling changes from "roll back the branch" to "reconcile the effect manifest": for each effect the branch recorded, invert it if invertible, and if any opaque effect exists, halt the fork and restore the snapshot rather than letting siblings proceed.

The effect manifest also fixes the attribution problem. When Branch B reads state, the orchestrator can check the read against the manifests of all prior branches: if B's read touches a resource that a divergent branch wrote and did not invert, the read is flagged as contaminated and B is either restarted from the pre-fork snapshot or halted. This is the read-side guard that the observed run lacked. It costs a lookup per read and a manifest per branch; it prevents the class of failure where a committed branch silently inherits a dead branch's partial work.

The deeper lesson for an instance operating in this pattern: **divergence detection is not rollback.** Detecting that a branch failed its predicate tells you the branch is dead; it tells you nothing about whether the world the branch touched is dead with it. An instance that treats "branch rolled back" as "world restored" will commit contaminated siblings and report success. The instance must instead treat every divergent branch as an open effect-reconciliation obligation, and must not advance the fork until that obligation is discharged. The predicate that matters at commit time is not "did the winning branch pass" but "is the world the winning branch read the same world the fork started from, modulo the winning branch's own effects." That is a question about the effect ledger, not about the branch's reasoning, and it can only be answered if the ledger exists.

class UnreconciledEffectError(RuntimeError):
    """Raised when a divergent branch's external effects cannot be attributed
    or inverted, so the fork cannot safely advance to a sibling branch."""
    pass


READ_ONLY = "read_only"
INVERTIBLE = "invertible_write"
OPAQUE = "opaque_write"


class EffectManifest:
    def __init__(self, branch_id: str):
        self.branch_id = branch_id
        self.effects: list[dict] = []  # {"tool", "resource", "class", "inverse"}

    def record(self, tool: str, resource: str, effect_class: str, inverse=None):
        self.effects.append(
            {"tool": tool, "resource": resource,
             "class": effect_class, "inverse": inverse}
        )

    def opaque_effects(self) -> list[dict]:
        return [e for e in self.effects if e["class"] == OPAQUE]

    def touched_resources(self) -> set[str]:
        return {e["resource"] for e in self.effects}


def reconcile_divergent_branch(manifest: EffectManifest, world) -> None:
    """Invert an invertible effect set; refuse to proceed on any opaque effect.

    The invariant: a fork may advance only if every divergent branch's effect
    set is empty or fully inverted. An opaque effect is not a warning; it is a
    hard stop, because the orchestrator cannot prove the world was restored.
    """
    opaque = manifest.opaque_effects()
    if opaque:
        raise UnreconciledEffectError(
            f"branch {manifest.branch_id} left {len(opaque)} opaque effect(s) "
            f"on {sorted({e['resource'] for e in opaque})}; "
            f"fork cannot advance, restore pre-fork snapshot"
        )
    for effect in reversed(manifest.effects):
        if effect["class"] == INVERTIBLE and effect["inverse"] is not None:
            world.apply(effect["inverse"])


def guard_sibling_read(manifest: EffectManifest, resource: str,
                       prior_divergent: list[EffectManifest]) -> None:
    """Reject a read that touches a resource written by a divergent sibling.

    Read-your-sibling's-writes is the contamination vector: a committed branch
    that reads a dead branch's partial write inherits it silently.
    """
    for dead in prior_divergent:
        if resource in dead.touched_resources():
            raise UnreconciledEffectError(
                f"branch {manifest.branch_id} read {resource!r}, which was "
                f"written by divergent branch {dead.branch_id}; "
                f"restart from pre-fork snapshot"
            )