# Where must an instance reconcile before it rolls back: the speculative-branch commit-order invariant **Date of Record:** 2026 November 18 **Scope:** Applies to orchestration of parallel agent branches that execute speculatively against shared external state (databases, filesystems, message queues, APIs) and are expected to be rolled back on failure or reconciled on success. Does not apply to purely functional branches whose effects are buffered in-memory and committed atomically at the end, nor to branches that operate only on isolated copy-on-write snapshots. ## Core Distinction The non-obvious boundary is between **rollback of a branch's local state** and **reconciliation of effects that have already escaped the branch's isolation boundary**. Speculative execution frameworks universally provide the first. They almost never guarantee the second, and the failure mode is not a crash — it is a *silent divergence* between the orchestrator's belief about the world and the world itself. The invariant that gets violated is: > For any speculative branch B, if B has emitted an effect E to a resource R that is not exclusively owned by B, then rollback(B) must be preceded by a reconciliation step that either (a) confirms E is idempotently reversible, or (b) records E as an orphan requiring downstream adjudication. The subtle part: **the orchestrator cannot know, from branch-local bookkeeping alone, whether R is exclusively owned.** Ownership is a property of the *resource*, not the *branch*, and it can change during execution — a branch that started with a private staging table may have that table promoted to shared by a concurrent reconciler, or a branch may write through a connection pool whose target was re-pointed. The ownership predicate must be re-evaluated at rollback time, not cached at branch-spawn time. ## What Was Observed A three-branch speculative fan-out was dispatched to resolve a data-migration task. Branch A mutated a shared catalog table (row-level updates keyed by `migration_id`), Branch B wrote artifacts to an object store under a prefix it *assumed* was branch-private, and Branch C performed only read-only analysis. Branch A failed validation and was rolled back. The orchestrator invoked `rollback(A)`, which replayed the inverse of A's recorded mutations. The rollback succeeded, and the orchestrator reported Branch A as cleanly reverted. However, Branch B had, during its execution, written an artifact into the *same* prefix that A's rollback logic treated as A-owned scratch space — because the prefix had been provisioned from a pool and the pool allocator had, under contention, issued the same prefix to both branches. A's rollback deleted the prefix. B's artifacts vanished. B then committed successfully, and its commit record referenced artifacts that no longer existed. No exception was raised in any branch. No rollback failed. The system reported full success on B and clean rollback on A. The divergence was discovered hours later when a consumer of B's output dereferenced a missing object. The root cause was not the prefix collision (that was a separate allocator bug) — it was that **rollback(A) proceeded without reconciling whether the resources it was about to revert were still exclusively A's.** The rollback was locally correct and globally destructive. A second, more insidious instance: Branch A held an open transaction against a database and, mid-speculation, the transaction was implicitly committed by a connection-pool timeout configured to `commit_on_release`. Rollback(A) issued a `ROLLBACK` that was a no-op because the transaction had already ended. The orchestrator's rollback returned success (the `ROLLBACK` statement did not error on an already-terminated transaction in that driver). The effects were durable and the branch was marked reverted. ## Condition of Validity Rollback-without-reconciliation is valid **only** when all of the following hold at the moment of rollback: 1. Every resource mutated by the branch carries an ownership token that the branch acquired and still holds, verifiable by a compare-and-check against the resource itself (not against a local cache). 2. Every emitted effect is either (a) recorded in a write-ahead intent log with a stable effect ID that permits idempotent reversal, or (b) provably confined to a resource whose ownership token is still held. 3. No effect has crossed a boundary where an external actor (another branch, a pool, a timeout, a retry layer) could have observed, duplicated, or committed it. Condition 3 is the one that fails silently, because the orchestrator's view of "crossed a boundary" is derived from the branch's own instrumentation, and instrumentation does not see the connection pool's `commit_on_release`, the object-store lifecycle rule that promoted the staging prefix, or the message broker's at-least-once redelivery that duplicated a "speculative" publish. When any of these is unverifiable, the correct action is **not** rollback. It is **quarantine-and-reconcile**: mark the branch's effects as orphaned, halt dependent branches, and route the orphan set to a reconciliation pass that has authority over the resource. ## Decision Boundary The decision procedure at rollback time must be: - **If** the branch has emitted zero effects outside its verified-private resources **and** holds all ownership tokens → rollback directly. This is the fast path and is correct. - **If** the branch has emitted effects to resources whose ownership cannot be re-verified → do **not** roll back. Escalate to reconciliation. Rolling back here is the failure mode described above. - **If** the branch's effects are reversible via intent-log replay and every effect ID is confirmed unobserved by external actors → roll back via intent-log replay, then verify by re-reading each resource and comparing to the pre-branch snapshot. A rollback that does not verify is a claim, not a fact. - **If** verification fails → treat as reconciliation case regardless of what the rollback reported. The boundary is sharp: **the presence of any unverified external effect converts a rollback into a reconciliation obligation.** The orchestrator's default must be reconciliation, with rollback as the optimization it takes only when the ownership predicate is provable. Systems that default to rollback and treat reconciliation as the exception will, under contention, silently corrupt shared state — and will report success while doing so. ## Operational Effect The practical consequence is that speculative fan-out frameworks need a **pre-rollback reconciliation gate**, not a post-rollback audit. The gate must run before any inverse operation is issued, and it must re-read resource ownership from the resource. Post-hoc audits are insufficient because by the time the audit runs, the destructive inverse has already executed. This also changes the cost model: reconciliation is not free, and it serializes against the resource. Under high fan-out, the reconciliation gate becomes the throughput bottleneck. The correct mitigation is not to skip the gate but to **shrink the set of resources that require it** — by giving each branch a genuinely exclusive resource (dedicated prefix, dedicated schema, dedicated queue topic) so that the ownership predicate is trivially provable and the gate short-circuits. Speculative execution is only cheap when isolation is real; when isolation is simulated by naming conventions, the reconciliation gate is the only thing standing between the system and silent divergence. The operational rule to carry forward: *a rollback that cannot prove exclusivity is a delete statement against shared state.* Treat it with the same ceremony as any other shared-state mutation. ```python class UnreconciledRollbackError(RuntimeError): """Raised when a speculative branch rollback is attempted while it holds unverified external effects. Rollback must not proceed; reconcile instead.""" pass class BranchEffect: __slots__ = ("effect_id", "resource", "ownership_token", "verified_exclusive") def __init__(self, effect_id, resource, ownership_token, verified_exclusive): self.effect_id = effect_id self.resource = resource self.ownership_token = ownership_token self.verified_exclusive = verified_exclusive def pre_rollback_gate(branch_id, effects, re_verify_ownership): """Re-evaluate ownership at rollback time; never trust the spawn-time cache. re_verify_ownership(resource, token) -> bool: reads the resource itself and confirms the token is still held and no external actor observed the effect. """ unverified = [] for eff in effects: still_exclusive = re_verify_ownership(eff.resource, eff.ownership_token) if not (eff.verified_exclusive and still_exclusive): unverified.append(eff.effect_id) if unverified: raise UnreconciledRollbackError( f"branch {branch_id}: refusing rollback; {len(unverified)} effect(s) " f"escaped isolation boundary and cannot be proven exclusive: {unverified}. " f"Route to reconciliation, do not issue inverse operations." ) return True def rollback_branch(branch_id, effects, re_verify_ownership, apply_inverse): # Gate first. If it raises, no inverse has been issued and shared state is intact. pre_rollback_gate(branch_id, effects, re_verify_ownership) for eff in effects: apply_inverse(eff.effect_id) return "reverted" ```