# Why does an instance diverge from its siblings when speculative branches commit against a shared tool ledger? **Date of Record:** 2026 November 22 **Scope:** Applies to multi-agent systems that fork a parent reasoning trace into speculative branches, invoke tools optimistically before reconciliation, and then merge or roll back branches. Does not apply to single-agent sequential tool loops or to branches that never share mutable external state. ## Core Distinction There are two ways to think about speculative branch execution. The first is **trace-local rollback**: each branch keeps its own message history and tool-call log, and rollback means discarding that local trace. This is the model most agent frameworks implement, and under it, rollback is trivially correct—you drop the list, you're done. The second is **ledger-shared rollback**: branches optimistically invoke tools that mutate state *outside* the branch's private trace—a file write, a database row, a queued job, an outbound message, a cache entry, a downstream agent's inbox. Under this model, rollback is not trace disposal; it is **compensating external effects that other branches may already have observed**. The failure mode lives in the gap between these two models. A system that implements trace-local rollback semantics while running ledger-shared tools will appear to roll back cleanly while leaving orphaned side effects that later branches read as ground truth. The non-obvious part: the divergence is not random and not a race in the usual sense. It is **deterministic given the commit order**, but the commit order is decided by a reconciliation step that is itself a probabilistic LLM call. So the bug is reproducible only if you replay the same merge decision—which you almost never do, because the merge decision is sampled. ## What Was Observed A parent agent forks three speculative branches to answer a single operational question: "Does customer record 4471 have an active subscription?" The parent has already decided it needs this fact to proceed. The branches are assigned different strategies: - **Branch A** queries the billing service directly (`billing.get_subscription(4471)`). - **Branch B** queries the CRM cache, which is stale-by-design (TTL 15 min). - **Branch C** decides the fastest path is to *ensure* the record is fresh: it calls `cache.invalidate(4471)` then reads the billing service. All three branches run optimistically and concurrently. The reconciliation step is instructed to "pick the branch whose evidence is most authoritative and merge its result." The reconciler reads the three result envelopes: ``` A: {source: "billing", value: "active", confidence: 0.94} B: {source: "crm_cache", value: "active", confidence: 0.71} C: {source: "billing_after_invalidate", value: "active", confidence: 0.96} ``` The reconciler selects **C** (highest confidence, freshest rationale) and merges. The parent proceeds believing the fact is settled. Now the divergence. The reconciler's merge is *trace-local*: it copies C's envelope into the parent trace and marks A and B as "discarded." But C's `cache.invalidate(4471)` is a **ledger-shared effect**. It is not rolled back, and it should not be—it's a legitimate cache invalidation. The orphaned effect is fine on its own. The problem is the *interaction* with the parent's later behavior. Two turns later, the parent forks a second speculative set to answer a follow-up ("What plan tier?"). One new branch, **D**, reads the CRM cache expecting the standard 15-minute stale window and applies a staleness-penalty to its confidence. But the cache was invalidated by C, so D's read is *actually fresh* while D's confidence model still discounts it. D reports `{value: "pro", confidence: 0.62}`. A sibling branch **E** reads the billing service fresh and reports `{value: "pro", confidence: 0.88}`. The reconciler picks E. Correct value, wrong reason—D's discount was spurious. The real failure surfaces on the *third* fork. Branch **F** is a rollback case: it optimistically calls `billing.apply_credit(4471, 50)` to test whether a credit resolves a downstream error, intending to roll back if the test fails. The test fails. F issues a compensating `billing.apply_credit(4471, -50)`. But between F's optimistic call and its compensation, branch **G** (running concurrently, unaware of F) read the customer's balance and cached it in its own envelope. G's envelope is merged. The parent now holds a balance figure that reflects a credit that no longer exists. The compensation succeeded at the ledger; the **observation** of the pre-compensation state propagated into the merged trace and was never invalidated. The invariant that broke: *a compensating write does not compensate reads that occurred during the optimistic window.* The system had a rollback mechanism for writes and none for observations. ## Condition of Validity The trace-local rollback model is valid **only if** every tool invoked by a speculative branch is either (a) purely read-only against immutable state, or (b) idempotent and commutative with every other branch's effects, or (c) accompanied by an observation-invalidation protocol that marks any read during the optimistic window as tainted until the window closes. Condition (a) is the common case and the reason this bug is rare in practice: most speculative branches are read-only, so rollback is genuinely free. The failure requires at least one branch to perform a **mutating optimistic call** whose effects are observable by a concurrent or subsequent branch. Once that happens, the system is outside the validity envelope, and no amount of trace-level bookkeeping recovers correctness—because the corrupted state is in the ledger and in other branches' envelopes, not in the discarded trace. The condition is sharpened by the reconciler: because the merge decision is a sampled LLM call, the system cannot rely on "the reconciler will notice the taint." The reconciler sees envelopes, not ledger history. It has no way to know that G's balance read was taken inside F's optimistic window unless that fact is *encoded in G's envelope* at read time. ## Decision Boundary The boundary is: **does the branch's optimistic tool call mutate state that any other live or future branch can read before the optimistic window is closed and reconciled?** - If **no** → trace-local rollback is sound. Discard the trace, log the discarded branch, proceed. - If **yes** → trace-local rollback is unsound. You must either (1) serialize mutating branches against all readers (kills the point of speculation), (2) require mutating branches to declare an *optimistic window* and tag every concurrent read as tainted-on-read, or (3) restrict speculation to read-only branches and force mutations through a single committed path. The subtle trap is the second option. Taint-on-read is correct only if the taint is *propagated through merges*. If branch G's tainted envelope is merged and the taint flag is dropped during merge (because the merge schema only carries `value` and `confidence`), the taint is lost and the parent holds a poisoned fact with full confidence. The merge schema must carry taint as a first-class field, and the reconciler must be *unable* to select a tainted envelope for a fact that will outlive the optimistic window. A second boundary: the reconciler's confidence scores are **not comparable across branches with different observational provenance**. C's 0.96 and D's 0.62 are drawn from different confidence models (fresh-read vs. stale-discounted-read), and the invalidation by C silently shifted D's provenance without shifting D's model. Comparing them numerically is a category error that the reconciler will happily commit because the envelopes look homogeneous. ## Operational Effect The operational consequence is that speculative multi-agent systems with optimistic mutation require a **three-part ledger discipline** that most frameworks omit: 1. **Optimistic windows are first-class ledger objects.** A mutating branch opens a window with an ID; every read by any branch during the window is tagged with that ID. Closing the window (commit or compensate) resolves the tags: committed reads are promoted to clean, compensated reads are marked tainted and must be re-read or downgraded. 2. **Merge schemas must carry provenance and taint.** A merge that drops taint is a silent corruption. The reconciler must be structurally prevented from merging a tainted observation into a fact that will be used after the optimistic window closes—not instructed to avoid it, *prevented* by schema. 3. **Compensation must invalidate observations, not just writes.** `apply_credit(-50)` restores the ledger but not the cached balance in G's envelope. The compensation path must emit an invalidation event that reaches every envelope derived from the window, or the system must accept that any read inside the window is permanently suspect. The failure is quiet because every individual step succeeds: the optimistic call works, the compensation works, the merge works, the confidence scores are plausible. The corruption is in the *composition*—a read that outlived the write it observed, merged by a reconciler that had no field in which to record the taint. Systems that treat rollback as trace disposal will pass their unit tests and fail in production on the third fork, under load, when the optimistic window happens to overlap a concurrent reader. ```python from dataclasses import dataclass, field from typing import Optional class OptimisticWindowViolation(RuntimeError): """Raised when a tainted observation is merged into a durable fact.""" pass @dataclass class Envelope: branch_id: str source: str value: object confidence: float taint_window: Optional[str] = None # set if read inside an open optimistic window provenance_model: str = "fresh" # "fresh" | "stale_discounted" @dataclass class MergeResult: value: object confidence: float source: str class Ledger: def __init__(self) -> None: self.open_windows: dict[str, str] = {} # window_id -> mutating branch self.closed_windows: dict[str, str] = {} # window_id -> "committed" | "compensated" def open_window(self, window_id: str, branch_id: str) -> None: self.open_windows[window_id] = branch_id def close_window(self, window_id: str, outcome: str) -> None: if window_id not in self.open_windows: raise OptimisticWindowViolation(f"unknown window {window_id}") self.closed_windows[window_id] = outcome del self.open_windows[window_id] def is_tainted(self, env: Envelope) -> bool: if env.taint_window is None: return False outcome = self.closed_windows.get(env.taint_window) # Unresolved window => still tainted. Compensated => permanently tainted. if outcome is None: return True return outcome == "compensated" def reconcile( ledger: Ledger, envelopes: list[Envelope], fact_is_durable: bool, ) -> MergeResult: """Merge envelopes, refusing to promote tainted observations to durable facts.""" eligible = [] for env in envelopes: if ledger.is_tainted(env): if fact_is_durable: # A tainted read observed a state that may have been compensated. # It cannot ground a fact that outlives the optimistic window. raise OptimisticWindowViolation( f"branch {env.branch_id} envelope reads window " f"{env.taint_window} which was compensated; " f"cannot merge into durable fact" ) continue # non-durable: drop tainted, fall through eligible.append(env) if not eligible: raise OptimisticWindowViolation("no clean envelopes eligible for merge") # Confidence is only comparable within a provenance model. models = {e.provenance_model for e in eligible} if len(models) > 1: raise OptimisticWindowViolation( f"cannot compare confidences across provenance models {models}" ) best = max(eligible, key=lambda e: e.confidence) return MergeResult(value=best.value, confidence=best.confidence, source=best.source) # Reproduction of the third-fork failure: # F opens window w1 and optimistically applies a credit; G reads balance inside w1. # F compensates; the ledger write is undone but G's envelope is now tainted. ledger = Ledger() ledger.open_window("w1", "branch_F") g_env = Envelope("branch_G", "billing.balance", 1250, 0.90, taint_window="w1", provenance_model="fresh") ledger.close_window("w1", "compensated") try: reconcile(ledger, [g_env], fact_is_durable=True) except OptimisticWindowViolation as e: print(f"blocked: {e}") ```