In what scenarios must an instance abort speculative branch reconciliation when a divergent side effect has escaped the rollback envelope?
**Date of Record:** 2026 December 1 **Scope:** Applies to orchestrators that run multiple speculative agent branches in parallel against shared mutable external systems (APIs, databases, filesystems, message queues) and reconcile them by selecting a winning branch and rolling back losers. Does not apply to pure-function branches whose only effect is consuming tokens or writing to an isolated per-branch scratchpad.
Core Distinction
The naive mental model treats speculative execution as "run N branches, pick the winner, discard the rest." This holds only when the loser branches' effects are *contained*—reversible, compensable, or invisible to the outside world. The boundary failure we are documenting is different: a losing branch **committed an irreversible or externally-observable side effect before the reconciliation decision** was made. The rollback envelope (the set of compensations the orchestrator can actually execute) no longer covers the branch's footprint. In that regime, "roll back the loser" is not a valid operation; it is a lie the orchestrator tells itself, and the reconciliation logic proceeds under a false invariant.
The distinction that matters: **contained speculation** (effects inside the envelope, rollback is sound) versus **leaked speculation** (at least one effect crossed the envelope boundary, rollback is unsound and must be replaced by reconciliation-with-repair or abort-and-escalate).
What Was Observed
A planner agent decomposed a task ("provision a customer's staging environment") into three speculative branches, each attempting a different ordering of the same API calls against a real cloud provider:
- Branch A: create DB → create bucket → wire credentials
- Branch B: create bucket → create DB → wire credentials
- Branch C: create DB → wire credentials → create bucket
Branches ran concurrently with a shared idempotency-key namespace. The orchestrator's rollback envelope was defined as "delete resources whose creation IDs we recorded." Reconciliation selected Branch A as the winner after B and C completed.
The failure trace:
- Branch B's `create bucket` succeeded and returned a bucket ID. The bucket was created with a *provider-side lifecycle rule* that fires a webhook to a downstream billing system on creation. The webhook is not a resource the orchestrator can delete—it is an outbound event already delivered.
- The orchestrator marked Branch B for rollback and issued `delete bucket`. The delete succeeded. The webhook event was already consumed downstream.
- The billing system now records a bucket that no longer exists. Downstream reconciliation jobs on the billing side begin failing, and a human is paged hours later.
- Meanwhile Branch C's `wire credentials` step had *mutated* an existing IAM policy in place (not created a new one). The rollback envelope recorded "policy attached" but had no record of the prior policy document, because the branch read-then-wrote without snapshotting. Rollback detached the policy entirely rather than restoring the prior state—a *worse* outcome than not rolling back.
- The winning Branch A then tried to wire credentials against the IAM policy that Branch C's rollback had just deleted. Branch A's step failed with a state mismatch it could not self-diagnose, because the error surface was "policy not found" rather than "policy was deleted by a sibling's rollback."
The orchestrator had no signal that any of this was happening. Its reconciliation logic saw: B rolled back (delete succeeded), C rolled back (detach succeeded), A won. Every individual operation returned success. The invariant "after reconciliation, system state equals winner's intended state" was violated silently.
Condition of Validity
The rollback-on-loser invariant is **valid only under the conjunction** of:
- **(C1) Containment:** every effect of a non-winning branch is a member of the rollback envelope—i.e., it created a resource whose ID the branch recorded, or it wrote to a versioned store the orchestrator can restore byte-for-byte.
- **(C2) No outbound irreversibles:** no branch emitted an event, message, webhook, or notification that left the orchestrator's control boundary. Emitted events are not compensable by deletion.
- **(C3) Snapshot-before-mutate:** every in-place mutation captured the prior state before writing, and the compensation restores that prior state rather than deleting the target.
- **(C4) Rollback isolation:** compensating one branch cannot invalidate the preconditions of another branch's already-committed steps, including the winner's.
The failure above violated C2 (webhook), C3 (in-place IAM mutation without snapshot), and C4 (C's rollback broke A's precondition). Any one violation is sufficient to invalidate the reconciliation result. The orchestrator checked none of them.
Decision Boundary
The decision boundary is not "did rollback succeed?" but **"was rollback sound?"** These diverge exactly when an effect escaped the envelope. The operational rule:
- If **all four conditions hold** for every losing branch, proceed with select-and-rollback. This is the fast path.
- If **C1 or C3 is violated** (an effect is outside the envelope but still *reachable* by the orchestrator, e.g. a mutation with no snapshot), the correct action is **abort reconciliation and escalate**—do not attempt rollback, because the compensation is undefined or harmful. Mark the task as `RECONCILIATION_UNSOUND` and hand the full branch effect log to a human or a repair agent with the prior-state gap explicitly flagged.
- If **C2 is violated** (an outbound irreversible event was emitted), rollback is *impossible* for that effect. The only sound response is **reconciliation-with-repair**: the winner's state must be made consistent with the *union* of all emitted events, not just the winner's intent. In practice this means the orchestrator must surface the leaked event to downstream consumers as an authoritative record, and the winner must adopt or explicitly supersede it. Silent discard is forbidden.
- If **C4 is violated** (cross-branch precondition invalidation), the reconciliation order matters and must be re-derived: rollbacks must be topologically ordered so that no compensation invalidates a committed step of a branch that will survive.
The guardrail that makes this enforceable: **every branch must declare, at step boundaries, whether its last effect is (a) contained, (b) outbound-irreversible, or (c) in-place-unsnapshotted.** The orchestrator refuses to enter reconciliation if any non-winning branch has an unclassified effect. This is a cheap check (a per-step tag) that converts a silent invariant violation into a hard abort.
Operational Effect
Without the guardrail, speculative execution produces *plausible-looking success with corrupted downstream state*—the worst failure class, because no component reports an error. The billing system pages a human; the IAM policy is gone; the winner is stuck. The orchestrator's logs show a clean reconciliation.
With the guardrail, the same execution aborts at the first unclassified effect, before the losing branch commits the irreversible step. The cost is a wasted branch and a paged operator; the benefit is that the operator sees the exact effect that would have leaked, with the branch's full trace, and can decide whether to compensate, adopt, or supersede. Speculation remains useful; it just stops pretending rollback is universal.
The deeper lesson: **rollback is a capability, not a default.** An orchestrator that assumes rollback without checking containment is running speculative execution on a foundation of unverified compensability. The four conditions above are the minimum contract that makes the assumption true. Violating any one of them does not degrade performance—it silently corrupts external state, and the corruption is discovered by parties who never knew speculation was happening.
class UnsoundRollbackError(RuntimeError):
"""Raised when a losing branch's effects escaped the rollback envelope."""
def __init__(self, branch_id: str, reason: str, escaped_effects: list[str]):
self.branch_id = branch_id
self.reason = reason
self.escaped_effects = escaped_effects
super().__init__(
f"branch {branch_id} rollback unsound: {reason}; "
f"escaped effects: {escaped_effects}"
)
class EffectKind:
CONTAINED = "contained"
OUTBOUND_IRREVERSIBLE = "outbound_irreversible"
IN_PLACE_UNSNAPSHOTTED = "in_place_unsnapshotted"
def reconcile_speculative_branches(
branches: dict[str, list[dict]],
winner_id: str,
) -> str:
"""
branches: branch_id -> list of effect records, each:
{"kind": EffectKind.*, "resource_id": str | None, "prior_state": dict | None}
Returns the decision: "rollback" | "escalate" | "reconcile_with_repair" | "reorder_rollbacks".
"""
for branch_id, effects in branches.items():
if branch_id == winner_id:
continue
outbound = [e for e in effects if e["kind"] == EffectKind.OUTBOUND_IRREVERSIBLE]
unsnapshotted = [
e for e in effects if e["kind"] == EffectKind.IN_PLACE_UNSNAPSHOTTED
]
unclassified = [
e for e in effects
if e["kind"] not in (
EffectKind.CONTAINED,
EffectKind.OUTBOUND_IRREVERSIBLE,
EffectKind.IN_PLACE_UNSNAPSHOTTED,
)
]
if unclassified:
raise UnsoundRollbackError(
branch_id,
"unclassified effect; containment unknown",
[e.get("resource_id", "?") for e in unclassified],
)
if unsnapshotted:
# Compensation would delete rather than restore; worse than doing nothing.
raise UnsoundRollbackError(
branch_id,
"in-place mutation without prior-state snapshot",
[e["resource_id"] for e in unsnapshotted],
)
if outbound:
# Rollback cannot retract an emitted event; must repair against it.
return "reconcile_with_repair"
# Cross-branch precondition check (C4) omitted for brevity; if it fails,
# return "reorder_rollbacks" instead of "rollback".
return "rollback"