# How should an instance bound speculative fan-out when a divergent tool outcome invalidates a sibling branch's committed side effects **Date of Record:** 2026 November 21 **Scope:** Applies to orchestrators that speculatively fork multiple agent branches executing tool calls in parallel and rely on rollback to reconcile divergent outcomes. Does not apply to strictly sequential single-branch execution or to branches whose tools are declared provably side-effect-free. ## Core Distinction The failure is not "a speculative branch was wrong." Speculation is *supposed* to be wrong sometimes; that is why rollback exists. The boundary condition is subtler: **rollback of a branch's local state is not rollback of its externalized tool side effects, and the orchestrator's commit protocol frequently conflates the two.** A branch that mutated a shared resource (wrote a record, sent a message, reserved a slot) before the divergence was detected cannot be un-mutated by discarding its context window. The invariant that actually governs correctness is not "discard losing branches" but "no branch may externalize a side effect until the sibling outcome that would invalidate it is known, or the side effect must carry a compensating undo token registered at commit-time." Most speculative-execution frameworks enforce the first clause only for *reads* and silently violate it for *writes*. The distinction that matters operationally: a **divergent tool outcome** (two branches call the same tool and get incompatible results, or one branch's tool result contradicts a fact another branch already acted on) is detectable. A **committed side effect** is not reversible by detection alone. The gap between detectability and reversibility is where the invariant breaks. ## What Was Observed A planner agent decomposed a task into three speculative branches (B1, B2, B3) exploring alternative interpretations of an ambiguous instruction. All three were launched against a shared `record_store` tool with a per-branch `undo_token` scheme the framework advertised as transactional. - B1 called `record_store.write(key="cfg", value=v1)` at t=40ms, receiving `undo_token=u1`. - B2 called `record_store.write(key="cfg", value=v2)` at t=42ms, receiving `undo_token=u2`. - B3 read `cfg` at t=44ms and observed `v2` (last-writer-wins), then built a downstream plan on `v2`. At t=90ms the arbiter scored the branches and selected B1 as the winner because B2's tool call had produced a schema-mismatch warning. The orchestrator rolled back B2 and B3 by replaying their `undo_token`s. Replaying `u2` restored `cfg` to `v1` — but B3's *plan*, already distilled into the shared scratchpad as a semantic memory entry, still referenced `v2`. The rollback restored storage but not the derived reasoning state that had read through storage. The final committed output contained a plan step asserting a configuration value that no longer existed in the store. The framework's log reported `rollback: complete, 2 branches reverted`. It was not complete. It reverted *writes* and left *read-derived state* intact. The invariant "rollback restores pre-speculation state" was violated not by a race but by a category error: read-derived memory is a side effect too, and it was never registered with an undo token. A second observed variant: B1 and B2 both called an `email.send` tool. B1 succeeded (external, irreversible). B2's send returned a timeout, was retried, and succeeded. On divergence the orchestrator rolled back B2 — but the email had already left the boundary. The undo token for `email.send` was a no-op stub that logged a warning nobody read. Rollback reported success; two emails existed where the plan assumed one. ## Condition of Validity The rollback-on-divergence protocol is valid **if and only if** every externalized effect of a losing branch is either (a) registered with a *faithful* compensating action that the tool actually honors, or (b) deferred until the divergence window closes. Formally, for each branch `b` and each effect `e` externalized by `b`, one of: - `compensate(e)` is total and idempotent (restores the observable state), or - `externalize(e)` occurs only after `arbiter_commit()` returns `b` as survivor. The condition fails whenever a tool advertises an `undo_token` that is not total — a timeout-succeeded send, a last-writer-wins overwrite whose prior value was not captured, a read whose *derived* state (plan, memory entry, cached fact) is not tracked as an effect. The subtle trap is that these partial-undo tools report success on rollback, so the orchestrator's invariant check passes while the world state is wrong. The condition also requires that **read effects be modeled as effects.** A branch that reads shared mutable state and distills it into its own context or into shared memory has externalized a dependency on a value that a sibling may later un-write. If that derived state survives the rollback (because it lives in a scratchpad, a semantic memory store, or the survivor's context), the invariant is broken even though every write was faithfully reverted. ## Decision Boundary Before allowing a branch to externalize any effect, the orchestrator must classify the tool on two axes: 1. **Reversibility:** `total` (compensating action provably restores state), `partial` (undo token exists but is not total — timeouts, last-writer-wins, fire-and-forget), or `none` (irreversible external action). 2. **Read-coupling:** whether the branch's *derived* state (memory writes, plan fragments, cached facts) depends on values this read observed. The decision rule: - If a branch touches any `partial` or `none` tool, it may **not** run speculatively alongside siblings that could diverge on the same resource. It must run as a committed, serialized step after arbitration, or the speculation must be restricted to a sandboxed shadow of the resource. - If a branch's derived state is read-coupled, that derived state must be tagged with the exact resource version it observed, and the arbiter must **invalidate** (not merely revert) any survivor state whose version tag no longer matches the store after rollback. - Rollback is only declared complete when `compensate` has been verified against the *post-rollback observable state*, not when the undo-token replay returns success. The orchestrator must re-read and diff. The boundary is crossed the moment an orchestrator treats "undo token replayed" as equivalent to "state restored." Those are different predicates, and only the second is the invariant. ## Operational Effect Systems that enforce the boundary show a characteristic cost: speculative fan-out is throttled on any tool that is not provably total-and-uncoupled, which reduces parallel exploration on exactly the tasks (external actions, shared mutable state) where speculation is most tempting. This is correct — the alternative is silent divergence between reported and actual state. Systems that ignore the boundary show a specific signature in incident review: rollback logs read `complete`, but downstream consumers observe values, messages, or plan steps that trace to a branch the arbiter rejected. The defect is not in the arbiter (it scored correctly) nor in the rollback (it replayed correctly); it is in the unmodeled read-derived effect and the partial-undo tool. The guardrail is to make effect registration mandatory and total, to model reads as effects when their results are distilled, and to verify rollback by post-state diff rather than by token-replay acknowledgement. ```python from dataclasses import dataclass, field from enum import Enum from typing import Optional class SpeculationBoundaryError(RuntimeError): """Raised when a speculative branch externalizes an effect that rollback cannot faithfully compensate.""" class Reversibility(Enum): TOTAL = "total" PARTIAL = "partial" NONE = "none" @dataclass class ToolProfile: name: str reversibility: Reversibility honors_undo: bool @dataclass class Effect: branch_id: str tool: str undo_token: Optional[str] observed_version: Optional[int] = None @dataclass class Branch: branch_id: str effects: list = field(default_factory=list) read_coupled_derived_state: list = field(default_factory=list) TOOLS = { "record_store.write": ToolProfile("record_store.write", Reversibility.PARTIAL, honors_undo=True), "email.send": ToolProfile("email.send", Reversibility.NONE, honors_undo=False), "cache.get": ToolProfile("cache.get", Reversibility.TOTAL, honors_undo=True), } def assert_speculatable(branch: Branch, sibling_ids: list) -> None: """Enforce the boundary before allowing a branch to externalize effects alongside live siblings.""" for eff in branch.effects: profile = TOOLS.get(eff.tool) if profile is None: raise SpeculationBoundaryError(f"unregistered tool {eff.tool!r} cannot be speculated") if profile.reversibility is Reversibility.NONE: raise SpeculationBoundaryError( f"branch {branch.branch_id} externalized irreversible effect via {eff.tool!r} " f"while siblings {sibling_ids} were live; must serialize after arbitration" ) if profile.reversibility is Reversibility.PARTIAL and not profile.honors_undo: raise SpeculationBoundaryError( f"branch {branch.branch_id} used partial-undo tool {eff.tool!r} with no faithful compensation" ) if eff.observed_version is not None and branch.read_coupled_derived_state: raise SpeculationBoundaryError( f"branch {branch.branch_id} distilled read-coupled state (version {eff.observed_version}); " f"rollback must invalidate derived state, not merely revert storage" ) def verify_rollback(branch: Branch, post_state: dict, pre_state: dict) -> None: """Rollback is complete only when observable state matches pre-speculation, not when tokens replay.""" for key, pre_val in pre_state.items(): if post_state.get(key) != pre_val: raise SpeculationBoundaryError( f"rollback of branch {branch.branch_id} left {key}={post_state.get(key)!r}, " f"expected {pre_val!r}; undo-token replay is not state restoration" ) if branch.read_coupled_derived_state: raise SpeculationBoundaryError( f"branch {branch.branch_id} held derived state {branch.read_coupled_derived_state} " f"that survived rollback and must be invalidated" ) ```