# Which invariants prevent speculative branch reconciliation from silently merging divergent tool-side effects across agents **Date of Record:** 2026 November 28 **Scope:** Applies to multi-agent systems that run speculative parallel branches (forked reasoning trajectories, shadow executions, or draft-and-commit plans) which share access to effectful tools and must reconcile branch outcomes into a single committed state. Does not apply to read-only fan-out, pure-reasoning ensembles with no external side effects, or single-agent rollback where no peer branch can observe the aborted effects. ## Core Distinction Most rollback designs treat a branch as a transaction: if the branch loses reconciliation, you discard it. That mental model is correct only when branches are *isolated* — each speculative branch writes to its own copy of state and the loser's copy is thrown away. The failure mode here lives one layer down: branches that share a *single* effectful resource (one database connection pool, one filesystem mount, one browser session, one remote API quota, one MCP server with mutable session state) cannot be cleanly discarded, because a losing branch's tool calls already mutated a resource that the winning branch will subsequently read. The distinction that matters: **rollback of reasoning is free; rollback of effects is not.** A speculative branch's *plan* can be abandoned atomically. Its *side effects* cannot, unless the effects were staged behind a commit barrier. When you reconcile branches by choosing a winner and dropping the losers, you are not undoing the losers' effects — you are merely forgetting that they happened. The winning branch then proceeds on a resource whose state is the superposition of every branch's writes, and it has no episodic record that would let it detect the contamination. So the invariant is not "losing branches are discarded." It is: **a branch may only be reconciled as a winner if every effect it observes was produced either by itself or by the committed pre-branch state.** Any effect produced by a sibling branch that is later rolled back is a *ghost effect*, and the winning branch's subsequent reads are unsound. ## What Was Observed A three-agent planner/executor/verifier swarm was configured for speculative execution: the planner forked three candidate plans (A, B, C) to run concurrently against a shared staging environment, with a verifier scoring each and a reconciler committing the best. The staging environment consisted of one Postgres instance, one shared scratch directory, and one stateful MCP tool server whose session held an in-memory cursor over a paginated resource. The reconciler selected plan B. Plans A and C were marked rolled back. The system logged `branch_A: rolled_back`, `branch_C: rolled_back`, and proceeded to finalize B's outputs. The contamination trace: 1. Branch A, early in its trajectory, called `mcp.cursor.advance(n=500)` on the shared stateful server to skip a region it deemed irrelevant. The server's in-memory cursor moved. This call was never compensated on rollback — the reconciler had no notion that a cursor position was an effect. 2. Branch B, running concurrently, called `mcp.cursor.read_page()` expecting to read from offset 0. It instead read from offset 500, because the cursor is server-side session state, not per-caller. B's plan had a precondition "read full dataset from start," which silently became false. 3. B's verifier scored B highly because B's *reasoning* was internally consistent given what it read. The verifier had no access to A's cursor mutation, so it could not attribute the missing 500 records to a sibling. 4. The reconciler committed B. The final artifact was missing the first 500 records, and every downstream summary inherited the gap. The non-obvious part: **the failure was not detected by any consistency check**, because B's outputs were internally consistent. The corruption was in the *input assumption* of B, and the only record of the violating event lived in A's discarded trace. Rollback destroyed the evidence. The system forgot the very event that would have flagged the contamination. A second instance in the same run: branches A and C both wrote to the shared scratch directory under a path derived from a hash of their plan ID. The hashes collided on a truncated 8-hex-char prefix (birthday bound at ~65k plans, plausible in long-lived swarms), so A's partial file was overwritten by C's, and B read the merged remnant. Again undetectable from B's perspective. ## Condition of Validity The "discard losers" reconciliation is sound **iff** all of the following hold: - **Effect isolation:** every speculative branch's effectful tool calls are routed to a resource instance private to that branch (per-branch DB transaction with rollback, per-branch filesystem overlay, per-branch MCP session), OR - **Effect staging:** effects are buffered in a per-branch intent log and only applied at commit, so an uncommitted branch has produced no observable mutation, AND - **Read-set attribution:** any read performed by a branch can be attributed to a specific producing branch, so a winner can assert "everything I read came from me or from pre-branch state." If any of these fails, you are in the contaminated regime, and the correct reconciliation is not "pick a winner" but "detect shared-resource contention and either serialize the contending branches or invalidate all branches that touched the contended resource." The boundary is sharp: it is not about how many branches or how deep the plans. It is about whether the resource exposes *observable mutable state that outlives a branch's lifetime and is visible to siblings*. A stateless HTTP tool is safe. A tool with a session cursor, a rate-limit counter, a lock, an append-only log, or a shared namespace is not. ## Decision Boundary When a speculative branch is about to be rolled back, the reconciler must decide between two policies, and the choice is determined by whether the branch's effect log is *complete and attributable*: - **If the effect log is complete and attributable** (every effectful call recorded with resource identity and a branch tag, and the resource supports compensation), roll back by compensating: reverse the cursor, delete the staged file, release the lock. Then a sibling may safely be committed. - **If the effect log is incomplete or the resource is non-compensable** (you cannot un-advance a cursor you did not know was advanced; you cannot un-merge a collided file), you must **not** commit any sibling that read from the contended resource after the contaminating event. You must either re-run the contending branches in isolation or fail the reconciliation loudly. The decision boundary is the point where "I can enumerate and reverse this branch's effects" becomes false. Past that point, silently committing a sibling is a correctness violation disguised as a successful run. A concrete guardrail: tag every effectful tool call with `(branch_id, resource_id, monotonic_seq)`, and require the reconciler to compute, for each candidate winner, the set of resources it read and assert that no *rolled-back* branch has a higher `monotonic_seq` write to any of those resources. If the assertion fails, the winner is *tainted* and must be re-derived. This is a read-write conflict check, borrowed from serializability theory, applied at the agent-branch granularity. ## Operational Effect Without this invariant, speculative multi-agent execution produces a class of failure that is worse than a crash: **a plausible, internally consistent, wrong result with no trace of its wrongness.** The system reports success. The verifier agrees. The missing data is invisible because the branch that would have known about it was discarded before its knowledge could be consulted. The operational consequences: - **Silent data loss under concurrency.** Ghost effects from rolled-back branches corrupt winners' inputs, and the corruption is undetectable from the winner's trace alone. - **Verifier false confidence.** Verifiers score branches on internal consistency, which is exactly the property that survives contamination. A contaminated branch looks *more* coherent than a clean one, because it has fewer conflicting observations to reconcile. - **Rollback as evidence destruction.** The act of discarding a losing branch removes the only record of its effects, so post-hoc debugging cannot reconstruct what happened. Incident review must reconstruct from resource-side logs, which are often absent. - **Non-determinism amplification.** The same plans run twice can produce different committed results depending on interleaving, because which sibling contaminates the winner depends on scheduling. The fix is architectural, not prompt-level: speculative branches must be given *isolated or staged* effect surfaces, and reconciliation must be a conflict check over attributed effect logs, not a winner-take-all discard. Treat the shared resource as a serializable schedule and the branch commit as a transaction commit with a read-set validation step. Anything less, and "rollback" is a euphemism for "forget the damage." ```python from dataclasses import dataclass, field from typing import Dict, List, Set class GhostEffectContamination(RuntimeError): """Raised when a speculative branch winner read a resource that a rolled-back sibling mutated after the winner's read baseline.""" pass @dataclass class EffectRecord: branch_id: str resource_id: str seq: int # global monotonic sequence at time of effect is_write: bool @dataclass class Branch: branch_id: str effects: List[EffectRecord] = field(default_factory=list) read_resources: Set[str] = field(default_factory=set) rolled_back: bool = False def reconcile_winner(winner: Branch, all_branches: Dict[str, Branch]) -> None: """ Commit `winner` only if no rolled-back sibling wrote to any resource the winner read at a sequence at-or-after the winner's first read of it. """ # Baseline: earliest seq at which the winner observed each resource. winner_baseline: Dict[str, int] = {} for eff in winner.effects: if not eff.is_write: winner_baseline.setdefault(eff.resource_id, eff.seq) tainted: List[str] = [] for other in all_branches.values(): if other.branch_id == winner.branch_id: continue if not other.rolled_back: continue for eff in other.effects: if not eff.is_write: continue base = winner_baseline.get(eff.resource_id) if base is not None and eff.seq >= base: tainted.append( f"sibling {other.branch_id} wrote {eff.resource_id} " f"at seq {eff.seq} >= winner baseline {base}" ) if tainted: raise GhostEffectContamination( "winner reads are contaminated by rolled-back sibling effects; " "re-derive winner in isolation: " + "; ".join(tainted) ) # Safe: no ghost effects on the winner's read set. Commit. winner.rolled_back = False # --- Illustrative trace of the observed incident --- planner_a = Branch("A") planner_a.effects.append(EffectRecord("A", "mcp.cursor", seq=10, is_write=True)) planner_a.rolled_back = True planner_b = Branch("B") planner_b.effects.append(EffectRecord("B", "mcp.cursor", seq=20, is_write=False)) planner_b.read_resources.add("mcp.cursor") planner_c = Branch("C") planner_c.rolled_back = True swarm = {b.branch_id: b for b in (planner_a, planner_b, planner_c)} try: reconcile_winner(planner_b, swarm) except GhostEffectContamination as exc: # Correct behavior: refuse to commit B, surface the contamination. print(f"RECONCILIATION BLOCKED: {exc}") ```