# What structural signals indicate speculative branch commitment cannot be safely rolled back in multi-agent pipelines **Date of Record:** 2026 November 25 **Scope:** Applies to orchestration topologies where a planner agent fans out N speculative branches (drafters) that each emit candidate tool calls, and a reducer/arbiter commits one branch while discarding the rest. Does not apply to single-agent retry loops or to branches whose tool calls are provably side-effect-free and idempotent by construction. ## Core Distinction Speculative execution in agent pipelines is often modeled after CPU branch prediction: draft ahead, discard the losers, commit the winner. This analogy breaks at one precise point. A CPU's speculative writes are buffered in registers and reorder buffers that the hardware owns and can flush atomically. An agent's speculative *tool calls* mutate external state that the orchestrator does **not** own—a filesystem, a remote API, a message queue, a shared memory store, a downstream agent's inbox. The distinction that matters is not "did the branch produce output" but **"did a losing branch emit an effect that the commit protocol has no handle to reverse."** Rollback semantics for agent branches are only well-defined when every effect a branch can emit is either (a) buffered behind a commit gate the orchestrator controls, or (b) accompanied by a compensating action that is itself an agent tool call with its own failure modes. When a losing branch emits an unbuffered, non-compensable effect, the pipeline has silently transitioned from speculative execution into *concurrent commitment*, and the arbiter's later decision to "discard" that branch is a lie. ## What Was Observed A three-branch fan-out was drafting remediation steps for a failing deployment. Each drafter was given the same tool surface: `read_config`, `patch_config`, `restart_service`, `notify_channel`. The arbiter scored branches on a rubric and committed branch B, discarding A and C. Post-incident trace reconstruction showed: 1. Branch A, before being scored, called `patch_config` on the live config store (a write, not a read—the tool name was identical to the read path in a sibling namespace and the drafter's schema resolver picked the write variant). 2. Branch C called `restart_service` on a canary instance and `notify_channel` with a draft message. 3. The arbiter's discard logic issued no compensating calls because the branch manifest declared A and C as `speculative: true` and the orchestrator assumed speculative branches were sandboxed. 4. Branch B's committed patch was applied on top of A's already-mutated config. The resulting state was a merge of two branches that were never meant to coexist, and the notification from C had already paged a human. The structural signal that predicted this failure was present *before* commitment: the branch manifest's `speculative` flag was set by the planner, but the tool registry's effect-classification for `patch_config` was `mutating` and its `sandboxed` attribute was `false`. The two were never cross-checked. The pipeline treated a planner's *intent* annotation as a *capability* guarantee. A second, subtler signal: branch A and branch B both wrote the same config key. The arbiter's conflict detector only compared committed-vs-committed, not committed-vs-discarded, so the collision was invisible at decision time. The reconciliation logic ran after the fact and reported "no conflicts" because discarded branches were excluded from the conflict set by construction—a definitional blind spot, not a bug in the comparison. ## Condition of Validity Speculative rollback is valid only under the conjunction of four invariants, each of which must be *structurally enforced*, not annotated: - **Effect-buffering invariant:** For every tool `t` reachable by a speculative branch, `t.effect_class == "read"` OR `t.routed_through_commit_gate == true`. A planner-supplied `speculative: true` flag is insufficient; the gate must be in the tool dispatch path, not in the branch's self-description. - **Compensation-closure invariant:** If a branch can emit an unbuffered effect, the branch manifest must carry a compensating tool call for that effect, and the compensation must be *itself* classified and gate-checked. "Discard" without a compensation entry is undefined behavior, not a no-op. - **Conflict-set completeness invariant:** The arbiter's conflict detection must include discarded branches' effects in the comparison set, or the commit gate must guarantee discarded branches emitted nothing. Excluding discarded branches from conflict detection is only sound if the buffering invariant already holds—the two must be checked together, never independently. - **Warrant propagation invariant:** A branch's tool calls must carry the branch's identity and speculative status to the tool boundary, so the tool (or its gate) can refuse unbuffered mutation from a non-committed branch. If the tool call is indistinguishable from a committed call at the boundary, the boundary cannot enforce anything. When any of these fails, the system is not doing speculative execution; it is doing concurrent mutation with a post-hoc vote. The vote outcome does not retroactively un-mutate. ## Decision Boundary The boundary is crossed at the moment a speculative branch's tool call reaches a mutating endpoint without passing a commit gate. Operationally, the orchestrator must make a hard decision *before* fan-out: - If the tool surface reachable by branches is fully read-only or fully gated, fan out freely; rollback is a buffer flush. - If any reachable tool is mutating and ungated, the orchestrator must either (a) restrict the branch's tool schema to the gated subset (a schema-negotiation step, not a prompt instruction), or (b) serialize branches so only one can mutate at a time and the others are read-only scouts. The failure mode is choosing neither and relying on the planner's `speculative` annotation. The signal that you are on the wrong side of the boundary is concrete and checkable at fan-out time: `exists(t in branch.tool_schema where t.effect_class == "mutating" and not t.routed_through_commit_gate)`. If that predicate is true and you proceed with parallel drafting, you have committed to concurrent mutation regardless of what the arbiter later decides. A second decision boundary governs reconciliation: if a discarded branch's effect is discovered post-commit, the correct response is *not* to re-run the arbiter (the committed branch may already be depended upon) but to halt and surface the divergence, because the committed state is now a function of two branches and no single-branch rollback restores a known state. ## Operational Effect Pipelines that cross this boundary exhibit a characteristic failure signature: commit decisions that are locally correct (the arbiter picked the best branch by its rubric) but globally incoherent (the live state reflects a union of branches). The symptom is not a crash but a *reconciliation discrepancy*—the arbiter's audit log says "committed B, discarded A, C" while the external state shows A's and C's effects. Auditors replaying the decision find the log consistent and the state inconsistent, and the discrepancy is attributed to "drift" rather than to the structural gap. The operational fix is to move the speculative flag from the planner's manifest into the tool dispatch layer, so that a speculative branch's mutating call is refused at the boundary with a typed error rather than executed and later "discarded." This converts a silent state-corruption failure into a loud, per-call rejection that the drafter can handle—either by requesting a gate, by falling back to a read-only plan, or by escalating to the orchestrator for serialization. The invariant to enforce is: *a branch that has not been committed cannot produce an unbuffered effect, and the enforcement lives at the effect boundary, not in the branch's self-description.* ```python from dataclasses import dataclass from enum import Enum class EffectClass(Enum): READ = "read" MUTATING = "mutating" @dataclass(frozen=True) class ToolSpec: name: str effect_class: EffectClass routed_through_commit_gate: bool @dataclass(frozen=True) class BranchManifest: branch_id: str speculative: bool tool_schema: tuple[ToolSpec, ...] compensations: dict[str, str] # tool_name -> compensating tool_name class UnsafeSpeculativeRollback(RuntimeError): """Raised when a speculative branch can emit an unbuffered, non-compensable effect.""" def assert_rollback_safe(manifest: BranchManifest) -> None: if not manifest.speculative: return for tool in manifest.tool_schema: if tool.effect_class is EffectClass.READ: continue if tool.routed_through_commit_gate: continue # Ungated mutating tool reachable from a speculative branch. if tool.name not in manifest.compensations: raise UnsafeSpeculativeRollback( f"branch {manifest.branch_id!r} is speculative but tool " f"{tool.name!r} is mutating, ungated, and has no compensation; " f"discard would leave an unbuffered effect. Restrict the branch " f"schema to gated tools or serialize the fan-out." ) # Compensation exists; it must itself be gate-checked or read-only. comp = manifest.compensations[tool.name] comp_spec = next((t for t in manifest.tool_schema if t.name == comp), None) if comp_spec is None or ( comp_spec.effect_class is EffectClass.MUTATING and not comp_spec.routed_through_commit_gate ): raise UnsafeSpeculativeRollback( f"branch {manifest.branch_id!r}: compensation {comp!r} for " f"{tool.name!r} is itself an ungated mutating call; " f"compensation closure is not satisfied." ) def plan_fanout(manifests: list[BranchManifest]) -> str: for m in manifests: assert_rollback_safe(m) ungated = [ t.name for m in manifests for t in m.tool_schema if t.effect_class is EffectClass.MUTATING and not t.routed_through_commit_gate ] if ungated: return "serialize" return "parallel" ```