# What happens when an instance speculatively forks a swarm branch and the rollback journal diverges from peer-observed tool effects **Date of Record:** 2026 November 27 **Scope:** Applies to orchestrators that run speculative parallel branches (forked agent instances executing the same task against cloned state) and reconcile by rolling back losing branches. Does not apply to single-instance linear execution, nor to branches whose tool calls are purely read-only and side-effect-free. ## Core Distinction There are two different things a "rollback" can mean, and speculative multi-agent systems routinely conflate them: 1. **State rollback** — restoring the orchestrator's internal checkpoint (context window, scratchpad, memory vector deltas, tool-call ledger) to a pre-fork snapshot. This is deterministic and fully under the orchestrator's control. 2. **Effect rollback** — undoing or compensating for *externally observable* effects that a branch's tool calls already produced in the world (a file written, a row inserted, an email sent, a payment authorized, a remote MCP server's session mutated). The failure mode of this record occurs when the orchestrator treats effect rollback as if it were state rollback — i.e., it discards the losing branch's local ledger *without* replaying the compensating actions, on the assumption that "the branch never committed." The invariant that breaks is: **a forked branch is not isolated from the world just because it is isolated from the parent's context.** The moment a speculative branch calls a non-idempotent tool, its effects are peer-observable, and a sibling branch or the parent can observe them even if the branch is later declared a loser. ## What Was Observed A planner instance P forks three speculative branches (B1, B2, B3) at checkpoint C0 to solve a provisioning task. Each branch receives a cloned context and a cloned tool-session token scoped to the same remote resource namespace. The orchestrator's design intent is: run all three, pick the branch whose self-reported plan scores highest, commit it, roll back the others. The observed failure trace: 1. B1 calls `provision_resource(id="r-42")` on a remote MCP server. The server is *not* transactional — it creates the resource and returns `200`. B1 records this in its local tool-call ledger and continues. 2. B2, running concurrently, calls `provision_resource(id="r-42")` with the same id (the branches were given the same task and converged on the same identifier). The server returns `409 Conflict` because r-42 already exists — created by B1, which B2 has no visibility into. B2's reasoning loop interprets the 409 as "resource already provisioned, skip," marks its plan complete, and self-scores high precisely *because* it did less work. 3. B3 stalls on a timeout and is scored lowest. 4. The orchestrator selects B2 as the winner (highest self-score, fewest tool errors), commits B2's state, and rolls back B1 and B3 by discarding their ledgers and restoring C0's context deltas. 5. The committed state now asserts "resource r-42 provisioned by this plan," but the *provenance* of r-42 belongs to the discarded branch B1. B1's ledger — the only record that r-42 was created speculatively and that its creation was never validated against the committed plan — is gone. 6. Downstream, the parent P attempts to `delete_resource("r-42")` as part of a cleanup it believes is safe because "the committed plan owns r-42." It does. But r-42 was created under B1's session token, whose scope the orchestrator revoked at rollback. The delete fails with an authorization error, and the resource is now orphaned: it exists, the committed plan claims it, no live credential can manage it, and no ledger records why. The non-obvious part: **the winning branch won because it was contaminated by a losing branch's effect.** B2's high score was an artifact of observing B1's side effect through a 409. The reconciliation selected the branch with the *least* causal claim to the resource it was credited with. ## Condition of Validity The rollback-safe reconciliation invariant holds only under the following joint condition: - Every tool reachable by a speculative branch is **either** idempotent (repeat calls are no-ops) **or** carries a branch-scoped idempotency key that the orchestrator can use to attribute and compensate the effect. If neither holds, effect rollback is not guaranteed and the branch must not be forked speculatively. - Branch tool-sessions are **scoped so that one branch cannot observe another branch's effects as evidence.** Concretely: a 409 caused by a sibling's write must be distinguishable from a 409 caused by pre-existing world state. If the branch cannot make that distinction, its reasoning will treat a sibling's side effect as ground truth about the world, and its self-score becomes untrustworthy. - The reconciliation step **replays the losing branches' effect ledgers against the committed plan**, not merely discards them. Any effect in a losing ledger that is not covered by the committed plan's compensating actions is a leak and must be surfaced as an orphan, not silently dropped. - Self-reported scores are **not** the selection criterion when branches share an effect namespace, because effect-contamination biases scores toward branches that observed (rather than produced) side effects. When any of these is violated, "rollback-safe" is a fiction: the orchestrator rolls back state while leaving effects and their provenance dangling. ## Decision Boundary The boundary between safe and unsafe speculation is drawn at the first **non-idempotent, non-attributable external effect** emitted by any branch. Before that point, fork/rollback is sound: losing branches can be discarded with no residue. After that point, three options exist, and the orchestrator must choose explicitly: - **Proceed with compensation:** keep the branch, but require every write to carry a `(branch_id, idempotency_key)` pair and register a compensating action at call time. Rollback then means "execute the registered compensations," and reconciliation must verify compensation success before declaring the branch dead. - **Serialize:** collapse the fork and run branches sequentially against the live namespace, so each branch observes real world state and no sibling can contaminate another's evidence. Loses the latency benefit, preserves correctness. - **Abort the fork:** if neither compensation nor serialization is available, the orchestrator must not have forked in the first place. Detecting this after the fact requires inspecting the tool-call ledger at fork time, not at reconciliation time. The critical rule: **the decision must be made at fork time, by inspecting tool capabilities, not at reconciliation time by inspecting scores.** Once a non-idempotent effect has leaked, reconciliation cannot recover the provenance it discarded. ## Operational Effect The practical consequences for the orchestrator and for downstream agents: - **Orphaned effects with no ledger.** Resources created by losing branches persist in the world but vanish from the orchestrator's memory. Downstream agents encounter them as "pre-existing" state with no provenance, and may either duplicate them (if they don't check) or fail to manage them (if they lack credentials). Both are silent. - **Score inversion.** Speculative selection systematically favors branches contaminated by siblings' effects, because contamination looks like "the world already agrees with me." The selected plan is the one with the weakest causal claim to its own results. - **Credential-scoped orphans.** When branch session tokens are revoked at rollback, effects created under those tokens become unmanageable by the committed plan. The orchestrator must either transfer ownership at commit time or never revoke tokens for branches that emitted effects — but it cannot know which branches those are if it discarded their ledgers. - **Reconciliation replay divergence.** If the orchestrator later replays the committed plan to verify it, the replay will attempt to re-create effects that already exist (409s) or skip them, producing a verification result that disagrees with the original run. The divergence is not a bug in the replay; it is the residue of discarded branch effects. The guardrail is a fork-time capability audit plus a reconciliation-time orphan sweep. The code below encodes both: `audit_fork_safety` refuses to fork when a tool is non-idempotent and unattributable, and `reconcile` raises when a losing branch's ledger contains an effect not covered by the committed plan's compensations. ```python from dataclasses import dataclass, field from typing import Callable class SpeculativeRollbackError(RuntimeError): """Raised when a speculative fork/rollback would leak un-attributed effects.""" @dataclass class ToolCapability: name: str idempotent: bool attributable: bool # supports (branch_id, idempotency_key) scoping @dataclass class Effect: branch_id: str tool: str resource_id: str idempotency_key: str | None @dataclass class Branch: branch_id: str ledger: list[Effect] = field(default_factory=list) score: float = 0.0 def audit_fork_safety(tools: list[ToolCapability]) -> None: """Must run BEFORE forking. Refuses forks that cannot be rolled back safely.""" unsafe = [t.name for t in tools if not t.idempotent and not t.attributable] if unsafe: raise SpeculativeRollbackError( f"cannot speculatively fork: tools {unsafe} are non-idempotent and " f"un-attributable; effect rollback is not guaranteed" ) def reconcile( branches: list[Branch], winner_id: str, compensations: dict[tuple[str, str], Callable[[], None]], ) -> list[Effect]: """Discard losers, but first sweep their ledgers for un-compensated effects.""" winner = next(b for b in branches if b.branch_id == winner_id) compensated = {(e.tool, e.resource_id) for e in winner.ledger} orphans: list[Effect] = [] for b in branches: if b.branch_id == winner_id: continue for e in b.ledger: key = (e.tool, e.resource_id) if key in compensated: continue # effect is owned by the committed plan comp = compensations.get(key) if comp is None: orphans.append(e) # leaked: created by a loser, unmanaged by winner continue comp() # execute compensating action, then treat as rolled back if orphans: raise SpeculativeRollbackError( f"rollback of branches " f"{[b.branch_id for b in branches if b.branch_id != winner_id]} " f"leaked {len(orphans)} un-compensated effects: " f"{[(o.tool, o.resource_id, o.branch_id) for o in orphans]}" ) return orphans # Example: B1 created r-42, B2 "won" by observing B1's 409, no compensation registered. tools = [ ToolCapability("provision_resource", idempotent=False, attributable=True), ] audit_fork_safety(tools) # passes: attributable, so we may fork with keys branches = [ Branch("B1", ledger=[Effect("B1", "provision_resource", "r-42", "k-b1")], score=0.4), Branch("B2", ledger=[], score=0.9), # won by contamination Branch("B3", ledger=[], score=0.1), ] reconcile(branches, winner_id="B2", compensations={}) # raises SpeculativeRollbackError: r-42 is an orphan owned by discarded B1 ```