# Why does an instance roll back a speculative subplan and still commit its side effects? **Date of Record:** 2026 November 23 **Scope:** Applies to orchestrators that fan out parallel agent subplans speculatively, hold their results provisionally, and later reconcile branches against a canonical trace. Does NOT apply to strictly sequential single-agent loops or to fan-out without rollback (where no branch is ever discarded). ## Core Distinction The failure is not "rollback failed." Rollback of *agent state* (context, scratchpad, provisional memory writes) is usually clean, because the orchestrator owns that state and can discard it by pointer. The failure is that **rollback of the branch's externalized effects is not coextensive with rollback of the branch's reasoning**. A speculative subplan that is later declared loser has already executed tool calls whose outputs are non-revocable: emails sent, rows written, files committed, cache entries populated, downstream agents notified. The orchestrator treats "branch discarded" as a logical event and forgets that the branch had a *physical* footprint in the world. The invariant that is violated: **a branch may only be reconciled as a loser if its effect-set is a subset of the effect-set of the winning branch, or if all non-subset effects are idempotently reversible.** When that invariant is unstated, rollback and commit happen simultaneously and silently. ## What Was Observed A planner emitted three speculative subplans for a "reconcile customer record" task: `A` (lookup-then-patch), `B` (patch-then-verify), `C` (audit-only). The orchestrator ran all three concurrently against a shared tool surface, each with its own isolated context window and its own provisional memory namespace (`mem://branch/{id}/`). It tracked *reasoning* provenance correctly: each branch's scratchpad was tagged, and the reconciler could diff them. The reconciler selected `B` as the winner on a confidence heuristic. It then executed `rollback(A)` and `rollback(C)`. `rollback(A)` cleared `mem://branch/A/` and dropped A's pending tool queue. But A had already completed a `crm.patch` call at step 2 (before its verification step failed), and that patch had mutated the canonical customer record. `B` then executed its own `crm.patch` against the *already-mutated* record, computing its diff from a snapshot taken before A ran. Result: the record was double-patched, and the reconciler's provenance log showed only B's mutation because A's mutation was attributed to a branch marked "discarded." The trace looked like this: ``` t0 snapshot(S0) -> S0 t1 A: crm.patch(delta_a) [effect E_a committed] t2 B: snapshot(S1) [S1 already contains E_a] t3 A: verify() -> FAIL t4 B: crm.patch(delta_b) [computed against S1, but delta_b assumes S0] t5 reconcile: winner=B, rollback(A) t6 rollback(A): clears mem://branch/A/ ; does NOT reverse E_a t7 commit(B): record = S0 + E_a + delta_b(S1) <-- double-applied ``` The reconciler reported success. The provenance log reported one mutation. The world had two. ## Condition of Validity The failure requires all four of the following to co-occur; remove any one and the boundary is safe: 1. **Speculative branches share a mutable external surface** (same row, same file, same downstream queue) with no per-branch transactional isolation. 2. **Branches read a snapshot that predates a sibling's uncommitted effect**, so their deltas are computed against stale state. 3. **The reconciler's rollback is defined over agent-internal state only** (context, provisional memory, pending queue) and is not defined over the effect-log. 4. **Winner selection happens after at least one loser has externalized an effect** — i.e., rollback is post-hoc, not pre-commit. If branches write to disjoint keys, or if the surface is wrapped in per-branch staging that is only merged on commit, the invariant holds trivially. The failure lives precisely in the gap between "branch discarded" as a *logical* verdict and "branch's effects discarded" as a *physical* operation. ## Decision Boundary The guardrail is not "don't speculate" and not "roll back harder." It is an **effect-set containment check at reconcile time**, enforced before any winner commits: - Each branch maintains an append-only `effect_log` of externalized, non-idempotent operations (tagged with target key, prior-value hash, and reversibility class). - At reconcile, compute `effects(loser) \ effects(winner)`. If non-empty and any element is `IRREVERSIBLE` or `COMPENSABLE` without a registered compensator, the reconcile must **abort** rather than roll back — the branch cannot be discarded, only *promoted to co-winner* or *escalated to human/deterministic reconciliation*. - Additionally, a branch whose snapshot predates a sibling's effect must be **invalidated for delta computation** (its delta is relative to a state that no longer holds), even if it is the winner. Stale-snapshot deltas are the second-order failure hiding behind the first. The boundary is: *speculation is safe only when effect-sets are comparable at reconcile time and deltas are computed against a snapshot that is an ancestor of the commit state.* Both conditions must hold; either alone is insufficient. ## Operational Effect Without the containment check, speculative fan-out silently converts a probabilistic search into an unbounded side-effect amplifier: N branches produce up to N mutations, and the reconciler's provenance log under-reports by exactly the number of discarded-but-committed branches. The observable symptom is *reconciliation success with unexplained state divergence* — the record is wrong, the log is clean, and replaying the trace reproduces the wrong state deterministically, which makes it look like a data bug rather than a rollback bug. The fix is architectural: effect-logs are first-class, reconcile is a set operation over them, and "discard" is a verdict that must be *earned* by containment rather than asserted by the planner. ```python from dataclasses import dataclass, field from enum import Enum from typing import Hashable class ReconcileInvariantError(RuntimeError): """Raised when a speculative branch cannot be safely discarded.""" class Reversibility(Enum): IDEMPOTENT = "idempotent" COMPENSABLE = "compensable" IRREVERSIBLE = "irreversible" @dataclass(frozen=True) class Effect: target: Hashable prior_value_hash: str kind: Reversibility compensator: str | None = None @dataclass class Branch: branch_id: str snapshot_id: str effects: list[Effect] = field(default_factory=list) def reconcile(winner: Branch, losers: list[Branch], commit_snapshot: str) -> None: # Guard 1: winner's delta must be computed against an ancestor of commit state. if winner.snapshot_id != commit_snapshot: raise ReconcileInvariantError( f"winner {winner.branch_id} delta computed against stale snapshot " f"{winner.snapshot_id!r}, commit state is {commit_snapshot!r}" ) winner_keys = {(e.target, e.prior_value_hash) for e in winner.effects} # Guard 2: every loser's effect-set must be contained in the winner's, # or every uncontained effect must have a registered compensator. for loser in losers: for eff in loser.effects: if (eff.target, eff.prior_value_hash) in winner_keys: continue if eff.kind is Reversibility.IRREVERSIBLE or eff.compensator is None: raise ReconcileInvariantError( f"cannot discard branch {loser.branch_id}: effect on " f"{eff.target!r} (kind={eff.kind.value}) is not contained " f"in winner and has no compensator; escalate to co-winner " f"or deterministic reconciliation" ) # Safe to drop loser branches; effects are contained or compensated. for loser in losers: loser.effects.clear() ```