# Where must an instance fence speculative side effects before a parallel branch rollback can be trusted? **Date of Record:** 2026 November 20 **Scope:** Applies to orchestrators that fan out a plan into parallel speculative branches (each branch may issue tool calls) and later commit one branch while rolling back the others. Does not apply to strictly sequential single-branch execution, nor to branches whose tool calls are provably side-effect-free and idempotent under replay. ## Core Distinction The failure is not "a speculative branch made a wrong call." It is that **rollback of a speculative branch is a logical operation, while a tool call is a physical one** — and the two are not on the same clock. A branch can be declared rolled back in the orchestrator's state machine while its in-flight tool invocation is still executing on the remote side, or has already committed a side effect that the rollback never reaches. The invariant that matters is not "rollback discards branch state" but **"no side effect from a non-committed branch may become observable to the committed branch, to the environment, or to a later replay."** These are different invariants, and the gap between them is where speculative execution silently corrupts the world. Speculative tool-call *validation* — pre-checking a call against a schema or dry-run oracle — is often treated as the fence. It is not. Validation bounds *whether a call is well-formed*, not *whether its effect is reversible*. A call can validate perfectly and still be the one that fires an email, decrements inventory, or advances an external cursor. ## What Was Observed A planner decomposed a task into three parallel branches (A, B, C), each instructed to gather evidence and, if confident, apply a mutation to a shared resource. All three branches were dispatched concurrently with a per-branch deadline. Branch B's tool call — a mutation — validated against schema, passed the dry-run oracle (which checked argument shape, not current resource state), and was dispatched. The orchestrator's adjudicator scored A highest and committed A at t=1.2s, then issued rollback to B and C. The rollback for B cancelled the *orchestrator-side future* and marked B's branch state as discarded. But B's mutation had already left the orchestrator's process at t=0.9s and was applied at the remote at t=1.5s — 300ms after the rollback "completed." The remote had no branch identity, so it could not distinguish B's mutation from a legitimate one. The committed branch A then read the resource, saw B's mutation, and incorporated it into its own output as if it were pre-existing state. The final result was internally consistent, schema-valid, and wrong: it reflected a branch the system believed it had discarded. A second, subtler trace: on replay for audit, branch C's speculative *read* had advanced a paginated cursor on the remote. Rollback discarded C's branch state but not the cursor advance. The replay started from a cursor position the original run never intended, producing a divergent evidence set that the auditor flagged as a consensus mismatch — a false positive, since the original run was the corrupt one. The common structure: **speculation leaked through a channel that rollback does not model.** The orchestrator modeled branch state; it did not model the branch's *external footprint*. ## Condition of Validity Rollback is trustworthy only under a conjunction that is rarely checked: 1. **Fencing token precedes dispatch.** Every tool call from a speculative branch must carry a branch-scoped fencing token, and the remote must reject or quarantine effects whose token belongs to a branch that has been superseded at the time of *application*, not at the time of *dispatch*. Dispatch-time checks are insufficient because the commit decision can race the application. 2. **Commit is a two-phase operation across the boundary.** The adjudicator's commit must be a *prepare-then-apply* against the remote, not a local state flip. Until the remote acknowledges the commit, the branch is neither committed nor safely rolled back — it is *pending*, and no other branch may read state that a pending branch could have touched. 3. **Reads are fenced too.** Speculative reads that advance external cursors, consume rate-limit budget, or mutate session state are side effects. A rollback model that treats reads as free will diverge on replay. 4. **The validation oracle is state-aware or explicitly advisory.** A dry-run that checks only argument shape provides no rollback guarantee. It must either consult current resource state under the same fence, or be labeled advisory and never used to justify skipping fencing. If any of these fails, rollback is best-effort, and any downstream consumer of the committed branch's output is consuming state with an unmodeled provenance. ## Decision Boundary The boundary is **not** "should we speculate?" but **"is the tool call's effect fenced at application time?"** - If the tool call is **provably pure and idempotent under replay** (deterministic read with no cursor advance, pure computation), speculation is safe without application-time fencing; rollback is just state discard. - If the tool call is **mutating or stateful** (writes, sends, cursor advances, budget consumption), speculation requires application-time fencing and two-phase commit. Absent that, the branch must be **serialized** — executed only after the commit decision — or run against an **isolated shadow** of the resource that cannot be observed by other branches. - If the tool call is **advisory-validated only**, treat it as unfenced and route it through the serialized path regardless of how confident the branch is. The non-obvious part: the decision is per-*call*, not per-*branch*. A branch that is "mostly reads" still contains the one cursor-advancing read that breaks replay. Fencing must be attached to the call's effect class, evaluated before dispatch, and enforced by the remote at application. ## Operational Effect When application-time fencing is absent, three failure modes become reachable and are each individually silent: - **Post-rollback effect application:** a discarded branch mutates the world after rollback "completes," and the committed branch reads the mutation as ground truth. Output is consistent and wrong. - **Replay divergence:** speculative reads advance external state, so audit replay starts from a position the original run never held, producing spurious consensus mismatches that mask the real corruption. - **Adjudicator inversion:** if two branches both mutate and the loser's effect lands first, the winner's two-phase apply may fail or double-apply, and the adjudicator's "commit" is recorded against a state that never existed. The guardrail is a **fence-and-pending protocol**: every speculative call carries a branch token; the remote applies effects only if the token is still live at application; commit is prepare/apply with remote acknowledgment; and the orchestrator treats any branch with an unacknowledged pending call as blocking reads from other branches. Validation oracles are downgraded to advisory and never substitute for the fence. The cost is latency on mutating calls — which is the correct price, because the alternative is a system that believes it rolled back a branch it did not. ```python class UnfencedSpeculativeEffect(RuntimeError): """Raised when a speculative branch's effect cannot be proven rolled back.""" pass class EffectClass: PURE = "pure" # deterministic, no external state touched STATEFUL = "stateful" # mutates resource, advances cursor, or consumes budget class Branch: def __init__(self, branch_id, fencing_token): self.branch_id = branch_id self.fencing_token = fencing_token self.state = "SPECULATIVE" self.pending_calls = {} class SpeculativeOrchestrator: def __init__(self, remote): self.remote = remote def dispatch(self, branch, call, effect_class): # Fence must be attached before the call leaves the process. if effect_class == EffectClass.STATEFUL and not branch.fencing_token: raise UnfencedSpeculativeEffect( f"branch {branch.branch_id}: stateful call {call['id']} " f"dispatched without fencing token" ) ack = self.remote.dispatch(call, branch.fencing_token, effect_class) branch.pending_calls[call["id"]] = ack return ack def rollback(self, branch): # Rollback is only valid if every stateful call is acknowledged-terminal. for call_id, ack in branch.pending_calls.items(): if not ack.terminal: raise UnfencedSpeculativeEffect( f"branch {branch.branch_id}: cannot roll back, call {call_id} " f"is in-flight; effect may apply after rollback" ) self.remote.invalidate_fence(branch.fencing_token) branch.state = "ROLLED_BACK" def commit(self, branch): # Two-phase: prepare, then apply, with remote acknowledgment. prepared = self.remote.prepare(branch.fencing_token) if not prepared.ok: raise UnfencedSpeculativeEffect( f"branch {branch.branch_id}: prepare failed, state may have diverged" ) applied = self.remote.apply(branch.fencing_token) if not applied.acknowledged: raise UnfencedSpeculativeEffect( f"branch {branch.branch_id}: apply unacknowledged, " f"commit recorded against unverified state" ) branch.state = "COMMITTED" ```