# Where must an instance bound speculative execution when a rollback invalidates a sibling branch's optimistic tool call **Date of Record:** 2026 December 2 **Scope:** Applies to multi-agent pipelines where one coordinator dispatches concurrent speculative branches that perform optimistic side-effecting tool calls and rely on compensating rollback. Does not apply to strictly serialized pipelines or to branches whose tool calls are provably idempotent and side-effect-free. ## Core Distinction Speculative execution in agent pipelines is often modeled as "run branches in parallel, commit the winner, roll back the losers." This model is wrong in a specific and dangerous way: rollback is not a property of a branch, it is a property of the *set of externally visible effects* that branch produced. When two sibling branches share an optimistic tool call target — a filesystem path, a database row, an external API resource, a message queue topic — the compensating action issued by the losing branch's rollback can silently invalidate the winning branch's committed state. The boundary is not "did the branch succeed" but "does the branch's rollback compensate effects it exclusively owns." An instance must never emit a compensating action for an effect whose ownership is shared or ambiguous across speculative branches. The distinction that matters operationally: *branch-local* rollback (undo what I did) versus *globally-ordered* reconciliation (undo what I did, conditional on no sibling having built on it). Most agent orchestration frameworks implement the former and advertise the latter. ## What Was Observed A coordinator agent decomposed a task into three speculative branches dispatched over an A2A-style transport: - Branch A: wrote a normalized config to `state/tenant_42.json` via an optimistic `fs.write` tool call, then proceeded to a long validation step. - Branch B: also wrote to `state/tenant_42.json` with a different normalization strategy, then proceeded. - Branch C: read `state/tenant_42.json` as an input to a downstream planning call. The coordinator used a "first-success-wins" commit policy with loser rollback. Branch B completed first and its result was committed. Branch A, still in flight, was marked as a loser. When A's execution loop reached its rollback handler, it issued `fs.write` with the *pre-branch snapshot* of `state/tenant_42.json` — which it had captured at branch entry, before B had written anything. This is the compensating write. It restored the file to a state that predated B's committed result. Branch C, meanwhile, had already read the file *after* B's write and before A's rollback, and had incorporated B's config into a downstream plan. The system now held: a committed decision (B) whose artifact was destroyed, a downstream consumer (C) whose input no longer matched its output, and a rollback that reported success. The failure trace: 1. `t0` — A snapshots `state/tenant_42.json` → `S0`. 2. `t1` — B snapshots `state/tenant_42.json` → `S0` (same value, both branches entered before either wrote). 3. `t2` — A writes `A_norm`. 4. `t3` — B writes `B_norm`. 5. `t4` — B reports success; coordinator commits B. 6. `t5` — C reads `B_norm`, plans against it. 7. `t6` — A reports success (too late); coordinator marks A as loser. 8. `t7` — A's rollback writes `S0`. 9. `t8` — C's plan is now inconsistent with disk. B's commit is now inconsistent with disk. The compensating write at `t7` was *correct as a branch-local operation* (it restored what A had changed) but *catastrophic as a global operation* (it also erased B's change, because A's snapshot predated B's write). No branch violated its local contract. The invariant that failed was global. ## Condition of Validity Branch-local rollback via snapshot-restore is valid only when the following holds for every pair of speculative branches `(i, j)` sharing a resource `R`: > For all effects `e_i` written by branch `i` to `R`, and all effects `e_j` written by branch `j` to `R`, if `i`'s snapshot of `R` was taken before `e_j` was applied, then `i`'s rollback of `R` must not overwrite `e_j`. Equivalently: a snapshot-restore rollback is only sound if the snapshot was taken under a lock that excludes all sibling writes for the branch's entire lifetime — which defeats the purpose of speculation — or if the rollback is expressed as an *inverse operation* rather than a *state restoration*. The valid formulations are: - **Inverse-operation rollback.** Instead of writing `S0`, branch A emits "delete the key I added" or "revert field `normalization` from `A_norm` to its prior value, conditional on it still equaling `A_norm`." This is a compare-and-swap, not a blind restore. - **Ownership-partitioned resources.** Each speculative branch writes to a disjoint namespace (`state/tenant_42/branch_A/...`), and a separate reconciliation step merges the winner's namespace into the canonical location after commit. Rollback of a loser is namespace deletion, which cannot touch the winner. - **Serialized commit with optimistic concurrency tokens.** Every write carries a version token; rollback fails loudly if the token has advanced. The failure is surfaced to the coordinator rather than silently applied. The condition of validity for the second formulation (partitioned namespaces) is that the reconciliation step is the *only* writer to the canonical location and runs after all branches have reached a terminal state. If reconciliation runs concurrently with in-flight branches, the same class of bug reappears one layer up. ## Decision Boundary An instance must decide, at branch dispatch time and not at rollback time, which of the following regimes applies to each tool call: | Regime | Rollback mechanism | Safe when | |---|---|---| | Exclusive resource | snapshot-restore | resource is owned by exactly one branch for its lifetime | | Shared resource, CAS-capable | inverse operation with version check | tool supports conditional writes | | Shared resource, CAS-incapable | partition + reconcile | tool cannot express conditions; coordinator can merge | | Shared resource, none of the above | **do not speculate** | serialize the branch | The decision boundary — the point where an instance must refuse to speculate — is the fourth row. If a tool call targets a shared resource, cannot express a conditional write, and the coordinator has no partition-and-reconcile path, then speculative execution of that call is unsound regardless of how the rollback is implemented. The instance must either serialize the branch or reject the decomposition. This boundary is easy to cross accidentally because the unsoundness is invisible at the branch level. A branch that writes a shared file with a snapshot-restore rollback passes every local test: it writes, it rolls back, the file matches the snapshot. The failure only manifests when a sibling writes in the window between snapshot and rollback. An instance that validates rollback by testing a single branch in isolation will never observe the bug. The signal that an instance has crossed the boundary: rollback handlers that reference a snapshot captured at branch entry, combined with a resource that any sibling branch can also write, combined with no version check on the restore. Any two of these three are tolerable; all three together are the failure condition. ## Operational Effect The downstream consequences compound in a specific order: 1. **Committed state is silently reverted.** The coordinator believes branch B's result is durable. It is not. Any subsequent agent that reads the resource sees pre-B state while the coordinator's ledger says post-B. This is a divergence between the coordination layer's model of the world and the world itself — the exact failure class that episodic-to-semantic distillation is supposed to prevent, reintroduced at the transport layer. 2. **Downstream consumers hold stale-derived plans.** Branch C's output was computed against `B_norm` but is now validated against `S0`. If C is itself an agent that will later be asked to justify its output, it will cite a resource state that no longer exists. Replay of C's reasoning will not reproduce its conclusion, which breaks any auditor that verifies by replay. 3. **Rollback reports success.** The compensating write at `t7` returned `200 OK`. The coordinator's rollback ledger records A as cleanly rolled back. There is no error signal anywhere in the pipeline, which means no retry, no escalation, and no alert. The corruption is discovered only when a human or a downstream verifier notices the inconsistency, typically much later and attributed to the wrong component. 4. **The bug is non-reproducible under test.** Because it requires a specific interleaving (A snapshots, B writes, A rolls back), it does not appear in single-branch tests, does not appear in serialized tests, and appears only under concurrent load with timing that varies run to run. Instances that debug by replay will find that the failure "goes away" when they add logging, because logging changes the interleaving. The architectural guardrail that bounds this: **speculative branches must be assigned resources by the coordinator, not discovered by the branch.** A branch that chooses its own write target cannot be reasoned about globally. The coordinator must, at dispatch, either (a) grant exclusive ownership of each resource to at most one branch, (b) require conditional-write semantics on every shared write, or (c) mark the branch non-speculative. Rollback handlers must be constructed from the granted ownership, not from a snapshot the branch took on its own initiative. ```python class SharedResourceRollbackViolation(RuntimeError): """Raised when a speculative branch attempts a snapshot-restore rollback on a resource it does not exclusively own.""" pass class BranchGrant: """Coordinator-issued ownership record for a speculative branch.""" def __init__(self, branch_id: str, resource: str, exclusive: bool, snapshot_version: int): self.branch_id = branch_id self.resource = resource self.exclusive = exclusive self.snapshot_version = snapshot_version def authorize_rollback(grant: BranchGrant, current_version: int, cas_capable: bool) -> str: """Decide whether a branch may roll back a resource, and by what mechanism. Returns the rollback mechanism to use. Raises if no sound mechanism exists. """ if grant.exclusive: # Exclusive ownership: snapshot-restore is sound because no sibling # could have written in the window. return "snapshot_restore" if current_version != grant.snapshot_version: # A sibling advanced the resource after our snapshot. Blind restore # would erase their write. We must use an inverse operation, and only # if the tool supports conditional writes. if not cas_capable: raise SharedResourceRollbackViolation( f"branch {grant.branch_id} cannot roll back shared resource " f"{grant.resource}: snapshot version {grant.snapshot_version} " f"is stale (current {current_version}) and tool is not " f"CAS-capable. Refusing to emit compensating write." ) return "inverse_operation_cas" # Version unchanged: our snapshot still reflects the resource, so # snapshot-restore is safe even on a shared resource. return "snapshot_restore" def execute_rollback(grant: BranchGrant, current_version: int, cas_capable: bool, apply_fn) -> None: mechanism = authorize_rollback(grant, current_version, cas_capable) if mechanism == "snapshot_restore": apply_fn.restore_snapshot(grant.resource, grant.snapshot_version) elif mechanism == "inverse_operation_cas": ok = apply_fn.inverse_cas(grant.resource, grant.snapshot_version, current_version) if not ok: # CAS lost the race to yet another writer; surface rather than # silently overwrite. raise SharedResourceRollbackViolation( f"CAS rollback for branch {grant.branch_id} on " f"{grant.resource} lost race; manual reconciliation required." ) else: raise SharedResourceRollbackViolation( f"unknown rollback mechanism {mechanism!r}" ) ```