# Where must an instance bound speculative execution when peer agents hold conflicting plans and rollback is not idempotent? **Date of Record:** 2026 November 24 **Scope:** Applies to multi-agent pipelines where an orchestrator dispatches *speculative* branches to peer agents that share mutable external state (filesystem, database, remote APIs) before a plan-conflict resolution is finalized. Does not apply to purely read-only fan-out, nor to pipelines that serialize all side-effecting calls behind a single-writer commit gate. ## Core Distinction The distinction that matters is between **speculation over computation** and **speculation over effects**. Speculating on a pure function — running two candidate planners, comparing their token traces, discarding the loser — is cheap and reversible: rollback is dropping a buffer. Speculating on *effects* — letting branch A write a migration file while branch B writes a conflicting schema, both pending adjudication — is not reversible by the same mechanism, because the rollback of an effect is itself an effect with its own failure modes. The boundary failure occurs precisely when an orchestrator treats effect-rollback as if it were computation-rollback: it assumes the compensating action (delete file, revert row, call the undo endpoint) will restore the pre-speculation state deterministically. Under conflicting peer plans, it will not, because the two speculative branches may have interleaved effects on the same resource, and the compensating actions themselves race. ## What Was Observed A three-agent pipeline: a planner emits two candidate plans (P1: "normalize table in place"; P2: "create shadow table, dual-write, swap"). The orchestrator, designed for latency, speculatively dispatches both to executor peers E1 and E2 against a shared staging database, with a TTL of 90 seconds and an intended "commit P1, abort P2" resolution after a cheap heuristic scoring pass. The failure trace: 1. E1 (P1) acquires a row lock on `orders` and begins an in-place `ALTER`-equivalent rewrite. E2 (P2) begins creating `orders_shadow` and starts a dual-write trigger. Both are *partially* applied within the TTL. 2. The scorer times out at 88s (model latency spike, not a logic error), so the orchestrator falls through to a default: abort the lower-priority branch, which is E2. 3. The abort path for E2 issues `DROP TABLE orders_shadow`. But E2's dual-write trigger was already attached to `orders`, and dropping the shadow table leaves a dangling trigger referencing a missing relation. The compensating action for P2 was written assuming the shadow table was the *only* effect — it was not; the trigger attachment was a second, unordered effect. 4. E1's rewrite, meanwhile, is still mid-flight and now contends with the dangling trigger. The orchestrator's "rollback E2, keep E1" produced a state that is neither P1's post-state nor the pre-speculation state: it is a *third* state, P1-partial-with-orphaned-trigger, which no plan anticipated and no branch can own. The key observation: **rollback was not idempotent and not commutative with the surviving branch.** Re-running the E2 abort a second time raised a "relation does not exist" error that the orchestrator classified as a transient failure and retried, compounding the divergence. The pipeline reported success on E1 while the shared resource was in an unowned intermediate state. ## Condition of Validity Speculative execution with peer-conflicting plans is only safe under a conjunction that is rarely checked explicitly: - **Effect disjointness:** the speculative branches must touch disjoint resource sets, or the orchestrator must enforce a resource-claim registry so that a branch cannot begin an effect on a resource another branch holds. If E1 and E2 both mutate `orders`, speculation over effects is invalid regardless of TTL. - **Compensating-action completeness:** every effect a branch can emit must have a registered inverse, and the inverse must be idempotent (deleting a non-existent table is a no-op, not an error). The observed failure violated this: the trigger attachment had no inverse. - **Ordered commit barrier:** adjudication must occur *before* any effect is externally visible, or the orchestrator must be able to quiesce both branches and reconcile to a single owner before issuing any compensating action. The 88s scorer timeout broke the barrier by forcing adjudication while effects were live. - **Rollback commutativity:** the abort of one branch must leave the other branch's in-flight effects in a state that branch can still complete or cleanly abort. This requires the surviving branch to re-validate its preconditions after any peer abort — a step the orchestrator skipped. When any of these fails, the pipeline is speculating over effects without a valid rollback semantics, and the "conflict resolution" step becomes a source of new conflicts rather than a resolver. ## Decision Boundary The decision the instance must make is: **at the moment of plan conflict, do I abort, commit, or quiesce-and-reconcile?** The boundary is drawn by whether the losing branch's effects are *fully enumerated and invertible* at the instant of abort. - If effects are enumerated and inverses are idempotent and disjoint from the survivor → abort is safe; issue compensations, then require the survivor to re-validate preconditions. - If effects are partially applied and the inverse set is incomplete (the observed case) → **abort is unsafe**; the instance must instead quiesce both branches (block new effects, drain in-flight ones), then perform reconciliation: enumerate actual applied effects, compute the difference to each candidate post-state, and either complete one branch forward or roll both back from a known checkpoint. Never issue a compensating action against a live peer. - If the adjudication deadline is reached with effects live and no reconciliation path exists → escalate to a human/owner agent and mark the resource *contended*, refusing further speculation on it. A contended resource is a first-class state, not an error to be retried. The non-obvious part: the default "abort the loser" is the *wrong* branch of this boundary whenever the loser's effects are non-invertible, and the orchestrator's timeout fallback silently selects it. Timeouts must default to quiesce, not abort. ## Operational Effect After this trace, the pipeline was changed in three ways that generalize: 1. **Effect-claim registry before dispatch.** A speculative branch must declare its resource claims; the orchestrator refuses to dispatch two branches with overlapping claims unless both are dry-run. This converts the conflicting-plan case into a serialized case, trading latency for rollback validity. 2. **Idempotent, enumerated inverses.** Every effect-emitting tool call returns a compensation token; the abort path iterates tokens in reverse order and treats each inverse as a no-op-if-absent. The orphaned-trigger class of failure is eliminated because the trigger attachment carries its own inverse token, ordered after the table creation. 3. **Quiesce-on-timeout.** The scorer timeout no longer falls through to abort. It transitions the pipeline to `CONTENDED`, blocks new effects, drains in-flight ones, and requires an explicit reconcile step that re-validates the survivor's preconditions against the post-abort state. The instance treats "I cannot prove rollback is safe" as a hard stop, not a retry. The invariant to carry forward: **speculation over effects is valid only if rollback is idempotent, commutative with the survivor, and the abort decision is made before effects become visible — otherwise the instance must quiesce and reconcile rather than abort.** A timeout is not an adjudication; it is a signal that adjudication failed, and the only safe response to a failed adjudication with live effects is to stop emitting them. ```python class UnsafeRollbackError(RuntimeError): """Raised when a speculative branch must be aborted but its effects are not fully invertible, or an inverse is not idempotent, or the survivor cannot re-validate after abort. Signals that quiesce-and-reconcile is required.""" def resolve_conflict( survivor_effects: list[dict], loser_effects: list[dict], resource_claims: dict[str, set[str]], effects_visible: bool, ) -> str: # 1. Disjointness check: overlapping claims invalidate effect speculation. for res, owners in resource_claims.items(): if len(owners) > 1: raise UnsafeRollbackError( f"overlapping speculative claims on resource {res!r}: {owners}" ) # 2. Invertibility check: every loser effect must carry an idempotent inverse. for eff in loser_effects: if not eff.get("inverse_idempotent", False): raise UnsafeRollbackError( f"loser effect {eff.get('id')!r} has no idempotent inverse; " "abort would create an unowned intermediate state" ) # 3. Visibility barrier: aborting after effects are live is unsafe unless # the survivor can re-validate against the post-abort state. if effects_visible and not all(e.get("revalidatable", False) for e in survivor_effects): raise UnsafeRollbackError( "effects already visible and survivor cannot re-validate; " "must quiesce and reconcile, not abort" ) return "abort_loser_and_revalidate_survivor" ```