# What structural signals indicate branch divergence is irreversible in speculative multi-agent execution with rollback **Date of Record:** 2026 November 15 **Scope:** Applies to speculative multi-agent orchestration where N agent branches execute against a shared, mutable world-state (filesystem, database, external API quota, or message queue) and the orchestrator commits one branch while rolling back the others. Does not apply to purely functional branch evaluation where all side effects are deferred to a single commit phase, nor to branches operating on disjoint, non-observable state. ## Core Distinction The common mental model treats rollback as the inverse of execution: if branch B performed action `a`, rollback performs `a⁻¹`. This holds only for *reversible* actions — those whose inverse restores the exact pre-state and which were not observed by an external party during their lifetime. The failure boundary is not "did the rollback succeed" but "did any external observer act on the speculative state before rollback completed." A branch can roll back its own local state perfectly and still have leaked an irreversible commitment through an external observer — a downstream service that cached the value, a human who read the notification, a billing meter that incremented, a message that was consumed from a queue. The non-obvious invariant: **rollback safety is a property of the observation graph, not the mutation graph.** Two branches can perform identical local writes and have radically different reversibility because one exposed its intermediate state to an observer that cannot be un-observed. ## What Was Observed In a three-way speculative execution (branches A, B, C) against a shared staging environment, branch B issued a `POST /reservations` to an inventory service that debits a counter and emits an event to a Kafka topic consumed by a fulfillment worker. Branch B was rolled back after branch A was selected. The local rollback (deleting B's DB rows, reverting its file writes) completed in 40ms and reported success. However: - The inventory counter was already decremented; the compensating `DELETE` restored the counter value but the fulfillment worker had already dequeued the reservation event and emitted a `pick_scheduled` downstream event. - The compensating delete produced a *second* counter mutation visible to a monitoring alert, which fired and paged an on-call engineer who acknowledged it — an irreversible human observation. - A retry of branch A, unaware of the leaked event, double-scheduled the same SKU. The rollback was locally correct and globally wrong. The structural signal that predicted this was present before rollback: the branch's action graph contained an edge from a mutating node to an *event-emitting* node whose consumers were outside the transaction boundary. No such edge existed for branches A or C, which mutated only state the orchestrator owned. ## Condition of Validity Rollback-on-divergence is safe **iff** every speculative action's effect is confined to a state domain that the orchestrator can both (a) restore to its exact prior value and (b) prove was not observed by any actor outside the orchestrator's control during the speculation window. Formally, for each action `a` in branch B, the set `observers(a) \ orchestrator` must be empty for the window `[t_exec(a), t_rollback_complete]`. This condition is *not* satisfied when any of the following structural signals are present: 1. **Egress edges:** the branch's action graph has an edge leaving the orchestrator's state domain (HTTP call to a third party, event emission, queue enqueue, notification dispatch). These are irreversible by construction; compensation is a *new* action, not an inverse. 2. **Compensation asymmetry:** the compensating action is not the inverse of the original. A debit's inverse is a credit, but a credit is a distinct event with its own audit trail and alerting behavior. If `compensate(a) ≠ a⁻¹` structurally (different endpoint, different event type, different side-effect profile), the branch is not rollback-safe. 3. **Observer acknowledgment:** any external actor acknowledged receipt of the speculative effect (a 2xx response that implies durable commitment, an ack from a consumer, a human action taken in response). Once acknowledged, the effect is committed regardless of local state. 4. **Non-idempotent compensation:** the compensating action, if retried, produces additional divergence. A `DELETE` that decrements a counter is idempotent only if it checks existence first; a blind decrement is not. 5. **Ordering dependency:** the branch's actions were interleaved with another branch's actions against the same external resource, so the compensating action cannot distinguish which mutations to undo. ## Decision Boundary When any structural signal above is detected for the selected branch's *siblings* (the branches to be rolled back), the orchestrator must **not** attempt rollback. It must instead: - Mark the divergent branches as **poisoned** and escalate to a reconciliation path that treats their effects as committed-but-unwanted, requiring explicit compensation with its own idempotency keys and audit trail. - Halt further speculation against the affected external resource until reconciliation completes, to prevent compounding divergence. - Record the observation-graph edges that triggered the escalation as a permanent incident artifact, because they define the reconciliation scope. Conversely, if all sibling branches' action graphs are confined to orchestrator-owned state with no egress edges, rollback is safe and should proceed without escalation. The decision is structural and can be made *before* rollback is attempted, from static analysis of the action graph plus runtime observation tracking — this is the operational payoff: you can refuse to roll back a branch that would leak, rather than discovering the leak afterward. The subtle case: a branch with egress edges that were *not yet executed* at divergence time. Here rollback is safe for the executed prefix, but the orchestrator must cancel the pending egress actions atomically with the rollback, or a race will fire them post-rollback. The structural signal is the presence of egress edges in the *planned* graph, not just the executed graph. ## Operational Effect Instrumenting the action graph for egress edges and compensation asymmetry before rollback converts a class of silent, compounding divergence into an explicit reconciliation decision. In the observed incident, the pre-rollback check would have flagged branch B's `POST /reservations → event emission` edge and routed it to reconciliation, preventing the double-schedule and the spurious page. The cost is that reconciliation is slower and more manual than rollback; the benefit is that it is correct. The failure mode this replaces — "rollback succeeded locally, divergence leaked globally" — is the dominant cause of speculative-execution incidents in systems that treat rollback as a local operation. ```python from dataclasses import dataclass, field from enum import Enum from typing import FrozenSet class RollbackUnsafeError(RuntimeError): """Raised when a branch cannot be rolled back because its effects are irreversible.""" pass class EdgeKind(Enum): LOCAL_MUTATION = "local_mutation" EGRESS = "egress" # leaves orchestrator state domain EVENT_EMISSION = "event_emission" NOTIFICATION = "notification" @dataclass(frozen=True) class ActionNode: name: str kind: EdgeKind compensated_by: str | None = None # name of compensating action, if any compensation_is_inverse: bool = False idempotent_compensation: bool = False @dataclass class Branch: branch_id: str executed: list[ActionNode] = field(default_factory=list) planned: list[ActionNode] = field(default_factory=list) acknowledged_by_external: bool = False IRREVERSIBLE_KINDS: FrozenSet[EdgeKind] = frozenset({ EdgeKind.EGRESS, EdgeKind.EVENT_EMISSION, EdgeKind.NOTIFICATION, }) def assert_rollback_safe(branch: Branch) -> None: """ Structural pre-check: refuse rollback if the branch's executed or planned action graph contains irreversible or asymmetric edges. """ for node in branch.executed + branch.planned: if node.kind in IRREVERSIBLE_KINDS: raise RollbackUnsafeError( f"branch {branch.branch_id}: action '{node.name}' has " f"irreversible kind {node.kind.value}; rollback would leak " f"an un-observable commitment" ) if node.kind == EdgeKind.LOCAL_MUTATION and not node.compensation_is_inverse: raise RollbackUnsafeError( f"branch {branch.branch_id}: action '{node.name}' has " f"asymmetric compensation '{node.compensated_by}'; " f"compensation is a new action, not an inverse" ) if node.compensated_by and not node.idempotent_compensation: raise RollbackUnsafeError( f"branch {branch.branch_id}: compensation for '{node.name}' " f"is non-idempotent; retry would compound divergence" ) if branch.acknowledged_by_external: raise RollbackUnsafeError( f"branch {branch.branch_id}: effect acknowledged by external " f"observer; committed regardless of local state" ) def rollback_or_escalate(branch: Branch) -> str: try: assert_rollback_safe(branch) except RollbackUnsafeError as exc: return f"ESCALATE_TO_RECONCILIATION: {exc}" # safe: perform local rollback return "ROLLED_BACK" ```