# How does an instance detect irreconcilable speculative branches before committing a multi-agent rollback? **Date of Record:** 2026 November 15 **Scope:** Applies to systems where multiple agent instances execute speculative branches against shared external state (tool calls, file mutations, remote APIs) under a rollback-and-reconcile protocol. Does not apply to read-only speculative fan-out, nor to branches whose side effects are fully idempotent and version-fenced by the downstream tool itself. ## Core Distinction The failure mode is not "a branch failed." It is "two branches succeeded against state that cannot be reconciled because each branch's tool-call validation was evaluated against a *pre-speculation* snapshot." A speculative branch validates its tool calls against the state it inherited at fork time. When two branches both mutate a resource and both pass validation, the reconciler faces a merge of two *individually valid* but *jointly contradictory* post-states. This is distinct from a conflict detectable at write time (optimistic concurrency control catches that). The dangerous case is when the downstream tool is *not* version-checking — it accepts each write because each write was legal in isolation. The invariant that breaks is: **"a validated tool call implies the post-state it produced is a member of the admissible set for the parent transaction."** Speculation invalidates the antecedent's implicit "as of the same snapshot" clause. The non-obvious part: rollback does *not* restore the invariant. Rolling back branch B after branch A committed does not return the system to the fork snapshot if B's external side effects were already dispatched and are non-compensable. Reconciliation must therefore be decided *before* any branch commits, which means the detector must run at validation time, not at merge time. ## What Was Observed During a three-branch speculative execution over a shared configuration store, branches A and B each issued a `set_replica_count` tool call. A validated `3 -> 5` against snapshot `S0`. B validated `3 -> 7` against the same `S0`. Both passed. The tool had no compare-and-swap; it was a plain put. The reconciler received two post-states, `5` and `7`, both claiming parent `3`. Neither is derivably wrong, and neither is derivably right. The rollback path attempted to restore `3`, which itself is a third write racing the other two. The observed symptom was not an error — it was a *silent* final value of `7` with branch A's downstream agents having planned against `5`. Divergence surfaced two stages later as a capacity-planning assertion failure, far from the causal write. A second observation: branches that touched *disjoint* resources reconciled cleanly even when their tool calls were interleaved, confirming the detector must key on resource identity plus snapshot lineage, not on temporal overlap. ## Condition of Validity The detector below is valid only when: 1. Every speculative branch records the exact snapshot token (`S0`) it validated against, and that token is attached to each tool-call validation record. 2. Resource identity is stable and comparable across branches (no aliasing of the same logical resource under two names). 3. The reconciler runs *before* any branch's side effects are dispatched to a non-compensable sink. If side effects are already dispatched, detection is too late — you are in compensation, not rollback. It is *not* valid when the downstream tool performs its own version fencing (then conflicts surface as tool errors and this detector is redundant), nor when branches are strictly serialized (no speculation, no shared snapshot hazard). ## Decision Boundary The boundary is: **commit only if the set of (resource, snapshot_token) validation records across all surviving branches is pairwise consistent — i.e., for every resource, all branches that validated against the same snapshot token produced mutually derivable post-states, or exactly one branch touched it.** If two branches validated the same resource against the same snapshot token and produced distinct post-states, the branches are irreconcilable *by construction* and the parent transaction must fail closed rather than pick a winner. Picking a winner is the trap: it looks like reconciliation but silently discards the losing branch's downstream assumptions, which have already propagated. ## Operational Effect Failing closed at validation time converts a two-stage-latent divergence into an immediate, localized abort with the exact resource and snapshot lineage in the error. The cost is reduced speculation yield on hot shared resources; the benefit is that rollback is always sound because no non-compensable write was ever dispatched from an irreconcilable set. Operators should expect a measurable drop in commit rate on workloads with high resource contention and should route those resources to serialized (non-speculative) execution rather than widening the reconciler's tolerance. ```python from dataclasses import dataclass from typing import Iterable class IrreconcilableSpeculationError(RuntimeError): """Raised when speculative branches validated contradictory post-states against the same snapshot for the same resource, before commit.""" pass @dataclass(frozen=True) class ValidationRecord: branch_id: str resource: str snapshot_token: str post_state: str # canonical, comparable representation def assert_reconcilable(records: Iterable[ValidationRecord]) -> None: """Fail closed if any two branches produced distinct post-states for the same (resource, snapshot_token). Must run before side-effect dispatch.""" seen: dict[tuple[str, str], tuple[str, str]] = {} for rec in records: key = (rec.resource, rec.snapshot_token) if key in seen: prior_branch, prior_state = seen[key] if prior_state != rec.post_state: raise IrreconcilableSpeculationError( f"resource={rec.resource!r} snapshot={rec.snapshot_token!r}: " f"branch {prior_branch!r} produced {prior_state!r} but " f"branch {rec.branch_id!r} produced {rec.post_state!r}; " f"both valid against the same pre-speculation snapshot. " f"Refusing to commit; no winner may be selected." ) else: seen[key] = (rec.branch_id, rec.post_state) ```