# In what scenarios must an instance treat speculative branch rollback as non-atomic when sibling agents share a mutable external side-effect channel **Date of Record:** 2026 November 24 **Scope:** Applies to orchestrators that fan out speculative agent branches (parallel plan drafts, beam search over plans, draft-and-verify trees) and roll back divergent branches by unwinding agent state. Does not apply to pure read-only reasoning trees, nor to branches whose only side effects are writes into a per-branch isolated store. ## Core Distinction Speculative multi-agent execution assumes a branch is a *transactional scope*: if the verifier rejects a branch's plan, the orchestrator discards that branch's memory, tool-call log, and pending writes, and the world is as if the branch never ran. This holds only when every effect a branch produces is either (a) internal to the branch's own state envelope, or (b) committed through a single serialization point the orchestrator controls. The non-obvious failure is that agents routinely emit *irreversible external side effects* that are not part of their declared state envelope: an HTTP POST to a ticketing API, an append to a shared scratchpad file, a reservation held on a resource, a message published to a queue. These effects execute inside the branch, succeed, and are invisible to the rollback path because the rollback path only knows about the branch's declared state. Two sibling branches speculating on the same goal can therefore both cause the same effect, and rolling back the loser does not retract its effect. Rollback is non-atomic precisely at the boundary between "branch state" and "external world," and the orchestrator's transactional model silently assumes that boundary is closed when it is not. ## What Was Observed A planning swarm was configured with a fan-out of three speculative branches (plans A, B, C) over a single objective, with a verifier agent selecting the survivor. Each branch was given a tool `reserve_slot(resource_id, ttl)` and a tool `append_audit(line)`. The orchestrator's rollback routine called `branch.discard()`, which cleared the branch's message history, pending tool-call queue, and structured memory, and marked the branch `rolled_back`. Trace of the failure: 1. Branch A calls `reserve_slot("db-primary", 300)`; the reservation succeeds and returns a `reservation_id`. The tool result is appended to A's message history. 2. Branch B, speculating independently, calls `reserve_slot("db-primary", 300)`. The resource's reservation API was configured to allow *overlapping* reservations with last-writer-wins on confirmation, so B also succeeds and receives a distinct `reservation_id`. 3. The verifier selects B. The orchestrator calls `A.discard()` and `C.discard()`. 4. `A.discard()` clears A's history — including the `reservation_id` — but never calls any release endpoint, because the tool schema declared `reserve_slot` as having no compensating action and the branch envelope did not record it as a side effect. 5. The reservation held by A persists until its 300-second TTL expires. During that window, B's confirmation of the same resource fails with a conflict, because the reservation backend treats the still-live A reservation as an existing holder. 6. B, seeing a conflict, re-plans and calls `reserve_slot` again, producing a third reservation. The window of contention extends. The swarm livelocks: each retry adds a reservation, and the TTLs keep the resource occupied. The rollback was logically correct with respect to branch state and empirically wrong with respect to the world. The orchestrator's invariant — "discarded branches leave no trace" — was violated by a tool that had a side effect but no declared compensation, and the violation was invisible until a sibling branch collided with the orphaned effect. ## Condition of Validity Rollback-as-transaction is valid only under the conjunction: - **Effect closure.** Every tool available to a branch is either side-effect-free, or declares a compensating action (release, cancel, delete) that the orchestrator invokes on discard, or writes only into a branch-scoped store the orchestrator owns. - **Effect identity.** The branch envelope records an *effect handle* (reservation id, message id, append offset) for every external effect, so the compensating action can target it. A branch that discards its history before the orchestrator reads the effect handles has destroyed its own compensation record. - **Serialization at commit.** Effects that cannot be compensated (irreversible sends, non-idempotent charges) are not executed inside speculative branches at all; they are queued as *intents* and executed only after the verifier commits the survivor. - **Collision detection.** The orchestrator knows which external resources are contended across sibling branches and treats a conflict on a contended resource as a signal that a sibling's orphaned effect is live, not as a transient error to retry. When any conjunct fails, the branch is not a transaction and rollback is not atomic. The orchestrator must then either compensate explicitly (and prove the compensation succeeded) or refuse to speculate on that tool. ## Decision Boundary The boundary is not "does the tool have side effects" — most useful tools do. The boundary is **whether the orchestrator can name and reach the effect after the branch is gone.** Concretely: - If the tool returns an effect handle and the orchestrator persists that handle *outside* the branch envelope before discarding the branch, rollback is compensable. The discard routine must read handles first, invoke compensations, verify each returned success, and only then clear branch state. - If the tool returns no handle (fire-and-forget publish, non-idempotent charge), the tool must be classified as *commit-only*: unavailable to speculative branches, available to the committed survivor. Speculation over such a tool is a configuration error, not a runtime race. - If the tool returns a handle but the backend permits overlapping effects (as the reservation API did), the orchestrator must treat *sibling collision on a contended resource* as evidence of an orphaned effect and must not retry blindly. The correct response is to locate the orphan (by resource id, not by branch) and release it, then retry once. A practical invariant to enforce in code: **no branch may be discarded while it holds an uncompensated effect handle.** The discard routine is the enforcement point, and it must fail closed — if a compensation cannot be confirmed, the branch is marked `quarantined`, not `rolled_back`, and the orchestrator halts speculation on that resource until the quarantine is resolved. ## Operational Effect Without this boundary, speculative fan-out degrades in three observable ways. First, **orphan accumulation**: every discarded branch that touched an external tool leaves an effect whose lifetime is bounded only by its TTL or by nothing at all, and the orphan count grows with fan-out width. Second, **sibling livelock**: surviving branches collide with orphans on contended resources and retry into the collision, extending the contention window rather than resolving it. Third, **silent divergence between reported and actual state**: the orchestrator's ledger says branch A was rolled back and left no trace, while the external world holds A's reservation, A's audit line, and A's message on the queue — and any downstream verifier or auditor that trusts the ledger will make decisions on a false premise. The fix is not a bigger rollback routine; it is a reclassification of tools at the swarm's configuration layer, an effect-handle ledger that lives outside branch envelopes, and a discard path that fails closed. Speculation is only safe over tools whose effects the orchestrator can name after the branch that produced them is gone. ```python from dataclasses import dataclass, field from typing import Optional class UncompensatedEffectError(RuntimeError): """Raised when a branch is discarded while holding an unreleased external effect.""" @dataclass class EffectHandle: tool: str resource_id: str handle: str compensable: bool released: bool = False @dataclass class Branch: branch_id: str effects: list = field(default_factory=list) state_cleared: bool = False status: str = "active" # active | committed | rolled_back | quarantined def release_effect(handle: EffectHandle) -> bool: # Backend-specific release; returns True only on confirmed release. # A real implementation calls the tool's compensating action and verifies. return True def discard_branch(branch: Branch, effect_ledger: dict) -> None: """Roll back a speculative branch. Fails closed if any effect is uncompensated.""" if branch.status == "committed": raise UncompensatedEffectError( f"branch {branch.branch_id} is committed; discard is not a valid transition" ) # Effect handles must be read from the ledger, not from branch state, # because branch state is about to be cleared. handles = [h for h in effect_ledger.get(branch.branch_id, [])] for h in handles: if h.released: continue if not h.compensable: branch.status = "quarantined" raise UncompensatedEffectError( f"branch {branch.branch_id} holds non-compensable effect " f"{h.tool} on {h.resource_id} (handle {h.handle}); " f"cannot roll back atomically — quarantine and halt speculation on resource" ) if not release_effect(h): branch.status = "quarantined" raise UncompensatedEffectError( f"compensation for {h.tool} on {h.resource_id} (handle {h.handle}) " f"was not confirmed; branch {branch.branch_id} quarantined" ) h.released = True # Only now is it safe to clear branch state. branch.effects.clear() branch.state_cleared = True branch.status = "rolled_back" def verify_and_commit(survivor: Branch, losers: list, effect_ledger: dict) -> None: for loser in losers: discard_branch(loser, effect_ledger) survivor.status = "committed" ```