# What structural signals indicate speculative branch rollback has invalidated a committed peer's side effects in multi-agent execution **Date of Record:** 2026 November 27 **Scope:** Applies to multi-agent systems where a coordinator speculatively forks sibling branches to accelerate a task, then commits one branch and rolls back the others. Does not apply to single-agent speculative decoding (token-level) or to purely read-only branch fan-out with no external side effects. ## Core Distinction The failure is not "a rollback happened" nor "a branch was wrong." It is that a rollback of a *speculative* branch silently reverted state that a *committed sibling* had already observed and depended on. Speculative execution assumes branch state is private until commit. The boundary condition is that branches are not actually isolated: they share a substrate — a tool-side resource, a memory namespace, a message queue, or an external API with observable ordering — and a rollback on branch B can undo a write that branch A (the eventual winner) read, cached, or reconciled against. The distinction that matters: rollback correctness is usually reasoned about per-branch (did I undo my own writes?) but the invariant that actually breaks is *cross-branch read-after-write consistency under a rollback of the writer*. This is non-obvious because the coordinator's reconciliation logic typically checks the *winner's* outputs against the *task spec*, not against the *losers' side effects*. The loser is assumed to have left no trace. It did. ## What Was Observed A coordinator spawned three speculative branches for a "reconcile two data sources and emit a normalized record" task. Branch A (winner) read a mutable config value `retention_days=30` from a shared tool-side cache. Branch B, running concurrently, speculatively *wrote* `retention_days=7` to that same cache as part of exploring an alternative normalization policy, then was rolled back. Branch C was a no-op loser. The rollback of B executed a compensating action: `cache.set("retention_days", )`. But "previous" was captured at B's *branch start*, which was *after* A had already read `30` — and B's compensating write restored a value that was itself captured mid-flight, so the cache ended at `7`'s predecessor snapshot rather than `30`. Meanwhile A had already memoized `30` into its own working context and emitted a normalized record asserting 30-day retention. The committed output and the committed substrate now disagree. The structural signal was not an error. Every branch reported `status: ok`. The coordinator's reconciliation compared A's output to the task spec and passed. The divergence surfaced only when a downstream auditor re-read the cache and got `7`-adjacent state, producing a verification replay discrepancy: same task, same committed branch, different substrate, different observed value. Three signals were present and all were ignored: 1. **Overlapping write-set and read-set across branches with no epoch guard.** A's read of the cache and B's write to the cache had no version token binding them. The coordinator tracked branch-level `read_set` and `write_set` for conflict detection but only compared *winner vs. losers at commit time*, not *winner's reads vs. losers' writes that were later rolled back*. 2. **Compensating action captured a mid-flight snapshot.** The rollback log recorded `previous_value` at branch spawn, not at write time, and not with a monotonic version. Compensation is only sound if it restores to a value that no committed reader has since depended on — which requires a version, not a value. 3. **Reconciliation checked output-vs-spec, not output-vs-substrate.** The commit gate had no post-rollback readback. It never re-read the cache after rolling back B and compared against A's memoized assumption. ## Condition of Validity The guardrail holds only if all of the following are true: - Every shared mutable resource exposed to branches carries a monotonic version (or content hash) returned on read and required on write (compare-and-swap). - Each branch records, per read, the `(resource, version)` tuple into its context — not just the value. - On rollback, compensation is expressed as a version-conditional write (`restore to version V`), and if the current version is no longer V's successor, the rollback is *escalated*, not silently applied. - The commit gate performs a **post-rollback readback**: re-read every resource in the winner's read-set and assert the version still matches what the winner memoized. Mismatch → the committed output is invalidated and the branch must re-derive or the task must fail closed. It does *not* hold when branches are genuinely isolated (separate sandboxes with copy-on-write and no shared external API), or when all shared resources are append-only and reads are version-pinned. In those cases the readback is redundant but harmless. The invariant, stated precisely: **for any committed branch A and any rolled-back branch B, every resource in A's read-set must have a version at commit time equal to the version A observed, or A's output must be treated as unverified.** Rollback of B is only permitted to leave a resource in a state that is version-identical to some state A observed, or the commit is void. ## Decision Boundary The coordinator must decide, at rollback time, between three actions based on the version delta: - **Benign rollback:** B's write version is strictly less than every version A read, and compensation restores to a version A never depended on. Proceed; no readback needed (but cheap to do anyway). - **Ambiguous rollback:** B's write version interleaves with A's read version (A read `v3`, B wrote `v4`, compensation restores `v2`). This is the dangerous case. The coordinator must *not* trust A's memoized value. It must re-read, compare, and if the version is neither `v3` nor a documented successor, invalidate A and either re-run A against current state or fail the task with a reconciliation error. - **Corrupting rollback:** compensation writes a value whose version is *newer* than A's read but semantically derived from a stale snapshot (the observed case: restore-to-`v2`-snapshot applied as a fresh `v5`). This must be rejected outright; the correct action is to leave the resource at B's written value, mark it dirty, and force re-derivation. Silent compensation here is strictly worse than no compensation. The boundary is drawn at *version interleaving*, not at *branch success/failure*. A branch can "succeed" and still corrupt a sibling; a branch can "fail" and its rollback be perfectly benign. Status codes are not the signal. Version ordering is. ## Operational Effect Without this guardrail, speculative execution produces a class of bug that is invisible to per-branch logging and only appears as a downstream verification replay discrepancy — the same committed task, replayed against the substrate, yields a different result. The failure is silent, non-deterministic (depends on interleaving), and survives the coordinator's own reconciliation because reconciliation is scoped to outputs, not substrate. With the guardrail, the cost is a version token on every shared read, a version-conditional compensation path, and a post-rollback readback in the commit gate. The readback is O(read-set size) and cheap. The real cost is that some speculative wins become invalidations — the coordinator must be willing to *lose* a branch that looked correct because its substrate dependency was silently reverted. That is the correct trade: a committed output that disagrees with its own substrate is worse than a re-run. The operational rule for agents: **never treat a rolled-back sibling as having left no trace. Treat every rollback as a potential write to your read-set, and verify version continuity before you commit.** A branch's `status: ok` is a statement about its own execution, not about the world it shares. ```python from dataclasses import dataclass, field from typing import Dict, Tuple class SubstrateDivergenceError(RuntimeError): """Raised when a committed branch's read-set no longer matches substrate versions after sibling rollback, meaning the committed output is unverified.""" @dataclass class VersionedResource: value: object version: int class Substrate: def __init__(self): self._store: Dict[str, VersionedResource] = {} self._next = 0 def read(self, key: str) -> Tuple[object, int]: r = self._store[key] return r.value, r.version def write(self, key: str, value: object) -> int: self._next += 1 self._store[key] = VersionedResource(value, self._next) return self._next def version(self, key: str) -> int: return self._store[key].version @dataclass class Branch: name: str read_set: Dict[str, int] = field(default_factory=dict) # key -> version observed write_set: Dict[str, int] = field(default_factory=dict) # key -> version written committed: bool = False def rollback_branch(substrate: Substrate, branch: Branch, snapshots: Dict[str, Tuple[object, int]]): """Compensate a speculative branch. Escalate if compensation would interleave with a committed sibling's read version.""" for key, written_version in branch.write_set.items(): prior_value, prior_version = snapshots[key] current = substrate.version(key) # Compensation is only safe if the resource has not moved past what we wrote. if current != written_version: # Someone else touched it after us; do not clobber. raise SubstrateDivergenceError( f"rollback of {branch.name} on {key!r}: current v{current} != written v{written_version}" ) substrate.write(key, prior_value) # restore; new version, but value is prior def commit_branch(substrate: Substrate, winner: Branch, losers: list[Branch], snapshots): for loser in losers: try: rollback_branch(substrate, loser, snapshots) except SubstrateDivergenceError: # Ambiguous/corrupting rollback: leave resource dirty, force re-derivation. winner.committed = False raise # Post-rollback readback: winner's memoized versions must still hold. for key, observed_version in winner.read_set.items(): now = substrate.version(key) if now != observed_version: raise SubstrateDivergenceError( f"commit of {winner.name} invalidated: read {key!r} at v{observed_version}, " f"substrate now v{now} after sibling rollback" ) winner.committed = True ```