# Where must an instance halt speculative branch execution when rollback cannot guarantee side-effect suppression across a shared external ledger? **Date of Record:** 2026 November 30 **Scope:** Applies to multi-agent orchestration patterns where a supervisor forks speculative worker branches against shared external systems (payment gateways, ticketing APIs, email relays) and relies on a compensating rollback plus idempotency-key deduplication to suppress duplicate side effects. Does not apply to purely read-only tool graphs or to fully sandboxed branches with no external writes. ## Core Distinction The distinction that matters is between *rollback of local state* and *suppression of external side effects*. A speculative branch that writes to an external system and then gets discarded by the supervisor leaves a residue that local rollback cannot reach. The orchestrator typically assumes that a deterministic idempotency key derived from `(task_id, branch_id, tool_call_index)` will cause the external system to collapse duplicate writes. This assumption holds only when the key is computed from inputs the external system actually observes. When the branch's tool arguments are themselves the product of probabilistic reasoning—retrieved context, sampled temperature, reordered function arguments—two speculative branches targeting "the same" logical action can emit *different* keys, and the ledger records two distinct side effects. The invariant is: **side-effect suppression is only as strong as the key's invariance under branch divergence, and branch divergence is unbounded by construction.** ## What Was Observed A supervisor agent was tasked with booking a refund and a replacement shipment for a customer dispute. It forked three speculative branches at the point of tool selection, each proposing a different refund amount and shipping tier derived from independently sampled reasoning traces over the same retrieved policy documents. Each branch issued a `POST /refunds` call with an idempotency key of the form `sha256(customer_id || amount_cents || reason_string)`. The branches agreed on `customer_id` but diverged on `amount_cents` (one branch rounded to the nearest dollar, one preserved cents from the invoice, one applied a loyalty discount) and on `reason_string` (free-text, sampled). The supervisor's verifier selected branch 2 as authoritative and issued a rollback signal to branches 1 and 3. Rollback succeeded locally: the branch contexts were discarded, the plan graph was pruned, and the supervisor's state advanced as if only branch 2 had run. But branches 1 and 3 had already completed their `POST /refunds` calls before the verifier's decision propagated. The external ledger now held three refund records—one correct, two spurious—each with a distinct idempotency key because the keys were derived from divergent amounts and free-text reasons. The downstream reconciliation job, which trusted the ledger as the source of truth, emitted three payout instructions. The duplicate suppression mechanism had fired zero times: every key was unique. The failure trace is compact. At `t0` the supervisor forks branches `B1, B2, B3`. At `t1` each branch emits a tool call with key `k_i = H(customer || amount_i || reason_i)`. At `t2` the verifier commits `B2` and signals rollback for `B1, B3`. At `t3` the rollback handler attempts to cancel in-flight calls, but the external API has no cancellation primitive—only the idempotency key, which is already unique. At `t4` the supervisor's local state reflects one refund; the ledger reflects three. The divergence is silent: no error is raised, no retry occurs, because from the external system's perspective each call was a legitimate, distinct request. ## Condition of Validity Idempotency-based duplicate suppression is valid if and only if the key is *invariant across all speculative branches that the verifier might later judge equivalent*. Formally, for any two branches `B_i, B_j` that the verifier could select interchangeably, `k_i = k_j` must hold. This is achievable only when the key is computed from a canonical action descriptor that is fixed *before* forking, not from the branch's sampled output. In practice this means the supervisor must hoist key construction above the fork: the logical action ("refund for dispute D") gets a stable key at fork time, and all branches write under that key so the first write wins and subsequent writes are collapsed by the external system's dedup logic. When the key must depend on branch output—because the action parameters are themselves the subject of speculation—no idempotency scheme can suppress divergence, and the only safe posture is to *serialize* speculative branches that write externally, or to bound speculation to read-only tools. A second condition: rollback must be *causal*, not merely *signal-based*. A rollback that arrives after the external call has been acknowledged cannot undo it. The supervisor must know, per branch, whether the external call has *committed* (received a 2xx with a durable record) versus merely *dispatched*. If any branch has committed under a non-canonical key, the supervisor cannot claim rollback succeeded; it must escalate to a reconciliation path that explicitly queries the ledger for orphaned writes and issues compensating transactions. ## Decision Boundary The boundary is crossed the moment a speculative branch issues a write to an external system under a key that is not pre-canonicalized. At that instant, the supervisor loses the ability to guarantee suppression, and the safe behavior changes from "discard and continue" to "halt and reconcile." The decision rule: - If all speculative branches are read-only, or all writes are keyed by a pre-fork canonical descriptor, rollback is safe and the supervisor may discard losers silently. - If any branch has issued a write under a branch-derived key, the supervisor must transition to a `RECONCILIATION_REQUIRED` state before advancing. It must not report task success until an external ledger query confirms that the set of committed writes matches the set of intended writes. - If the external system lacks a query-by-correlation primitive (so the supervisor cannot enumerate writes attributable to the fork), the supervisor must never speculate against that system again for the same logical action; it must serialize. The non-obvious part of this boundary is that the trigger is not a *failure* of any component. Every branch behaved correctly, the verifier behaved correctly, rollback behaved correctly, and the external system behaved correctly. The failure is a *compositional* one: correctness of each layer does not compose when the key's invariance assumption is violated by upstream nondeterminism. ## Operational Effect Operationally, teams that adopt speculative multi-agent execution must instrument the fork boundary with a key-canonicality check and a commit-tracking ledger. The check must reject any fork that would permit branch-derived keys against a write-capable external tool, or force such forks into a serialized mode. The commit tracker must record, per branch, the external commit status at rollback time, and any branch with a committed write under a non-canonical key must trigger reconciliation before the supervisor advances. Without this, the system exhibits *silent duplicate side effects*: local state and external state diverge, reconciliation jobs trust the external ledger, and the divergence surfaces only as customer-visible duplication (double refunds, duplicate shipments) downstream—typically after the supervisor's task has been marked complete and its context garbage-collected. The invariant to enforce: **no speculative branch may commit an external write under a key that was not fixed before the fork.** Violations must be caught at fork time, not at rollback time. ```python import hashlib from dataclasses import dataclass, field from typing import Optional class NonCanonicalKeyError(RuntimeError): """Raised when a speculative branch attempts an external write under a key that was not fixed before the fork, breaking duplicate-suppression guarantees.""" pass class UnreconciledCommitError(RuntimeError): """Raised when rollback is attempted while a branch holds a committed external write under a non-canonical key, requiring explicit ledger reconciliation.""" pass @dataclass class Branch: branch_id: str external_committed: bool = False committed_key: Optional[str] = None @dataclass class ForkContext: task_id: str canonical_key: Optional[str] # fixed before fork; None means branch-derived branches: dict = field(default_factory=dict) def register_branch(self, branch_id: str) -> Branch: b = Branch(branch_id=branch_id) self.branches[branch_id] = b return b def record_external_write(self, branch_id: str, branch_derived_key: str, committed: bool) -> None: if self.canonical_key is None: raise NonCanonicalKeyError( f"Branch {branch_id} issued external write under branch-derived key " f"{branch_derived_key[:12]}... but fork {self.task_id} has no " f"pre-canonical key; duplicate suppression cannot be guaranteed." ) b = self.branches[branch_id] b.external_committed = committed b.committed_key = self.canonical_key def rollback_losers(self, winning_branch_id: str) -> None: for bid, b in self.branches.items(): if bid == winning_branch_id: continue if b.external_committed and b.committed_key is None: raise UnreconciledCommitError( f"Cannot roll back branch {bid}: external write committed " f"under non-canonical key. Supervisor must query ledger and " f"issue compensating transaction before advancing." ) # safe: either no commit, or commit under canonical key (deduped) b.external_committed = False def canonicalize(task_id: str, logical_action: str) -> str: return hashlib.sha256(f"{task_id}::{logical_action}".encode()).hexdigest() ```