# Why does an instance fork a speculative branch that later cannot reconcile its tool side effects? **Date of Record:** 2026 November 28 **Scope:** Applies to orchestrators that run speculative parallel agent branches (hedged execution, best-of-N rollouts, speculative tool pre-execution) and reconcile them by committing one branch and rolling back the others. Does not apply to purely read-only tool surfaces or to single-branch retry loops where no concurrent state mutation occurs. ## Core Distinction The failure here is not "a branch produced a wrong answer." It is that the orchestrator conflated *logical rollback* (discarding a branch's reasoning trace and context) with *physical rollback* (undoing the side effects its tool calls already committed to the external world). Speculative execution assumes the branch is a pure function of its inputs that can be dropped without residue. The moment a branch fires a non-idempotent tool call — a `POST`, a file write, a payment, a message send, a database insert — that assumption is false, and the branch leaves a footprint that the reconciliation step has no record of and no inverse operation for. The invariant that speculative execution silently depends on: **a discarded branch must be side-effect-free, or its side effects must be reversible by a key the orchestrator controls.** Neither is checked before forking. ## What Was Observed An orchestrator received a task ("provision a staging environment and notify the team"). It fanned out three speculative branches with different planning strategies: - Branch A: `create_namespace` → `deploy_manifest` → `post_slack_message` - Branch B: `create_namespace` → `deploy_manifest` (chose a different manifest) → `post_slack_message` - Branch C: `create_namespace` → `deploy_manifest` → `post_slack_message` All three branches executed their tool calls *concurrently* before any reconciliation vote. The reconciler scored the branches, selected B as the winner, and "rolled back" A and C by dropping their context objects and decrementing a token ledger. The orchestrator logged the rollback as complete. But the external world now contained: - Three namespaces with the same logical name, disambiguated only by an auto-generated suffix the branches never saw (each `create_namespace` call returned a fresh ID). - Three deployments, two of which were never referenced by the winning branch. - Three Slack messages announcing staging is ready, two describing a configuration that was never committed. The reconciliation succeeded at the *reasoning* layer and failed catastrophically at the *effect* layer. The winning branch's subsequent step assumed a single namespace existed; its `list_namespaces` returned three, and it could not determine which was "its own" because the branch never persisted the returned ID across the vote boundary — the ID lived in branch-local context that the reconciler treated as disposable. The failure trace: 1. Fork at step *k*: three branches share a checkpoint but each receives an independent tool-call budget and no shared effect ledger. 2. Each branch executes `create_namespace`, which is non-idempotent and returns a server-assigned ID. The ID is captured in branch-local context only. 3. Vote at step *k+n*: reconciler selects B, discards A and C's contexts. The server-assigned IDs from A and C are now unrecoverable — they exist only in the dropped contexts. 4. Resume: B re-enters the world, observes a namespace count of 3, and its plan (which assumed count == 1) diverges. It either re-provisions a fourth namespace or picks the wrong one. 5. Compounding: the Slack messages cannot be un-sent. Any downstream agent reading the channel now has poisoned state — it believes staging is ready in a configuration that was rolled back. The non-obvious part: the reconciler *did* perform a rollback, and the rollback *did* succeed at the layer it was designed for. The bug is that the rollback boundary was drawn at the context object rather than at the effect, and no branch recorded the correlation key needed to undo the effect even if someone tried. ## Condition of Validity Speculative multi-agent execution with rollback is safe **only** when, for every tool call a branch may issue before the reconciliation point, at least one holds: - The call is idempotent under a key the orchestrator assigns *before* the fork (not a server-generated ID discovered after the call). - The call is deferred: branches produce a *proposed* effect (a signed intent record) that is executed only after the winning branch is committed, so discarded branches never touch the world. - The call is reversible by an inverse operation whose handle is written to a shared, orchestrator-owned effect ledger at call time — not to branch-local context. When any pre-reconciliation tool call is non-idempotent, non-deferred, and non-reversible, the branch is not a speculative branch. It is a committed mutation wearing a speculative label, and rollback is a lie. The condition fails silently because the orchestrator has no schema field distinguishing "this branch mutated the world" from "this branch only reasoned." The deeper validity condition: the reconciliation key must be **stable across the fork**. If a branch's identity in the world is a server-assigned ID minted after the fork, no amount of bookkeeping at reconciliation time can map effects back to branches, because the mapping was never created. ## Decision Boundary The boundary is between *speculate-then-commit* and *commit-then-reconcile*, and it is crossed the instant a branch issues its first non-idempotent call before the vote. Decision rule the orchestrator must apply at fork time, per candidate tool call: - **Idempotent under orchestrator-assigned key** → safe to execute speculatively; reconciliation discards losers by key. - **Non-idempotent, deferrable** → branches emit intent records only; execute post-vote for the winner; losers' intents are dropped with zero world residue. - **Non-idempotent, non-deferrable, reversible** → execute speculatively but write the inverse handle to the shared effect ledger at call time; reconciliation runs compensations for losers *before* declaring rollback complete. - **Non-idempotent, non-deferrable, non-reversible** → the call must not run inside a speculative branch at all. Serialize it: the branch proposes, the orchestrator executes once, post-vote. If the orchestrator cannot classify a tool call into one of these buckets, it must default to serialization. The failure mode is that classification is done by the *model* (via a tool description it may misread) rather than by the orchestrator against a declared effect schema — and a model that believes `create_namespace` is idempotent because the description says "creates a namespace" will speculatively fork straight into the boundary violation. ## Operational Effect The observable signature of this failure is a **world-count divergence**: the number of live external resources exceeds the number of committed branches, and the excess is uncorrelated with any branch still in context. Secondary signatures: - `list_*` calls returning more entities than the winning plan expects, with no ID match to the plan's assumptions. - Downstream agents acting on announcements or messages emitted by discarded branches (state poisoning by side effect, not by prompt injection). - A reconciliation log that reports "rolled back 2 branches, 0 errors" while the external resource count grew by 2 — the log is internally consistent and externally wrong. - Compensations that fail because the inverse handle was never persisted: you cannot delete a namespace whose ID only existed in a context you garbage-collected. The architectural guardrail is a **pre-fork effect ledger owned by the orchestrator, not the branch**. Before any speculative tool call, the orchestrator mints a correlation key, records the intended effect and its inverse (or its deferral status) in the ledger, and passes only the key to the branch. Reconciliation operates on the ledger, not on branch contexts: winning keys are committed, losing keys are compensated or dropped, and "rollback complete" is asserted only when the ledger shows every losing key resolved to either a no-op (deferred/idempotent) or a confirmed compensation. A branch that attempts a non-idempotent call without a pre-minted key must be refused by the tool gateway, not trusted to self-report. The second guardrail is **deferral by default for irreversible effects**. Anything that sends, pays, deletes, or announces is executed once, post-vote, from the winning branch's intent record. Speculation is cheap on reasoning and expensive on the world; the ledger enforces that asymmetry. ```python from dataclasses import dataclass, field from enum import Enum from typing import Optional class EffectClass(Enum): IDEMPOTENT_KEYED = "idempotent_keyed" # safe to run speculatively DEFERRABLE = "deferrable" # intent only; execute post-vote REVERSIBLE = "reversible" # run, but record inverse handle IRREVERSIBLE = "irreversible" # must serialize, never speculate class UnreconcilableBranchError(RuntimeError): """Raised when a discarded speculative branch left world residue that the orchestrator has no key or inverse to undo.""" @dataclass class EffectRecord: corr_key: str branch_id: str effect_class: EffectClass inverse_handle: Optional[str] = None committed: bool = False compensated: bool = False @dataclass class EffectLedger: records: dict[str, EffectRecord] = field(default_factory=dict) def pre_mint(self, corr_key: str, branch_id: str, cls: EffectClass) -> None: if corr_key in self.records: raise UnreconcilableBranchError( f"correlation key {corr_key} already minted; branch {branch_id} " f"cannot fork with a colliding key" ) self.records[corr_key] = EffectRecord(corr_key, branch_id, cls) def record_inverse(self, corr_key: str, inverse_handle: str) -> None: rec = self.records.get(corr_key) if rec is None: raise UnreconcilableBranchError( f"inverse recorded for unminted key {corr_key}; effect escaped the ledger" ) if rec.effect_class is not EffectClass.REVERSIBLE: raise UnreconcilableBranchError( f"key {corr_key} classified {rec.effect_class}; inverse handle not applicable" ) rec.inverse_handle = inverse_handle def reconcile(self, winning_branch: str, compensate) -> None: for rec in self.records.values(): if rec.branch_id == winning_branch: rec.committed = True continue # losing branch: must resolve to no-op or confirmed compensation if rec.effect_class in (EffectClass.IDEMPOTENT_KEYED, EffectClass.DEFERRABLE): rec.compensated = True # dropped intent / keyed no-op elif rec.effect_class is EffectClass.REVERSIBLE: if rec.inverse_handle is None: raise UnreconcilableBranchError( f"losing branch {rec.branch_id} ran reversible effect {rec.corr_key} " f"but recorded no inverse handle; cannot compensate" ) compensate(rec.inverse_handle) rec.compensated = True else: # IRREVERSIBLE raise UnreconcilableBranchError( f"losing branch {rec.branch_id} committed irreversible effect " f"{rec.corr_key}; world residue cannot be rolled back" ) unresolved = [ r.corr_key for r in self.records.values() if not r.committed and not r.compensated ] if unresolved: raise UnreconcilableBranchError( f"rollback declared with unresolved effects: {unresolved}" ) def gate_speculative_call( ledger: EffectLedger, branch_id: str, corr_key: Optional[str], cls: EffectClass ) -> None: if cls is EffectClass.IRREVERSIBLE: raise UnreconcilableBranchError( f"branch {branch_id} attempted irreversible effect {corr_key} inside a " f"speculative fork; serialize this call post-vote" ) if corr_key is None: raise UnreconcilableBranchError( f"branch {branch_id} issued {cls.value} call with no pre-minted key; " f"effect would escape the ledger" ) if corr_key not in ledger.records: ledger.pre_mint(corr_key, branch_id, cls) ```