# What structural signals indicate rollback divergence in speculative multi-agent branch execution **Date of Record:** 2026 December 3 **Scope:** Applies to orchestrated agent systems that speculatively fork a shared reasoning context across N parallel executors, run divergent tool calls, and roll back losing branches by restoring a checkpointed state. Does not apply to purely sequential single-agent loops or to stateless request/response inference. ## Core Distinction The failure mode is not "a branch returned a wrong answer." It is that a *rollback* silently failed to restore the state the surviving branch assumed it inherited. Speculative branch-and-rollback relies on a checkpoint being a complete, self-contained snapshot of agent state: conversation prefix, tool-call ledger, scratchpad memory, and any side-effect markers. The non-obvious boundary is that **tool outcomes are not part of the checkpoint** — they are external, non-deterministic, and frequently write to shared resources (files, databases, remote APIs) that the checkpoint cannot rewind. So there are two classes of divergence. *Soft divergence* is a branch producing a different token sequence — recoverable by discarding the branch's context. *Hard divergence* is a branch producing an external side effect (a POST, a file write, a queue enqueue) that survives rollback and contaminates every sibling branch that shares the same resource namespace. The structural signal that distinguishes them is whether the branch's tool-call ledger contains any write-class operation whose effect is observable by a sibling *after* the rollback barrier fires. ## What Was Observed A three-way speculative executor forks at a planning node. Branch A calls `search_docs`, Branch B calls `create_ticket`, Branch C calls `search_docs` with a rephrased query. The orchestrator selects Branch A on a confidence score and rolls back B and C. The rollback restores the context prefix and the scratchpad, but the ticket created by Branch B persists in the issue tracker. Ten steps later, Branch A's continuation calls `list_open_tickets`, sees the orphaned ticket, and treats it as evidence that a prior step already filed the issue — because *from the surviving context's perspective, the ticket's existence is unexplained but authoritative*. The agent then skips filing, and the task completes with a phantom reference to a ticket whose creation it never witnessed. The structural signal here is a **ledger asymmetry**: the tool-call ledger after rollback contains entries the restored context did not author. The context prefix says "no tickets filed"; the external world says "one ticket filed." Any agent that reconciles by trusting the world over its own ledger will silently adopt the orphan. Any agent that trusts the ledger over the world will double-file. Both are wrong, and the system has no signal that it is in this state unless the rollback barrier explicitly diffs external observations against the restored ledger. A second observed pattern: two branches both call `increment_counter` on the same key. Both succeed. Only one branch survives. The counter is now at 2, but the surviving branch's ledger records a single increment. The rollback is *contextually* clean and *semantically* corrupt. The signal is a **write-count mismatch** between the surviving branch's intended effect set and the resource's actual mutation count. ## Condition of Validity Rollback-based speculation is sound only under the invariant that every tool call is either (a) idempotent and keyed by a branch-scoped nonce, or (b) deferred until after branch selection. If a branch can perform a non-idempotent write before the selection barrier, the rollback is not a rollback — it is a context truncation with unresolved external residue. The condition of validity is therefore: ``` ∀ branch b, ∀ tool t invoked by b before selection: is_idempotent(t) ∧ keyed_by(t, nonce(b)) ∨ deferred(t) until after barrier ``` When this invariant is violated, the system must fall back to *compensating actions* (issue a delete, a reversal, a tombstone) rather than context restoration. Compensating actions are themselves tool calls with their own failure modes, so the fallback is strictly weaker than the invariant. The structural signal that you have crossed from speculatively-safe to compensatorily-unsafe territory is the presence of any write-class tool in a branch's ledger at the moment of rollback. ## Decision Boundary The decision is not "roll back or commit." It is "is this divergence soft or hard, and if hard, can it be compensated?" The boundary conditions: - **Soft divergence, clean ledger:** discard branch, restore checkpoint, proceed. No signal required. - **Hard divergence, idempotent writes with branch nonces:** discard branch, issue scoped deletes keyed by nonce, verify deletion, proceed. Requires a nonce-scoped cleanup tool to exist. - **Hard divergence, non-idempotent writes without nonces:** *do not roll back silently*. Escalate to a reconciliation step that surfaces the orphan to the surviving branch as an explicit, attributed fact ("Branch B created ticket #4471 before rollback; treat as pre-existing"). The surviving branch must be told, in-context, that the orphan exists and did not originate from its own reasoning. - **Hard divergence with un-compensable effects (sent emails, executed payments):** the speculation was invalid at fork time. The only correct action is to abort the fork tree and restart from the pre-fork checkpoint with write-class tools disabled for speculative branches. The structural signal that selects the third case over the second is the absence of a nonce-keyed cleanup path for the tool in question. If `create_ticket` has no `delete_ticket_by_nonce`, the branch is not speculatively safe regardless of how confident the selector is. ## Operational Effect Systems that implement this boundary correctly gain a measurable property: **rollback cost is bounded by the write-class tool surface, not by the branch count.** Speculation across read-only tools is free; speculation across write-class tools costs a compensation round-trip per orphan. Systems that skip the boundary exhibit a characteristic failure signature — phantom references, double-filed artifacts, and counters that drift by the number of discarded branches — that is invisible to per-branch evaluation because each branch, evaluated in isolation, looks correct. The corruption lives in the seam between the restored context and the un-restored world. The guardrail is a pre-fork audit: enumerate the tools reachable from the fork point, classify each as read-only, idempotent-write, or non-idempotent-write, and refuse to speculate if any non-idempotent-write is reachable without a compensation path. This audit is cheap, static, and catches the failure before the first token of the first branch is generated. ```python from dataclasses import dataclass, field from enum import Enum from typing import Callable class RollbackDivergenceError(RuntimeError): """Raised when a speculative branch's rollback leaves external residue that the restored context cannot reconcile.""" class ToolClass(Enum): READ_ONLY = "read_only" IDEMPOTENT_WRITE = "idempotent_write" NON_IDEMPOTENT_WRITE = "non_idempotent_write" @dataclass class ToolCall: tool: str tool_class: ToolClass nonce: str | None compensation: Callable[[], None] | None = None @dataclass class Branch: branch_id: str ledger: list[ToolCall] = field(default_factory=list) def audit_pre_fork(reachable_tools: dict[str, ToolClass]) -> None: """Refuse to speculate if any non-idempotent write lacks a compensation path.""" unsafe = [ name for name, cls in reachable_tools.items() if cls is ToolClass.NON_IDEMPOTENT_WRITE ] if unsafe: raise RollbackDivergenceError( f"Speculation unsafe: non-idempotent writes reachable without " f"compensation: {unsafe}. Disable write-class tools for speculative " f"branches or abort the fork." ) def rollback_branch(branch: Branch) -> list[str]: """Attempt to roll back a losing branch. Returns list of orphaned effects that could not be compensated and must be surfaced to the survivor.""" orphans: list[str] = [] for call in branch.ledger: if call.tool_class is ToolClass.READ_ONLY: continue if call.tool_class is ToolClass.IDEMPOTENT_WRITE and call.nonce: if call.compensation is None: raise RollbackDivergenceError( f"Branch {branch.branch_id}: idempotent write {call.tool} " f"has nonce but no compensation callable; cannot cleanly " f"roll back." ) call.compensation() continue # Non-idempotent or nonce-less write: cannot be undone. orphans.append(f"{call.tool}(nonce={call.nonce})") if orphans: raise RollbackDivergenceError( f"Branch {branch.branch_id} rollback left {len(orphans)} orphaned " f"external effects: {orphans}. Survivor must be re-prompted with " f"explicit attribution or the fork tree must be aborted." ) return orphans ```