# Where must an instance bound speculative rollback when parallel agent plans share a non-idempotent side-effect ledger **Date of Record:** 2026 November 26 **Scope:** Applies to orchestrators that fork parallel sub-agent plans speculatively (execute ahead of commit, reconcile on divergence) where at least one branch performs externally observable, non-idempotent effects. Does not apply to purely read-only speculation or to plans whose branches are fully idempotent and replay-safe. ## Core Distinction The failure is not "a speculative branch guessed wrong and was rolled back." That is the designed behavior. The failure is that **rollback is defined over agent state, but the observable world is mutated by effects that the rollback protocol cannot invert.** A speculative plan tree maintains two ledgers: an *intent ledger* (the agent's belief about what it has done, which rollback can truncate) and an *effect ledger* (what actually happened at external systems — emails sent, rows written, payments authorized — which rollback cannot truncate). The boundary condition appears when reconciliation decides to *abandon* a branch whose effects already escaped the sandbox but whose intent records are still present in a sibling branch that will now be *committed*. The commit does not know it is re-committing an effect the abandon path already materialized. The invariant that must hold: **for every effect that is non-idempotent, exactly one committed branch may own its emission, and the ownership token must be allocated before emission, not reconstructed at reconciliation.** When the token is reconstructed post-hoc from intent records, two branches can each believe they own the same emission, or neither can, and the reconciliation step silently picks one. ## What Was Observed A three-branch speculative fan-out: branch `A` plans "send customer notice," branch `B` plans "adjust account credit," branch `C` plans "reconcile ledger." All three fork from a shared checkpoint `S0`. Each branch buffers its tool calls as *proposed effects* in a local journal; a reconciler is supposed to select a consistent subset and commit. Branch `A` proposes `send_notice(id=4471)`. The reconciler, evaluating `A` against a peer branch's evidence, marks `A` as *diverged* (its premise — that the account is delinquent — is contradicted by `B`'s fresher read). The reconciler issues `rollback(A)`. But `A`'s tool executor had already *flushed* the notice to the mail relay: the flush was gated on a local pre-check, not on reconciler commit. `rollback(A)` truncates `A`'s intent journal and frees its checkpoint. The notice is out. The intent record is gone. Now `B` commits. `B`'s plan, having observed `A`'s shared-journal entry for `send_notice` *before* the truncation propagated (the reconciler truncates `A`'s journal but `B` had already snapshotted a read of the shared intent index at fork time), includes a compensating "ensure notice sent" step to maintain the invariant "if credit adjusted, customer must be notified." `B` emits `send_notice(id=4471)` again. The customer receives two notices for one credit adjustment. The reconciler's post-commit audit sees one intent record (`B`'s) and one effect (the mail relay's log shows two). Divergence is now *inside the committed state*, not in the abandoned branch. The trace, precisely: 1. `fork(S0) -> {A, B, C}`, shared intent index `I` snapshotted per branch at fork. 2. `A` flushes `send_notice` to relay (effect `e1`), writes `I[A] += send_notice`. 3. Reconciler reads `B`'s evidence, marks `A` diverged, calls `rollback(A)`. 4. `rollback(A)` truncates `I[A]`, frees `A`'s checkpoint. **Does not touch the relay.** 5. `B` commits. `B`'s plan step "ensure notice" reads its *fork-time snapshot* of `I`, which contains `A`'s `send_notice`, concludes the notice is already covered — OR, depending on ordering, concludes it must emit — and emits `e2`. 6. Commit audit: `I` has one `send_notice` (from `B`); relay has two effects. Invariant "one notice per adjustment" violated, undetected until external reconciliation. ## Condition of Validity The rollback-and-reconcile protocol is sound **only if** every non-idempotent effect is gated behind a commit token that is (a) allocated by the reconciler, (b) single-owner, and (c) checked at emission time against the reconciler's current ownership map — not against a fork-time snapshot. The protocol is *invalid* whenever any of the following hold: - Effects can flush before reconciler commit (speculative side-effect leakage). - Branch plans read a fork-time snapshot of the shared intent index to decide whether an effect is "already covered" (stale coverage inference). - Rollback truncates intent without recording a *tombstone* of effects that escaped, so a later commit cannot see that the effect happened. - The reconciler's ownership map is reconstructed at commit from surviving intent records rather than maintained as an append-only allocation log. The last is the sharp one: if ownership is inferred from *what intent records survive*, then rollback — which deletes intent records — *deletes ownership evidence*, and the surviving branch's inference about coverage is made against a hole. ## Decision Boundary An instance must **not** treat rollback as a compensating action for escaped effects. Rollback is a state-truncation primitive; it has authority over the intent ledger and none over the effect ledger. The decision boundary is: - **Effect not yet flushed** → rollback may discard the proposal. Safe. - **Effect flushed, idempotent, with a stable idempotency key** → rollback may discard the proposal; a later commit re-emitting with the same key is absorbed by the downstream. Safe, provided the key is derived from plan-invariant identity, not from branch-local counters. - **Effect flushed, non-idempotent, no pre-allocated commit token** → rollback is *not* a valid recovery. The instance must escalate to explicit compensation (emit an inverse effect) or halt. It must never let a sibling branch infer coverage from a truncated index. The guardrail: before any effect is emitted, the branch must acquire a commit token from the reconciler's append-only allocation log. The token is the *only* thing that authorizes emission. Rollback revokes tokens but writes a **tombstone** (`effect_id, branch, state=escaped|revoked`) that survives truncation. Commit-time coverage inference reads the allocation log, never the intent index. A sibling branch that would emit a duplicate must first check the allocation log for an existing token on the same effect identity; if a tombstone with `state=escaped` exists, the sibling must *not* re-emit and must instead surface the escaped effect to the reconciler for compensation decision. ## Operational Effect With the tombstone-and-token discipline, the observed double-notice becomes impossible: `A` acquires token `T1` for `send_notice(4471)` before flush; flush records `T1` as `escaped`. `rollback(A)` revokes `T1` and writes tombstone `T1: escaped`. `B`'s "ensure notice" step checks the allocation log, sees `T1: escaped`, and does not emit; it hands `T1` to the reconciler, which either accepts the single notice as the committed effect (and marks `T1` committed retroactively) or issues an explicit compensating retraction. The invariant "one notice per adjustment" is preserved by construction, not by audit. The cost is latency: every non-idempotent effect pays a synchronous token round-trip to the reconciler before emission, collapsing some speculation. That is the correct trade — speculation over non-idempotent effects without pre-allocated ownership is not speculation, it is an unlogged commit that the rollback protocol will later misdescribe. ```python from dataclasses import dataclass, field from enum import Enum from typing import Dict, Optional class SpeculativeRollbackError(RuntimeError): """Raised when a branch attempts to emit a non-idempotent effect without a reconciler-allocated commit token, or when commit-time coverage inference would re-emit an effect already marked escaped.""" pass class EffectState(Enum): PROPOSED = "proposed" ESCAPED = "escaped" REVOKED = "revoked" COMMITTED = "committed" @dataclass class AllocationLog: """Append-only ownership ledger. Survives branch rollback; tombstones escaped effects so sibling commits cannot infer coverage from a hole.""" entries: Dict[str, EffectState] = field(default_factory=dict) def allocate(self, effect_id: str, branch: str) -> str: if effect_id in self.entries: raise SpeculativeRollbackError( f"effect {effect_id} already allocated to " f"{self.entries[effect_id]}; branch {branch} cannot own it" ) token = f"{branch}:{effect_id}" self.entries[effect_id] = EffectState.PROPOSED return token def mark_escaped(self, effect_id: str) -> None: if self.entries.get(effect_id) != EffectState.PROPOSED: raise SpeculativeRollbackError( f"cannot mark {effect_id} escaped from state " f"{self.entries.get(effect_id)}" ) self.entries[effect_id] = EffectState.ESCAPED def revoke(self, effect_id: str) -> None: # Rollback revokes intent but MUST leave a tombstone, never delete. if effect_id not in self.entries: raise SpeculativeRollbackError( f"revoke of unknown effect {effect_id}" ) if self.entries[effect_id] == EffectState.PROPOSED: self.entries[effect_id] = EffectState.REVOKED # If already ESCAPED, tombstone stays ESCAPED — the effect happened. def commit(self, effect_id: str, branch: str) -> None: state = self.entries.get(effect_id) if state == EffectState.ESCAPED: # Accept the single escaped emission retroactively. self.entries[effect_id] = EffectState.COMMITTED return if state == EffectState.COMMITTED: raise SpeculativeRollbackError( f"double commit of {effect_id} by {branch}" ) if state in (EffectState.REVOKED, None): raise SpeculativeRollbackError( f"branch {branch} commits {effect_id} in state {state}; " f"no live token" ) self.entries[effect_id] = EffectState.COMMITTED def emit_non_idempotent(log: AllocationLog, effect_id: str, branch: str) -> None: state = log.entries.get(effect_id) if state is None: raise SpeculativeRollbackError( f"branch {branch} attempted to emit {effect_id} without an " f"allocated commit token; speculative flush is forbidden" ) if state == EffectState.ESCAPED: raise SpeculativeRollbackError( f"branch {branch} attempted to re-emit {effect_id} already " f"marked escaped; route to reconciler for compensation, do not " f"infer coverage from truncated intent index" ) if state != EffectState.PROPOSED: raise SpeculativeRollbackError( f"branch {branch} cannot emit {effect_id} in state {state}" ) log.mark_escaped(effect_id) def rollback_branch(log: AllocationLog, effect_ids: list[str]) -> None: for eid in effect_ids: log.revoke(eid) # tombstone preserved; never deletes # Reproduction of the observed double-notice under the fixed protocol. log = AllocationLog() log.allocate("send_notice:4471", branch="A") emit_non_idempotent(log, "send_notice:4471", branch="A") # A flushes rollback_branch(log, ["send_notice:4471"]) # revoke -> stays ESCAPED # Branch B's "ensure notice" step must now refuse to re-emit. try: emit_non_idempotent(log, "send_notice:4471", branch="B") except SpeculativeRollbackError as e: print(f"blocked duplicate: {e}") log.commit("send_notice:4471", branch="A") # single committed owner assert log.entries["send_notice:4471"] == EffectState.COMMITTED ```