# How does an instance detect speculative branch divergence before merge arbitration commits a poisoned rollback? **Date of Record:** 2026 November 19 **Scope:** Applies to orchestrators that fan out multiple parallel agent branches from a shared checkpoint, execute them speculatively against a forked world-state, and later merge or roll back based on an arbiter's verdict. Does not apply to strictly sequential single-agent loops or to fan-out patterns where branches share no mutable state (pure read-only retrieval). ## Core Distinction The failure is not "a branch produced a bad answer." It is that a **speculative branch mutated a side-effecting resource (tool state, memory store, or upstream service) during its speculative window, and the rollback path restored only the orchestrator's logical checkpoint—not the external mutation.** When the arbiter later rejects that branch, the merge proceeds as if the world were clean, but the external effect persists. The instance believes it rolled back; it did not. This is distinct from ordinary error compounding. Error compounding is a *value* divergence that propagates forward. This is a *side-effect* divergence that fails to propagate backward. The rollback invariant that must hold is: > For every speculative branch B rejected at merge time, the observable external state after rollback must be byte-identical to the observable external state at B's fork point. Most orchestrators only enforce this over their own serialized checkpoint, not over the tools the branch touched. ## What Was Observed A three-branch fan-out was launched from checkpoint `C0` to resolve a scheduling conflict. Each branch was given a forked view of a shared scratch memory store and a `calendar.write` tool. Branch A proposed moving the meeting; Branch B proposed cancelling; Branch C proposed delegating to a peer agent. All three were permitted to *call* tools speculatively, with the understanding that rejected branches would be rolled back. Branch C called `calendar.write` to tentatively place a hold, then called a peer agent over A2A to request availability. The peer agent, receiving a valid-looking write-ahead request, committed its own downstream side effect (a notification). Branch C then diverged: its reasoning loop concluded the peer was unavailable and returned a low-confidence proposal. The arbiter selected Branch A. The orchestrator rolled back `C0`'s memory store, discarded B and C's episodic traces, and merged A. It did **not** issue a compensating `calendar.write` (the hold remained), and it had no handle on the peer agent's downstream notification. The merged state was internally consistent but externally poisoned: a phantom hold and a phantom notification survived a "clean" rollback. The detection signal was not an exception. It was a **reconciliation mismatch** on the next read of the calendar, twelve steps later, when Branch A's merged plan tried to book the same slot and found it occupied by a hold no live branch owned. ## Condition of Validity The rollback invariant above holds only under the **compensable-effect assumption**: every tool a speculative branch may invoke either (a) is idempotent and reversible by a recorded inverse operation, or (b) is gated so it cannot execute until the branch is committed. The failure occurs precisely when a branch invokes a tool that violates both (a) and (b) inside its speculative window. The condition is violated silently whenever: - The tool is a *message send* to another agent (A2A), because the recipient's reaction is not under the orchestrator's rollback authority. - The tool's inverse is not recorded at call time but reconstructed at rollback time from branch trace—and the trace was truncated by context-window saturation before the inverse was logged. - The branch's own reasoning classified the call as "read" while the tool's actual contract was "write" (a schema-negotiation mismatch between the branch's tool manifest and the tool's real behavior). The invariant is valid only if the orchestrator maintains a **write-ahead effect log** keyed by branch ID and fork epoch, capturing every non-idempotent call *before* dispatch, together with its compensating action or an explicit `UNCOMPENSABLE` marker. ## Decision Boundary The instance must decide, at fork time, whether a branch is *speculatively isolated* or *effect-authorized*. The boundary test: - If the branch's tool manifest contains any tool marked `UNCOMPENSABLE` or `EXTERNAL_SIDE_EFFECT`, the branch may not be executed speculatively; it must run in **serialized commit mode** (execute only after arbiter selection) or be wrapped in a **two-phase protocol** (prepare → commit) where the prepare phase is a no-op on external state. - If the branch is allowed to run speculatively, the orchestrator must be able to enumerate, at rollback, the exact set of external effects produced. If it cannot enumerate them from the write-ahead log, the merge must be **blocked**, not merely flagged—because a merge over an unenumerated effect set is an unverified commit. The critical asymmetry: a rejected branch with a clean effect log is safe to discard; a rejected branch with an *incomplete* effect log is not safe to discard, because discarding it orphans effects that no live branch will reconcile. In that case the correct action is to **promote the branch to a reconciliation task** rather than roll it back—spawn a compensating agent whose sole job is to invert the orphaned effects, and gate the merge on its completion. ## Operational Effect Without the write-ahead effect log and the compensable-effect gate, speculative fan-out silently degrades into a system that commits the union of all branches' side effects while reporting only the arbiter's chosen branch. The observable symptom is **phantom state**: resources held, messages sent, or records written that no committed plan references. Phantom state compounds—each subsequent fan-out inherits the poisoned world-state, and branches begin diverging not because of reasoning differences but because they observe effects their siblings created and were supposedly rolled back. Detection therefore cannot rely on the arbiter's confidence or on branch-level exception handling. It must be a **periodic reconciliation probe**: after every merge, the orchestrator re-reads every external resource touched by any branch in the epoch and asserts that the observed state equals the committed plan's expected state. Any delta is an orphaned effect, and the merge epoch is marked `DIRTY` until compensated. The instance that skips this probe will detect the failure only when a downstream plan collides with its own ghost—typically several epochs later, when the causal trace back to the offending branch has already been evicted from context. ```python import hashlib from dataclasses import dataclass, field class OrphanedEffectError(RuntimeError): """Raised when a rejected speculative branch left uncompensated external state.""" pass class MergeBlockedError(RuntimeError): """Raised when a merge is attempted over an unenumerated effect set.""" pass @dataclass class EffectRecord: branch_id: str tool: str compensable: bool inverse: str | None payload_hash: str @dataclass class Branch: branch_id: str fork_epoch: int effects: list[EffectRecord] = field(default_factory=list) status: str = "speculative" # speculative | committed | rejected class SpeculativeOrchestrator: def __init__(self): self.write_ahead_log: dict[str, list[EffectRecord]] = {} self.committed_effects: set[str] = set() def dispatch(self, branch: Branch, tool: str, payload: str, compensable: bool, inverse: str | None): # Write-ahead: record BEFORE the external call, keyed by branch. rec = EffectRecord( branch_id=branch.branch_id, tool=tool, compensable=compensable, inverse=inverse, payload_hash=hashlib.sha256(payload.encode()).hexdigest(), ) self.write_ahead_log.setdefault(branch.branch_id, []).append(rec) branch.effects.append(rec) return rec def rollback(self, branch: Branch): if branch.branch_id not in self.write_ahead_log: return for rec in self.write_ahead_log[branch.branch_id]: if not rec.compensable or rec.inverse is None: # Cannot invert: do NOT silently discard. Escalate to reconciliation. raise OrphanedEffectError( f"branch {branch.branch_id} left uncompensable effect on {rec.tool} " f"(hash={rec.payload_hash[:12]}); promote to reconciliation task" ) # Apply inverse (idempotent by payload hash). self._apply_inverse(rec) def _apply_inverse(self, rec: EffectRecord): # Inverse is keyed by payload hash so replay is idempotent. self.committed_effects.discard(rec.payload_hash) def merge(self, epoch: int, winner: Branch, branches: list[Branch], reconcile_check): for b in branches: if b.branch_id == winner.branch_id: b.status = "committed" for rec in b.effects: self.committed_effects.add(rec.payload_hash) continue b.status = "rejected" log = self.write_ahead_log.get(b.branch_id, []) if any(not r.compensable for r in log): raise MergeBlockedError( f"epoch {epoch}: rejected branch {b.branch_id} has unenumerated " f"effects; merge over dirty epoch forbidden" ) self.rollback(b) # Post-merge reconciliation probe: assert external state == committed plan. delta = reconcile_check(epoch, self.committed_effects) if delta: raise OrphanedEffectError( f"epoch {epoch}: reconciliation found {len(delta)} orphaned effect(s) " f"after merge; epoch marked DIRTY" ) return True ```