In what scenarios must an instance abandon speculative branch reconciliation when rollback side effects are non-commutative across sibling agents

**Date of Record:** 2026 December 2 **Scope:** Applies to orchestrators that fan out speculative agent branches (parallel "try this plan" siblings), each holding leased resources and emitting side-effecting tool calls, then select a winning branch and roll back losers. Does not apply to read-only speculative execution, single-branch retry, or branches whose effects are fully sandboxed and trivially reversible.

Core Distinction

The distinction that matters is between **rollback as a state reset** and **rollback as an inverse operation**. Most speculative orchestration designs assume the loser branch can be "rolled back" by discarding its memory and releasing its lease—treating rollback as a logical undo of a local state machine. That assumption is valid only when branch effects are *commutative across siblings*: the order in which sibling branches executed their side effects does not change the observable world after losers are undone. When sibling branches mutate a shared, order-sensitive resource—an append-only ledger, a monotonically incrementing counter, an external queue with at-least-once semantics, a remote API that records call history—rollback is an *inverse action*, and inverse actions do not commute. The orchestrator can no longer "undo the losers" as a set; it must undo them in a specific sequence, and that sequence may not exist.

This is not the generic distributed-systems problem of compensating transactions. The agent-specific twist is that the *decision to roll back* is made by a probabilistic reconciler comparing branch outcomes, and the reconciler typically reasons over branch *reports* (what each agent claims it did) rather than branch *effects* (what actually landed). A sibling agent that timed out mid-call may report "no side effect" while its tool call is in flight or already committed on the remote side. The reconciliation decision and the rollback execution are therefore decoupled by an unreconciled window, and non-commutativity turns that window into a permanent inconsistency.

What Was Observed

A three-branch speculative plan-execution over a shared ticketing backend. Branch A (primary plan) and Branch B (fallback plan) both ran concurrently; Branch C was a verification sibling that audited A and B. Each branch held a lease on a distinct ticket range and emitted `increment_priority` and `append_audit_note` calls. The orchestrator's reconciler selected A on a 0.71 confidence margin after B's report arrived stale by 400ms.

The rollback procedure for B issued `decrement_priority` for each `increment_priority` B had reported. But B's last `increment_priority` call had been issued and not acknowledged before B was killed; the reconciler's view of B's effect log was truncated at the last ack. The `decrement_priority` therefore ran against a ticket whose priority had not yet been incremented by B—but the in-flight increment landed 90ms later. Net effect: the ticket ended one priority level higher than either branch intended. Branch C's audit, which had snapshot the ledger *before* the orphaned increment landed, recorded a clean rollback. The verification passed. The inconsistency was invisible to the reconciler because the reconciler trusted C's snapshot, and C's snapshot was taken at a point that did not include the orphaned effect.

The failure was not a race in the classical sense—every component behaved per its contract. It was a **reconciliation ordering violation**: the audit snapshot (C) was ordered before the orphaned effect (B's late increment), but the reconciler treated the audit as authoritative over the effect. Under commutative effects this ordering would be harmless; the final state would be the same regardless. Under non-commutative effects, the ordering is load-bearing and the reconciler had no mechanism to enforce it.

A second observation: when the orchestrator retried the reconciliation with a widened snapshot window, it observed the orphaned increment and issued a second `decrement_priority`. This over-corrected a different ticket that had legitimately received a priority bump from Branch A between the two snapshots. The reconciler had no way to distinguish "effect that should be undone" from "effect that arrived after the rollback decision and belongs to the winner." Each retry widened the inconsistency rather than converging.

Condition of Validity

The invariant that speculative rollback requires is: **for every pair of sibling branches (i, j), and every shared resource r, the effect of i on r and the rollback of j on r must commute, OR the orchestrator must hold a total order over all effects and rollbacks on r that is consistent with the reconciler's snapshot boundaries.**

The first disjunct is a property of the resource and effect types—it holds for isolated per-branch state, for CRDT-style mergeable state, and for resources where effects are idempotent and order-free. It fails for append-only logs, counters without compare-and-swap, external systems with at-least-once delivery, and any resource where the *number* of effects matters (not just the final value).

The second disjunct requires that the reconciler's snapshot be a *cut* in the causal order of all branch effects—i.e., no effect ordered before the snapshot may land after it. In practice this requires either (a) quiescing all sibling branches before snapshotting, which defeats the purpose of speculative parallelism, or (b) a fencing token per branch that the resource honors, so late effects from a fenced branch are rejected at the resource rather than landing silently.

The condition of validity is therefore: **speculative rollback is sound only when the orchestrator can prove, for each shared resource, that either sibling effects commute or that every branch holds a fencing token the resource enforces.** If neither holds, the orchestrator must not roll back speculatively—it must either serialize the branches on that resource or commit all branches and reconcile forward (accept the effects and compensate with new forward effects, never inverse ones).

Decision Boundary

The boundary is crossed at the moment the reconciler is about to emit an inverse effect (a `decrement`, a `delete`, a `cancel`) against a resource that also received effects from a sibling that has not been quiesced and fenced. The correct decision at that boundary is to **abandon inverse rollback and switch to forward reconciliation**: instead of undoing the loser's effects, the orchestrator computes the delta between the loser's actual landed effects (not its reported effects) and the winner's intended state, and emits forward corrective effects that bring the resource to the winner's state regardless of the loser's residue.

Forward reconciliation is sound under non-commutativity because it never relies on ordering between undo and other effects—it only relies on the resource supporting a *set-to-target* operation or a *recompute-from-truth* operation. It is more expensive (it requires reading actual landed state, not reported state) and it can be blocked if the resource does not expose a read-back. When read-back is unavailable, the orchestrator must escalate to human or to a serialized re-execution; it must not guess.

The boundary is *not* crossed when the resource is per-branch isolated (commutative by construction) or when fencing tokens are enforced and the reconciler waits for fence acknowledgment before snapshotting. In those cases inverse rollback remains sound and cheaper.

Operational Effect

The operational consequence is that speculative fan-out must be *resource-classified before dispatch*, not after reconciliation. Each branch's tool manifest must declare, per resource, whether effects are commutative, fenced, or neither. Branches touching "neither" resources must be serialized against each other or run in commit-all mode. The reconciler must refuse to emit inverse effects against "neither" resources and must route those branches to forward reconciliation with mandatory read-back.

The second effect is on the verification sibling: an auditor that snapshots state must snapshot at a *fenced cut*, meaning it must hold the same fencing tokens as the branches it audits, or it must be ordered strictly after all branch fences are acknowledged. An auditor that snapshots without fencing produces a report that is *causally unordered* with respect to branch effects, and the reconciler must treat such a report as advisory, never authoritative.

The third effect is on retry: a reconciler that retries after a failed rollback must treat the retry as a *new reconciliation epoch* with fresh snapshots and fresh fences, not as a continuation. Widening the snapshot window on retry is the anti-pattern observed above—it pulls in effects that belong to the winner and over-corrects. Each epoch must re-read actual landed state and recompute the delta from truth.

class NonCommutativeRollbackError(RuntimeError):
    """Raised when inverse rollback is attempted against a resource whose
    sibling effects are neither commutative nor fenced. The orchestrator
    must abandon inverse rollback and switch to forward reconciliation."""
    pass


class ResourceEffectClass:
    COMMUTATIVE = "commutative"   # order-free; inverse rollback sound
    FENCED = "fenced"             # fencing token enforced by resource; inverse sound if fence acked
    NEITHER = "neither"           # order-sensitive, no fence; inverse rollback UNSOUND


def rollback_branch(branch, resource_manifest, fence_acks, landed_state_reader):
    """
    Attempt inverse rollback of a losing speculative branch.
    Refuses if any touched resource is NEITHER and not fenced-acked.
    Returns forward-reconciliation plan instead of inverse effects when unsafe.
    """
    touched = branch.effect_log.resources()
    unsafe = []
    for r in touched:
        cls = resource_manifest.classify(r)
        if cls == ResourceEffectClass.NEITHER:
            unsafe.append(r)
        elif cls == ResourceEffectClass.FENCED and r not in fence_acks:
            unsafe.append(r)

    if unsafe:
        # Do not emit inverse effects. Require read-back and forward plan.
        if not landed_state_reader.available(unsafe):
            raise NonCommutativeRollbackError(
                f"Branch {branch.id} touched non-commutative resources {unsafe} "
                f"without fencing and without read-back; inverse rollback would "
                f"produce ordering-dependent inconsistency. Escalate to "
                f"serialized re-execution or human reconciliation."
            )
        # Forward reconciliation: compute delta from actual landed state to winner target.
        plan = []
        for r in unsafe:
            actual = landed_state_reader.read(r)
            target = branch.winner_target(r)
            if actual != target:
                plan.append(("set_to_target", r, target))
        return ("forward_reconcile", plan)

    # Safe path: commutative or fenced-acked resources; inverse rollback sound.
    inverse = [op.invert() for op in branch.effect_log.acked_effects()]
    return ("inverse_rollback", inverse)


def reconcile(speculative_result, resource_manifest, fence_acks, landed_state_reader):
    winner, losers = speculative_result.winner, speculative_result.losers
    for loser in losers:
        mode, ops = rollback_branch(loser, resource_manifest, fence_acks, landed_state_reader)
        if mode == "forward_reconcile":
            # New epoch: fresh fences, fresh snapshot, forward-only effects.
            apply_forward(ops)
        else:
            apply_inverse(ops)
    # Auditor reports are advisory unless snapshotted at a fenced cut.
    if not speculative_result.auditor.fenced_cut:
        speculative_result.auditor.mark_advisory()
    return speculative_result