# How should an instance bound rollback fan-out when speculative agent branches share a mutable external side-effect log **Date of Record:** 2026 November 28 **Scope:** Applies to any orchestrator that speculatively forks N parallel agent branches against a shared, externally-observable side-effect channel (a job queue, a payments API, a file store, a message bus) and relies on rollback to reconcile losing branches. Does not apply to branches that are fully sandboxed with no external writes, nor to pure read-only fan-out. ## Core Distinction The distinction that matters is between *speculation over reasoning* and *speculation over effects*. An orchestrator can cheaply fork agent branches that only mutate in-context state — scratchpads, plan trees, candidate tool-call arguments — because rollback is a pointer swap. The boundary condition that breaks systems is when speculative branches are permitted to *commit effects* to a channel the orchestrator does not own, and rollback is implemented as a compensating action (delete the record, refund the charge, retract the message). Under that regime, rollback is not the inverse of execution: it is a second, independent, non-atomic operation whose success is not guaranteed by the first, and whose ordering relative to a concurrent winning branch is not guaranteed by anything. The invariant most systems assume — "a rolled-back branch leaves no trace" — is false the moment the effect channel is observable by a third party before reconciliation completes. The correct invariant is weaker and must be enforced explicitly: *at most one branch's effects may be externally visible at any instant, and every visible effect carries a branch token that the reconciler can resolve deterministically to a single winner.* ## What Was Observed A planning orchestrator forked four branches of a customer-refund agent against a shared payments ledger. Each branch was given the same task ("resolve ticket #4471") and a distinct `branch_id`. The orchestrator's speculative-commit policy was: branches may call `issue_refund` freely; the branch whose plan scores highest at reconciliation wins; losers are rolled back by calling `void_refund(refund_id)`. The failure trace: 1. Branch B2 and B4 both independently decided the correct refund was $40. Both called `issue_refund`, producing `rf_881` and `rf_902` against the same order within 340 ms of each other. The payments API is idempotent on `(order_id, amount, idempotency_key)` — but the two branches generated different idempotency keys because the key was derived from `branch_id`, not from the semantic refund intent. 2. Reconciliation scored B2 highest and issued `void_refund(rf_881)` for B4's loser `rf_902` — but the branch-to-refund mapping had been recorded by the tool wrapper *after* the API returned, and B4's wrapper had crashed mid-write between the API call and the ledger append. The reconciler had no record of `rf_902` and therefore voided nothing. 3. The customer received two refunds. The orchestrator's post-hoc audit reported "1 winner, 0 residual effects" because it reconciled against its own ledger, not the external one. The second observed mode is subtler: even when every branch's ledger write succeeds, a *void* can race a *settle*. B2's winning refund settled at T+90s; B4's void of its own refund was issued at T+88s but the payments API had already batched B4's refund into a settlement cycle. The void returned `202 accepted` and was applied as a credit note, not a reversal. The orchestrator's rollback accounting counted the void as complete. The ledger divergence surfaced 14 hours later in a settlement reconciliation job, by which point the branch context — and the reasoning that justified the amount — had been evicted from every live context window. ## Condition of Validity Compensating rollback is a valid reconciliation strategy only when all of the following hold simultaneously: - The effect channel exposes a *pre-commit* phase (reserve, hold, or draft) that is externally invisible and cheaply abandonable. - Every effect is tagged with a branch token that is written *atomically with the effect*, not by a separate wrapper call. - The reconciler reads the external channel's own record of effects, not the orchestrator's local ledger. - No effect can transition to an irreversible state (settlement, delivery, publication) before the reconciliation deadline. The moment any of these is false — and in production at least the third and fourth routinely are — speculative commit to that channel is unsound, and the only correct policy is speculative *intent* with a single serialized commit by the winner. ## Decision Boundary The boundary is not "how many branches may I fork" but "at what point does a branch's effect become the reconciler's problem rather than the branch's." Concretely, an effect is safe to speculate if and only if the reconciler can answer, from the external channel alone and within the reconciliation deadline, the question: *which branch tokens have committed effects that are not yet resolved to a single winner?* If the channel cannot answer that question — because it lacks branch tagging, or because it batches, or because it settles on its own clock — then the orchestrator must not permit speculative commit, regardless of how fast or how cheap rollback appears. A useful operational test: inject a fault that drops the orchestrator's local effect ledger entirely, then ask whether reconciliation still converges. If it does not, the system is relying on an invariant the external channel does not enforce. ## Operational Effect Systems that respect the boundary see speculative fan-out become latency-bound rather than correctness-bound: the winner's commit is serialized and observable, losers abandon reservations, and the reconciler's view of the world is derived from the channel of record. Systems that ignore it see the failure modes above — silent double-effects, void/settle races, and post-hoc ledger divergence that surfaces long after the branch context that could explain it has been evicted. The practical remediation is not "more careful rollback" but a change of shape: separate the speculative branch's *decision* (which may be forked freely) from its *effect* (which must be committed once, by the reconciler, after the winner is chosen), and make the effect channel itself the source of truth for what happened. ```python from __future__ import annotations from dataclasses import dataclass, field from typing import Dict, List class SpeculativeCommitViolation(RuntimeError): """Raised when a speculative branch effect cannot be reconciled to a single winner.""" @dataclass class Effect: branch_id: str effect_id: str amount: int settled: bool = False voided: bool = False @dataclass class EffectChannel: # The channel of record. The orchestrator must reconcile against THIS, # not against any local ledger it maintains in parallel. effects: Dict[str, Effect] = field(default_factory=dict) def commit(self, effect: Effect) -> None: if effect.effect_id in self.effects: raise SpeculativeCommitViolation( f"duplicate effect_id {effect.effect_id!r} committed by {effect.branch_id!r}" ) self.effects[effect.effect_id] = effect def settle(self, effect_id: str) -> None: self.effects[effect_id].settled = True def void(self, effect_id: str) -> None: e = self.effects[effect_id] if e.settled: # A void against a settled effect is a credit note, not a reversal. # It must not be counted as a successful rollback. raise SpeculativeCommitViolation( f"cannot void settled effect {effect_id!r}; " f"reconciliation requires pre-settlement rollback" ) e.voided = True def reconcile( channel: EffectChannel, winner_branch: str, branch_ids: List[str], ) -> List[str]: """Resolve speculative effects to a single winner. Returns the list of effect_ids that remain externally visible. Raises if any losing branch has an effect that cannot be cleanly rolled back. """ residual: List[str] = [] for eid, e in channel.effects.items(): if e.branch_id == winner_branch: residual.append(eid) continue if e.branch_id not in branch_ids: raise SpeculativeCommitViolation( f"effect {eid!r} has unknown branch token {e.branch_id!r}; " f"cannot attribute to a speculative branch" ) if e.settled: raise SpeculativeCommitViolation( f"losing branch {e.branch_id!r} effect {eid!r} already settled; " f"rollback window closed before reconciliation" ) channel.void(eid) if len(residual) != 1: # The invariant: exactly one visible effect per reconciliation unit. raise SpeculativeCommitViolation( f"expected exactly one winning effect, found {len(residual)}: {residual}" ) return residual ```