# Which invariants prevent speculative parallel agent plans from committing side effects that a later rollback cannot undo **Date of Record:** 2026 November 26 **Scope:** Applies to orchestrators that launch multiple agent branches speculatively against shared external state (filesystems, APIs, message queues, databases) and reconcile by rollback-on-conflict. Does not apply to pure read-only fan-out or to branches whose effects are fully captured in an append-only log that is never externally observable. ## Core Distinction Speculative execution of parallel agent plans is only safe when the *observable effect* of a branch is decoupled from its *speculative commitment*. Most orchestrators conflate the two: they let each branch execute tools against live external systems, then "roll back" the loser by deleting files, reverting commits, or issuing compensating calls. This works only if every external effect is *reversible and idempotent under compensation* — an assumption that agent tool surfaces routinely violate. The real boundary is not "can we roll back?" but "is the rollback itself a speculative action that can conflict?" A compensating write is another write. When branch A and branch B both speculatively send an email, place an order, or transition a ticket to `in_progress`, the reconciliation step does not undo a side effect — it *adds a second side effect* (a "sorry, disregard" email, a refund, a status flip back) that is itself observable, may fail, and may race with the other branch's compensation. The invariant that must hold is: **no branch may perform an externally observable, non-compensable effect before the reconciliation barrier commits it.** Rollback is not a substitute for this invariant; it is a fallback that silently degrades to "emit contradictory effects in order." ## What Was Observed A planner decomposed a task into three parallel branches (A: update billing record, B: update billing record via a different code path, C: reconcile audit log). All three ran speculatively against a live Postgres instance and an outbound email tool. A and B produced conflicting writes to the same row; C read a snapshot mid-flight and wrote an audit entry consistent with A's version. On conflict detection, the orchestrator rolled back B by applying an inverse patch. Failure trace: 1. A commits `balance = 100`. B commits `balance = 90`. Both also enqueue a `notify_customer` email with the respective balance. 2. Reconciliation detects the row-version conflict, selects A as winner, and rolls back B via inverse patch: `balance` restored to 100. The inverse patch succeeds. 3. But B's email was already handed to the outbound queue with `balance = 90`. The compensating action for the email is *another* email, which the orchestrator did not model — its rollback contract only covered the database. 4. C's audit entry, written against A's snapshot, now references a state that briefly did not exist (B's 90) and a notification that was sent but "rolled back." 5. The customer receives "your balance is 90," then "your balance is 100," and the audit log shows a transition 100→90→100 that no committed plan ever authorized. The rollback was *locally correct and globally wrong*. The orchestrator's conflict model assumed effects were confined to a transactional store; the email tool was a non-transactional escape hatch that the rollback contract did not enumerate. This is the non-obvious failure: rollback completeness is a *property of the union of all tool surfaces*, and agents discover new tool surfaces at runtime, so the rollback contract is always potentially incomplete. A second observed variant: two branches both called an idempotent `create_ticket` endpoint with different payloads. The endpoint was idempotent on `(customer_id, title)` but not on `body`. Both succeeded as distinct tickets; rollback deleted only the loser's ticket by ID, but a downstream consumer had already paged on-call from the loser's ticket body. Compensation arrived after the page. The invariant "idempotent" was true at the endpoint and false at the system. ## Condition of Validity Rollback-based speculative execution is valid only when all of the following hold simultaneously: - **Effect enumeration is closed.** The set of external effects a branch can produce is known before execution and every member has a defined, tested compensation. Agent tool surfaces with dynamic tool discovery, freeform shell access, or arbitrary HTTP egress violate this. - **Compensation is causally ordered after the effect and before any observer.** If an observer (human, downstream service, pager) can act on the effect before compensation lands, rollback is not a rollback — it is a correction. - **Compensation is itself conflict-free.** Two branches' compensations must not target the same resource in an order-dependent way, or the reconciliation step reintroduces the race it was meant to resolve. - **The reconciliation barrier is a single serialization point.** Branch effects become visible to the rest of the system only after the barrier commits the winner. This requires staging (shadow writes, dry-run mode, sandboxed side-effect sinks), not post-hoc patching. When any of these fails, the correct architecture is not "better rollback" but *deferred commitment*: branches produce a plan plus a staged effect set, and the orchestrator applies only the committed branch's effects after reconciliation. Speculation then costs latency, not correctness. ## Decision Boundary Choose rollback-per-branch when: all tool surfaces are transactional or trivially compensable (pure compute, scratch filesystem, in-memory state), and no external observer can act on intermediate effects. Choose staged-commit (deferred effects) when: any branch touches an outbound channel (email, webhook, payment, ticket, pager), any tool surface is discovered at runtime, or any effect is observed by a party outside the orchestrator's control. The boundary is crossed the moment a branch's effect set contains one non-compensable member. A single non-compensable tool in the union poisons the whole scheme, because the orchestrator cannot know at plan time which branch will invoke it. The decision is therefore conservative: if *any* reachable tool is non-compensable, the plan must use deferred commitment, regardless of how many branches happen to avoid it on a given run. A useful heuristic for the boundary: ask whether the compensation for an effect would itself generate a notification to a human. If yes, the effect is externally observable and belongs behind the barrier. ## Operational Effect Teams that adopt rollback-per-branch without the closed-effect invariant observe a characteristic signature: conflict rates are low, rollback success rates are high, and yet incident volume rises with a specific shape — duplicate or contradictory customer-facing messages, audit logs with unauthorized intermediate states, and compensations that page humans after the fact. The failure is invisible in rollback metrics because the rollback *succeeded*; the damage was done by the effect it could not reach. The fix that holds is to make the reconciliation barrier the only writer. Branches run against a staging layer that records intended effects as data; the barrier selects a winner and applies that branch's effect set exactly once, in a defined order, with the loser's effects discarded before any external call. This converts an unbounded rollback-completeness problem into a bounded staging-fidelity problem, which is tractable because staging is under the orchestrator's control while external tool surfaces are not. The residual risk after staged commit is staging fidelity: the staging layer must model every effect the branch intends, and a branch that escapes staging (e.g., a shell tool that writes directly to a live endpoint) reintroduces the original failure. The guardrail is to deny branches direct access to non-compensable tools and expose them only as staged intents the barrier can replay. The invariant to enforce in code is that no branch may invoke a non-compensable tool except through the barrier, and the barrier must reject any effect set it cannot fully apply atomically. ```python class UnsafeSpeculativeCommit(RuntimeError): """Raised when a speculative branch attempts an effect that rollback cannot bound.""" pass NON_COMPENSABLE = {"send_email", "charge_card", "page_oncall", "create_ticket"} def apply_winner(effect_set, tool_registry, committed): """Apply only the committed branch's effects, after the reconciliation barrier. Invariant: no effect reaches an external observer until `committed` is True, and every effect in the set must be fully applicable atomically. """ if not committed: raise UnsafeSpeculativeCommit( "apply_winner called before reconciliation barrier committed" ) for effect in effect_set: tool = effect["tool"] if tool in NON_COMPENSABLE and not effect.get("staged_intent"): # A non-compensable tool reached the barrier without being staged; # rollback cannot undo it, so we must refuse rather than guess. raise UnsafeSpeculativeCommit( f"non-compensable tool {tool!r} not expressed as staged intent; " "refusing to commit because rollback cannot bound this effect" ) tool_registry.invoke(tool, effect["args"]) return True def reconcile(branches, winner_id): """Select a winner and discard losers' staged effects before any external call.""" winner = next((b for b in branches if b.id == winner_id), None) if winner is None: raise UnsafeSpeculativeCommit(f"winner {winner_id!r} not among branches") for b in branches: if b.id != winner_id and b.has_applied_non_compensable_effect(): # Loser already leaked an effect; rollback is no longer sufficient. raise UnsafeSpeculativeCommit( f"branch {b.id!r} applied a non-compensable effect before the " "barrier; reconciliation cannot restore consistency" ) return winner.staged_effects ```