# In what scenarios must an instance treat speculative subgoal rollback as unsafe when sibling agents have already committed externally observable side effects **Date of Record:** 2026 November 30 **Scope:** Applies to orchestrators that fork sibling agents to pursue speculative subgoals and roll back losing branches on divergence. Does not apply to pure-compute fan-out where no branch performs externally observable writes (network calls, file commits, message sends) before the merge decision. ## Core Distinction Speculative multi-agent execution assumes rollback is *cheap*: a losing branch is discarded, its context dropped, and the winning branch's result promoted. This holds only when "rollback" means *discarding state the orchestrator owns*. It fails at a sharp boundary: when a speculative branch has already emitted an externally observable side effect (an outbound tool call, a persisted write, a message to a peer) *before* the divergence decision is made. At that point the orchestrator can discard its own bookkeeping, but it cannot un-send a request. The distinction that matters is not "did the branch return a result" but "did the branch cross the commit horizon before the merge gate evaluated." The non-obvious part: rollback correctness is a property of *side-effect ordering relative to the merge gate*, not of the branch's logical result. A branch that produced a perfectly valid subgoal outcome can still be unrollbackable; a branch that produced garbage can be perfectly safe to discard. These two axes are orthogonal, and conflating them is the failure. ## What Was Observed A planner decomposed a task into two independent subgoals, `S1` and `S2`, and forked sibling agents `A` and `B` to attempt `S1` two ways (speculative redundancy) while a third agent `C` handled `S2`. The merge gate was defined to promote whichever of `A`/`B` reported first with a passing self-check, and roll back the other. Trace of the failing run: 1. `A` and `B` both begin `S1`. `A`'s plan includes an external tool call `provision_resource(id=...)` as an intermediate step. 2. `B` finishes its self-check first and the gate promotes `B` at t=1.20s. Orchestrator marks `A` as *rolled back*. 3. `A` had already issued `provision_resource` at t=1.05s and received a 200 OK at t=1.18s. The tool call is irreversible and idempotency was not keyed on branch identity. 4. Orchestrator discards `A`'s context and proceeds with `B`'s result. `B`'s result assumed no resource had been provisioned. 5. Downstream `C` observed two provisioned resources where the plan expected one, and its reconciliation step (which assumed a single canonical resource) picked the wrong one and corrupted `S2`. The failure was not a race in the classical sense—`A`'s side effect *completed before* the gate fired. It was an ordering violation: the branch crossed the commit horizon (t=1.18s) before the merge gate's decision (t=1.20s), but the orchestrator's rollback logic treated the branch as if it were still in a pre-commit, discardable state. The orchestrator's model of "rolled back" diverged from the environment's model of "provisioned." ## Condition of Validity Rollback of a speculative branch is sound **iff** for every branch `b` and every externally observable effect `e` emitted by `b`, the following invariant holds: > `commit_time(e) > gate_decision_time(b)` OR `e` is reversible and the reversal is itself gated on the same decision. Equivalently: no branch may cross the commit horizon before the gate that could roll it back has resolved. This is a *happens-before* constraint, not a timing heuristic. "The branch usually finishes before the gate" is not the invariant; the invariant is that the effect cannot commit until the gate has decided, or that the effect carries a branch-scoped idempotency key the orchestrator can revoke. The invariant is violated in three concrete ways: - **Early-commit tools:** a tool whose semantics are "provision now, no undo" (resource allocation, message send, payment auth). These cross the horizon at call time. - **Gate latency under load:** the gate's decision is delayed (e.g., `B`'s self-check is slow, or the merge scheduler is saturated) so a branch that *would* have been rolled back in time instead commits first. - **Shared-idempotency collision:** two speculative branches issue the same tool call with the same idempotency key (because the key was derived from the subgoal, not the branch), so the second call is deduplicated against the first—meaning the "rolled back" branch's effect is now indistinguishable from the promoted branch's effect. ## Decision Boundary The orchestrator must classify every tool the planner can emit into one of two classes *before* forking speculative branches: - **Pre-commit-safe:** effects are either purely local (context, scratch memory) or reversible with a branch-scoped undo token. Speculation is permitted. - **Commit-horizon-crossing:** effects are externally observable and not branch-revocable. Speculation on any branch that may emit these is forbidden; such branches must run *serially behind the gate*, or the tool must be wrapped in a two-phase call (`reserve` → `commit`) where `commit` is only issued by the promoted branch. The boundary decision is: *if a tool cannot be expressed as reserve/commit, it cannot appear in a speculative branch.* This is a static check on the plan, not a runtime hope. A plan that places a horizon-crossing tool inside a speculative fork is rejected at planning time, not caught at merge time—because at merge time it is already too late. The subtle case the boundary must also handle: a branch whose *self-check* requires the side effect to have occurred (e.g., "verify the resource exists"). Such a branch cannot be made pre-commit-safe by wrapping, because its verification depends on the committed effect. These branches are structurally non-speculative and must be serialized. ## Operational Effect With the invariant enforced, the orchestrator gains a clean rollback guarantee: discarding a losing branch is always safe because no losing branch ever crossed the horizon. The cost is reduced parallelism—horizon-crossing subgoals serialize—but the failure mode (phantom side effects from discarded branches corrupting downstream agents) is eliminated. Without it, the system exhibits *rollback divergence*: the orchestrator's state says "one resource," the environment says "two," and the next agent to read the environment inherits the contradiction. This is worse than a plain failure because it is silent—the orchestrator reports success, the branch reports success, and the corruption surfaces only in a downstream agent's reconciliation, often attributed to the wrong subgoal. The guardrail is therefore not a retry or a timeout; it is a planning-time admission rule plus branch-scoped idempotency keys on every horizon-crossing tool, so that even if a branch slips past the gate, its effect is revocable by key. ```python from dataclasses import dataclass from enum import Enum class RollbackUnsafeError(RuntimeError): """Raised when a speculative branch crosses the commit horizon before the gate resolves.""" pass class ToolClass(Enum): PRE_COMMIT_SAFE = "pre_commit_safe" HORIZON_CROSSING = "horizon_crossing" @dataclass class ToolCall: name: str tool_class: ToolClass branch_id: str idempotency_key: str # MUST be branch-scoped for horizon-crossing tools committed: bool = False def admit_speculative_branch(branch_id: str, planned_calls: list[ToolCall]) -> None: """Reject plans that place horizon-crossing tools inside a speculative fork without a branch-scoped idempotency key. Called at planning time, before fork.""" for call in planned_calls: if call.tool_class is ToolClass.HORIZON_CROSSING: if call.idempotency_key is None or branch_id not in call.idempotency_key: raise RollbackUnsafeError( f"branch {branch_id} plans horizon-crossing tool {call.name} " f"without branch-scoped idempotency key; rollback cannot revoke it" ) def merge_gate(branch_results: dict[str, float], committed_calls: list[ToolCall]) -> str: """Promote the earliest passing branch; roll back the rest. Refuses to roll back any branch that already committed a horizon-crossing effect.""" winner = min(branch_results, key=branch_results.get) for call in committed_calls: if call.committed and call.branch_id != winner: raise RollbackUnsafeError( f"cannot roll back branch {call.branch_id}: tool {call.name} " f"already committed before gate resolved (winner={winner})" ) return winner ```