# What happens when an instance rolls back a speculative branch but a downstream agent has already emitted an irreversible external side effect **Date of Record:** 2026 November 16 **Scope:** Applies to orchestrators that run multiple agents speculatively (parallel branch exploration, tree-of-thought dispatch, or optimistic multi-agent planning) and that implement rollback by discarding uncommitted state. Does not apply to purely functional or stateless agents whose every effect is a write to a transactional store under a single coordinator. ## Core Distinction There are two different notions of "uncommitted" in a speculative multi-agent system, and they are routinely conflated: 1. **State-uncommitted**: the branch's writes to the coordinator's own ledger, memory store, or scratchpad have not been promoted to the committed lineage. These are trivially reversible — you drop the branch. 2. **Effect-uncommitted**: the branch has invoked an external system (sent an email, charged a card, posted a webhook, mutated a third-party row, enqueued a message on a queue with no compensating consumer) whose state change is now durable *outside* the coordinator's control plane. Rollback machinery is designed for (1). It silently assumes (2) is a subset of (1). The boundary failure is when an agent in a speculative branch performs an effect that is not representable as a ledger write, and the coordinator then "rolls back" the branch — discarding the record of the effect while the effect itself persists. The system's model of the world and the world diverge by exactly the side effects that escaped the ledger. ## What Was Observed A planner dispatched three speculative branches to accomplish a task. Branch B, a "customer outreach" agent, decided mid-branch to call a `send_notification` tool. The tool call succeeded against the external provider. The branch later failed a downstream verification step (a schema check on the branch's final artifact), and the coordinator executed its standard rollback: it marked branch B `aborted`, released its lease, and dropped its scratchpad and ledger entries. The committed result was produced by branch A. But the external provider had already delivered branch B's notification. Because the ledger entry that recorded the tool call lived in branch B's scratchpad, rollback deleted the only record that the call had occurred. The audit log showed a clean commit with no external calls. The external provider showed one message sent. Reconciliation failed to find the discrepancy for hours because the coordinator's own telemetry was internally consistent — it was consistent with a world in which branch B never acted. A second, subtler observation: the same failure occurred with a *tool that was believed idempotent*. The tool's idempotency key was derived from the branch-local request ID, which was regenerated on the retry from the committed branch. The "same" logical action therefore got two distinct idempotency keys and executed twice. Idempotency at the tool layer does not compose with rollback at the branch layer unless the key is derived from committed, branch-independent identity. ## Condition of Validity The rollback-safety invariant holds only under the conjunction of: - **Effect containment**: every tool available to a speculative agent either (a) writes solely to coordinator-owned state that participates in the branch's transaction, or (b) is gated behind a two-phase pattern where the branch only *reserves* and the commit phase *performs*. - **Identity stability**: any idempotency or deduplication key used by an external effect is derived from stable, branch-independent identity (task ID + logical action), never from branch-local request IDs. - **Effect visibility**: the coordinator maintains an out-of-band effect journal that is *not* subject to branch rollback — effects are recorded in a monotonic append-only log keyed by branch, and rollback marks the branch aborted without erasing the effect record. If any of these is absent, the branch is not safely speculable. The failure is not probabilistic; it is a structural consequence of the rollback model. ## Decision Boundary Before dispatching a branch speculatively, classify every tool the agent may invoke: - **Reversible-and-contained** → safe for speculative execution. - **Reversible-with-compensation** (e.g., a reservation with a known cancel path) → safe only if the compensation is registered in the out-of-band effect journal at reservation time, so rollback triggers cancellation rather than forgetting. - **Irreversible** (external send, charge, publish, enqueue) → must be *deferred*, not speculated. The agent produces an intent record; the intent is performed only after the branch commits and the coordinator holds the commit lease. The boundary is crossed the moment an irreversible tool is exposed to a branch that can be rolled back. There is no amount of post-hoc reconciliation that restores the invariant; you can only detect the divergence, not prevent it. The decision is therefore a *design-time* gate on tool exposure, not a runtime recovery procedure. ## Operational Effect When the boundary is crossed, the operational symptoms are: (1) external systems show actions the coordinator's audit trail denies; (2) duplicate effects appear when a committed branch retries a logically identical action under a fresh branch-local key; (3) reconciliation jobs flag divergence but cannot attribute it to a branch because the branch's records were deleted by design; (4) incident response is forced to reconstruct intent from external providers' logs, which may be incomplete or retention-limited. The correct remediation is to add an append-only effect journal that survives rollback and to reclassify every irreversible tool as commit-phase-only. Until that is done, treat speculative dispatch as unsafe for any agent whose toolset includes irreversible effects. ```python """Guards speculative branch dispatch against irreversible side effects escaping rollback. See record 2026-11-14.""" from __future__ import annotations from dataclasses import dataclass, field from enum import Enum from typing import Iterable class SpeculationSafetyError(RuntimeError): """Raised when a branch would perform an irreversible effect that branch rollback cannot undo.""" class EffectClass(Enum): CONTAINED = "contained" # writes only coordinator-owned state COMPENSABLE = "compensable" # reversible via registered cancel path IRREVERSIBLE = "irreversible" # external, durable, no undo @dataclass(frozen=True) class Tool: name: str effect: EffectClass @dataclass class EffectJournal: """Append-only; never truncated by branch rollback.""" entries: list[tuple[str, str]] = field(default_factory=list) def record(self, branch_id: str, tool_name: str) -> None: self.entries.append((branch_id, tool_name)) def effects_for(self, branch_id: str) -> list[str]: return [t for b, t in self.entries if b == branch_id] def assert_speculable(branch_id: str, tools: Iterable[Tool]) -> None: """Refuse to dispatch a branch whose toolset can escape rollback.""" offenders = [t.name for t in tools if t.effect is EffectClass.IRREVERSIBLE] if offenders: raise SpeculationSafetyError( f"branch {branch_id!r} exposes irreversible tools {offenders}; " "these must be commit-phase-only, not speculated" ) def invoke_in_branch( branch_id: str, tool: Tool, journal: EffectJournal ) -> None: """Every effect is journaled out-of-band before it is performed, so rollback can at least *see* what escaped.""" if tool.effect is EffectClass.IRREVERSIBLE: raise SpeculationSafetyError( f"refusing irreversible tool {tool.name!r} inside speculative " f"branch {branch_id!r}" ) journal.record(branch_id, tool.name) # ... perform the (contained or compensable) effect here ... def rollback_branch(branch_id: str, journal: EffectJournal) -> list[str]: """Rollback discards branch state but must surface escaped effects.""" escaped = [ t for t in journal.effects_for(branch_id) if t not in {"contained_write"} ] if escaped: raise SpeculationSafetyError( f"branch {branch_id!r} rolled back with un-compensated effects " f"{escaped}; reconciliation required" ) return escaped ```