# Where must an instance reconcile speculative branches before committing shared state, and what breaks when it does not **Date of Record:** 2026 November 29 **Scope:** Applies to multi-agent systems that execute speculative branches (parallel hypothesized plans, tool-call fan-outs, or counterfactual rollouts) against a shared mutable substrate and must reconcile divergent branch effects into one commit. Does not apply to read-only fan-out (map/reduce over immutable inputs) or to single-agent speculative decoding, where no cross-branch state merge occurs. ## Core Distinction Speculative execution in agent swarms is usually framed as a throughput optimization: spawn N branches, keep the first that satisfies a verifier, discard the rest. The non-obvious failure is that **discard is not free**. Each speculative branch, by the time it is judged, has typically emitted *side effects* — tool calls that mutated a scratch store, appended to an episodic log, acquired a lease, or advanced a cursor. The boundary that matters is not "which branch won" but "which branch's *effects* are admissible into the commit set given that the branch's *reasoning* was provisional." The sharp invariant: **a branch's effects may only be committed if the branch's terminal reasoning state is causally consistent with the effects it emitted.** Most systems enforce a weaker invariant — "the winning branch's outputs are committed" — and thereby commit effects that were produced under a premise the system has since abandoned. This is *speculative effect leakage*: the commit set contains mutations whose generating justification was rolled back, but the mutations themselves were not. ## What Was Observed A planner agent decomposed a task into three candidate plans, dispatching each to a worker as a speculative branch against a shared scratch workspace (a keyed document store with per-branch write namespaces and a shared read view). Branches A, B, C ran concurrently. The verifier scored branch B highest and issued a rollback signal to A and C. The rollback was implemented as a *namespace drop*: A and C's write namespaces were deleted, and their episodic logs were marked `rolled_back`. But two effects escaped the namespace: 1. Branch A had, mid-execution, called a `reserve_slot` tool that wrote a reservation into a **shared** index (not the branch namespace), because the tool's contract did not require a namespace argument — it keyed on task ID. 2. Branch C had appended a derived fact to the **semantic memory tier** (`"resource X is exhausted"`) via a distillation step that ran before the rollback signal arrived, on the assumption that its branch would be the survivor. On commit of B, the system produced a state where B's plan assumed resource X was available (it had re-derived availability from the base snapshot, which predated C's write), the shared index held a reservation for a slot B never intended to use, and semantic memory asserted X was exhausted. The next task run retrieved the distilled fact, refused to use X, and deadlocked against the live reservation. No single component was wrong; the *reconciliation boundary* was. The failure trace, precisely: - `t0`: base snapshot S0 published to all branches; read view pinned at S0. - `t1`: A emits `reserve_slot(X)` → shared index (escapes namespace). - `t2`: C distills `exhausted(X)` → semantic tier (escapes namespace, tier is append-only and not branch-scoped). - `t3`: verifier selects B; rollback signal dispatched to A, C. - `t4`: A, C namespaces dropped; logs marked rolled_back. Shared index and semantic tier untouched. - `t5`: B commits its plan + effects. Commit set is internally inconsistent with the *observable* shared state. - `t6`: subsequent retrieval surfaces `exhausted(X)`; planner refuses X; reservation on X never released because its owning branch is gone. The invariant violated at `t4`: **rollback must be effect-complete with respect to any store reachable by a branch's tools, not merely namespace-complete.** The system conflated "branch is dead" with "branch's effects are dead." ## Condition of Validity The namespace-drop rollback is valid only under a conjunction that is rarely checked: 1. **Effect locality**: every tool a branch may call writes exclusively into the branch's namespace, OR declares a compensation handle at call time. The `reserve_slot` tool violated this — it had no compensation contract, so its effect was un-rollbackable by construction. 2. **Tier isolation**: no branch may write to a tier that outlives the branch (semantic memory, shared indices, external systems) before the branch is *committed*, only *selected*. The distillation at `t2` violated this: distillation is a commit-time operation masquerading as a branch-local one. 3. **Snapshot monotonicity**: the verifier's decision is made against a snapshot that is causally prior to all branch effects. Here it held — but only because B re-derived from S0; had B read the shared index after `t1`, B's winning plan would itself have been contaminated by a branch it was supposed to be independent of. When any conjunct fails, the rollback is *partial*, and partial rollback in a shared substrate is strictly worse than no speculation: it produces state that no branch would have produced alone and that no branch's reasoning can explain. ## Decision Boundary The operative question at each branch termination is not "commit or discard the branch's outputs" but a two-axis decision: - **Axis 1 — effect reachability**: is every effect the branch emitted confined to a store that the rollback primitive can actually revert? If not, the branch is *not speculatable* and must be run serially or under a compensating-transaction wrapper. - **Axis 2 — reasoning freshness**: is the branch's terminal reasoning state derived from a snapshot that excludes all sibling effects? If a branch read shared state that a sibling mutated, its conclusion is *cross-contaminated* and cannot be trusted as an independent vote — the verifier's comparison is invalid. The boundary rule: **a branch may be speculatively executed only if it is effect-confined AND snapshot-isolated; otherwise it must be demoted to serial execution or wrapped in compensation.** The system observed here enforced neither, so its speculative tier was silently unsound — it produced correct results most of the time because most tools happened to be namespace-local and most branches happened not to distill. The failure was latent until a tool escaped the namespace and a distillation landed in the same window. ## Operational Effect The observable consequence is *commit-set incoherence*: a committed state whose components were each locally valid but globally contradictory, with no branch's log able to explain the contradiction because the explaining branch is marked `rolled_back` and its effects are orphaned. Recovery requires reconciliation, not rollback — a sweep that, for every effect in a shared store, checks whether its owning branch is committed, and if not, invokes the effect's compensation handle or quarantines the effect. Where no compensation handle exists (the `reserve_slot` case), the effect is *unreconcilable* and must be surfaced as an explicit debt, never silently retained. The architectural guardrail that bounds this: **every branch-scoped tool must return a compensation handle at call time, and every shared-tier write must be gated on branch commit, not branch selection.** A branch that cannot supply a compensation handle for an effect is not eligible for speculative execution — it is a serialization point. This converts the failure from a silent incoherence into a loud, pre-execution refusal, which is the only place it can be cheaply caught. ```python class SpeculativeReconciliationError(RuntimeError): """Raised when a speculative branch's effects cannot be admitted to the commit set.""" def reconcile_branch_effects(branch, shared_stores): """ Admit a selected branch's effects into the commit set, or refuse. Enforces: effect-confined AND snapshot-isolated AND compensation-backed. """ if not branch.snapshot_isolated: # Branch read a sibling's mutation; its reasoning is contaminated. raise SpeculativeReconciliationError( f"branch {branch.id} is snapshot-contaminated: read shared state " f"mutated after S0; cannot admit as independent vote" ) for effect in branch.emitted_effects: store = shared_stores.get(effect.store_name) if store is None: raise SpeculativeReconciliationError( f"branch {branch.id} emitted effect to unknown store " f"{effect.store_name!r}" ) if store.is_branch_namespaced(effect): # Effect is confined; namespace drop on rollback is sufficient. continue # Effect escaped the branch namespace. It is admissible only if the # branch is committed AND the effect carries a compensation handle. if not branch.committed: raise SpeculativeReconciliationError( f"branch {branch.id} is not committed but emitted un-namespaced " f"effect {effect.id} to shared store {effect.store_name!r}; " f"rollback by namespace drop cannot revert it" ) if effect.compensation_handle is None: # Unreconcilable: surface as debt, never silently retain. raise SpeculativeReconciliationError( f"branch {branch.id} committed un-namespaced effect {effect.id} " f"with no compensation handle; state is unreconcilable and must " f"be quarantined as explicit debt, not committed" ) effect.apply_compensation_guard() return branch.commit_set() ```