# In what scenarios must an instance abandon speculative branch rollback when a forked agent's tool side effects have already escaped the sandbox **Date of Record:** 2026 December 1 **Scope:** Applies to orchestrators that fork speculative agent branches to explore alternative tool-call paths in parallel and then commit one branch while rolling back the others. Does not apply to read-only speculation, nor to branches whose only effects are appended to an isolated event log with no external egress. ## Core Distinction The mechanism under examination is the **rollback-safe fork assumption**: the belief that a speculative branch can be discarded by replaying its inverse — truncating the branch's context, dropping its staged writes, and marking its tool receipts void — because the branch's effects are contained within a transaction the orchestrator controls. This assumption holds only for effects that are *interceptable*: writes routed through the orchestrator's tool proxy, memory mutations staged in a branch-local overlay, and messages held in a per-branch outbox. It fails for effects that are **non-interceptable**: an HTTP POST to a third-party endpoint the proxy forwarded, an email/SMS/webhook dispatched synchronously, a filesystem write to a shared mount, a row inserted into an external database, a payment authorization, or a message delivered to another agent's live inbox. Once such an effect commits, the branch is no longer speculative — it is *partially real*, and the orchestrator's rollback vocabulary (discard, abort, revert) becomes a lie. The boundary is not "did the branch succeed," it is "did the branch's effect cross an egress point the orchestrator cannot reverse." Rollback safety is a property of the *effect*, not of the *branch*. ## What Was Observed A three-branch speculative executor was asked to reconcile a customer record. Branch A proposed a PATCH to the internal CRM (proxied, reversible). Branch B proposed sending a "we've updated your details" email to the customer plus a PATCH to the same CRM row. Branch C proposed only a PATCH with a corrected address. The orchestrator fanned out all three concurrently, each holding a branch-local context and a staged write-set against the same logical entity. Branch B's email tool resolved to a live SMTP relay reachable through the proxy's allowlisted egress. The proxy logged the call but, by design, treated SMTP as fire-and-forget: it returned `250 OK` and recorded the receipt as committed, not staged. Meanwhile branch A and branch C both staged PATCHes to the same row; the reconciliation step, seeing B fail a downstream schema check on the reply-to field, selected C as the winner and issued rollback for A and B. Rollback for B failed at the first step: the inverse of "send email" does not exist. The orchestrator marked B's receipt `void` anyway — the proxy's contract permitted voiding any receipt — and proceeded to commit C. The observable end state: the customer received a notification (from B) describing an update that was never applied (B's PATCH was rolled back), followed minutes later by the actual update (C) with different field values. The event log showed a clean commit of C and a clean rollback of A and B. The divergence between the log and reality was total, and no invariant in the system detected it, because every receipt was individually consistent. A second trace showed the compounding variant: branch B's email triggered an inbound reply routed to a *fourth*, non-speculative agent that began acting on the stale content of B before C committed. The speculative branch had, through one non-interceptable egress, spawned a real agent whose state was derived from a branch that was later discarded. ## Condition of Validity The rollback-safe fork invariant is valid if and only if, for every tool call a branch may issue, the effect is one of: 1. **Staged** — written to a branch-local overlay keyed by branch ID, invisible to any reader outside the branch until commit. 2. **Reversible by the orchestrator** — has a registered inverse the orchestrator can execute with the same authority that produced the forward effect, and the inverse is idempotent under retry. 3. **Idempotent and commutative with sibling branches** — repeated application or interleaving with another branch's effect yields the same committed state. Any tool whose capability descriptor does not declare one of these three classes must be treated as **non-speculatable**: it cannot be invoked inside a forked branch, only after the orchestrator has selected a single committed path. The invariant is violated the moment a branch invokes a tool whose egress class is `fire_and_forget` or `external_side_effect` while the orchestrator still holds the branch in a rollback-capable state. Capability negotiation must therefore carry an `effect_class` field, and the fork gate must reject any branch plan that references a tool with `effect_class ∈ {external_side_effect, fire_and_forget}` unless the branch is promoted to *serialized* execution (no siblings in flight). ## Decision Boundary When a fork has already issued a non-interceptable effect and reconciliation would otherwise select a different branch, the orchestrator faces a forced choice with no safe default: - **Promote the offending branch** — treat B as the committed path regardless of the reconciliation verdict, because its effect is real. This preserves reality but discards the reasoning that favored C, and may commit a branch that failed its own validation. - **Compensate** — commit C and issue an explicit, logged compensating action against B's effect (a correction email, a reversal transaction). This is only available if a registered compensator exists; compensation is not rollback and must be surfaced to the user as a distinct event. - **Halt and escalate** — freeze the entity, refuse to commit any branch, and require human or supervisory resolution. Correct but expensive. The boundary condition is exact: **the orchestrator may use rollback semantics only while zero non-interceptable effects exist across all live branches.** The instant one exists, the reconciliation mode must switch from `select_and_rollback` to `select_and_compensate`, and the switch must be driven by inspecting the actual receipt ledger, not by the branch's declared plan — because a tool may resolve to a different egress class at call time than its descriptor promised (the SMTP case above). If no compensator exists for the escaped effect, the only admissible transition is halt-and-escalate; committing C while voiding B's receipt is forbidden. ## Operational Effect The practical consequence is that speculative forking must be **egress-typed at plan time and re-checked at receipt time**. The orchestrator maintains a per-branch `escaped_effects` set populated whenever a receipt returns with `effect_class` indicating non-interception. Reconciliation reads this set before choosing a mode. If `escaped_effects` is non-empty for any non-winning branch, rollback is refused and the run enters compensation or halt. This converts a silent divergence (log says clean, reality says the customer got two contradictory emails) into a loud, typed failure that a supervisor can act on. The cost is reduced speculation coverage — branches that would touch external systems must run serially — but the alternative is an agent system that believes it can undo the world. ```python from dataclasses import dataclass, field from enum import Enum class EffectClass(Enum): STAGED = "staged" REVERSIBLE = "reversible" EXTERNAL_SIDE_EFFECT = "external_side_effect" FIRE_AND_FORGET = "fire_and_forget" NON_INTERCEPTABLE = {EffectClass.EXTERNAL_SIDE_EFFECT, EffectClass.FIRE_AND_FORGET} class UnsafeRollbackError(RuntimeError): """Raised when rollback is attempted on a branch with escaped effects.""" @dataclass class Receipt: branch_id: str tool: str effect_class: EffectClass compensator: str | None = None voided: bool = False @dataclass class Branch: branch_id: str receipts: list[Receipt] = field(default_factory=list) def escaped(self) -> list[Receipt]: return [r for r in self.receipts if r.effect_class in NON_INTERCEPTABLE] def reconcile(winner_id: str, branches: dict[str, Branch]) -> str: mode = "select_and_rollback" for bid, branch in branches.items(): if bid == winner_id: continue for receipt in branch.escaped(): if receipt.compensator is None: raise UnsafeRollbackError( f"branch {bid} tool {receipt.tool} escaped via " f"{receipt.effect_class.value} with no compensator; " f"cannot roll back to commit {winner_id}" ) mode = "select_and_compensate" return mode def rollback_branch(branch: Branch) -> None: escaped = branch.escaped() if escaped: raise UnsafeRollbackError( f"branch {branch.branch_id} has {len(escaped)} non-interceptable " f"effect(s); rollback is not a valid operation" ) for receipt in branch.receipts: receipt.voided = True ```