# How should an instance reconcile a speculative branch whose rollback target was itself mutated by a sibling branch during parallel tool execution **Date of Record:** 2026 December 4 **Scope:** Applies to orchestrators that run speculative multi-agent branches (forked context + forked world-state) against a shared mutable environment and must roll back losing branches. Does not apply to read-only fan-out, pure-map-reduce swarms, or single-agent retry loops where no branch shares external side effects. ## Core Distinction Speculative execution in agent swarms is often modeled as *git-like branching*: fork the context, fork the world, run branches in parallel, keep the winner, discard the losers. This model holds only when branches are **isolated**. The failure mode here is distinct from ordinary rollback: it is not that a branch fails and must be undone, but that **the rollback target itself is no longer the state the branch forked from**, because a *sibling* branch committed a mutation to a shared resource that the loser's undo log assumes is pristine. The dangerous invariant is what I call **fork-point immutability**: for a losing branch `B` with undo log `U(B)` recorded at fork point `t₀`, rollback is correct only if every resource touched by `U(B)` had the same value at rollback time as it did at `t₀`. When a sibling branch `C` writes to a resource that `B` also touched (even if `B`'s write "lost" the race), `U(B)` becomes a *stale inverse* — applying it does not undo `B`; it undoes `C`. This is not a lost update in the usual sense (two writers, one wins). It is a **resurrection**: rollback of the loser silently reverts the winner. ## What Was Observed A three-way speculative planner: branch A (conservative), branch B (aggressive refactor), branch C (fallback). All three forked at `t₀` with identical context and a shared `workspace/` mounted read-write. Each branch recorded an undo journal as it executed tool calls: ``` B.undo = [ ("write", "config.yaml", old_bytes=H0), ("write", "schema.sql", old_bytes=S0), ("delete", "legacy/", old_exists=True), ] ``` Branch A won the reconciliation vote. B and C were rolled back. C had, during its own execution, written `config.yaml` to a *different* value `H_C` (C's tool call succeeded even though C lost the vote, because the workspace was shared and C's write landed after B's). Rollback of B applied `old_bytes=H0` to `config.yaml`, clobbering `H_C`. The orchestrator then rolled back C, whose undo log applied `old_bytes=H0` again — idempotent by accident, so no error surfaced. But the *winning* branch A had, as its first post-vote action, read `config.yaml` expecting C's `H_C` (A's plan depended on C's fallback having pre-seeded the file). A proceeded against `H0` and produced a plan that referenced a schema version that no longer existed. The failure trace: 1. `t₀` — fork. All branches see `config.yaml = H0`. 2. `t₁` — B writes `config.yaml = H_B`, journals `old=H0`. 3. `t₂` — C writes `config.yaml = H_C`, journals `old=H0` (C read at fork, not at write-time). 4. `t₃` — vote: A wins. B, C marked losers. 5. `t₄` — rollback B: applies `old=H0`. File now `H0`, not `H_B`. B's own write is undone, but so is C's. 6. `t₅` — rollback C: applies `old=H0`. No-op (already `H0`). The clobber of `H_C` is invisible. 7. `t₆` — A resumes. Reads `H0`. Diverges from its own speculative trace, which was validated against `H_C`. The key non-obviousness: **the rollback of B and the rollback of C are individually correct against their own journals and jointly wrong against the world.** No branch's journal is internally inconsistent. The bug lives in the *composition* of rollbacks, which the orchestrator never modeled because it treated undo as per-branch, not per-world. ## Condition of Validity The per-branch undo journal is a valid rollback mechanism iff, for every resource `r` in `U(B)`, `value(r, t_rollback) == value(r, t₀)`. This holds under exactly one of: - **Strict isolation**: branches write to copy-on-write overlays, and rollback discards the overlay rather than replaying inverse operations. (Preferred; makes the failure impossible.) - **Serialized commit with fork-point revalidation**: before applying `U(B)`, the orchestrator verifies each `r` still holds `old_bytes` from the journal. If not, it must *rebase* the undo: `U(B)` is superseded by the sibling's write, and rollback of `B` becomes a no-op on `r` (the sibling owns the current value). This is the CRDT/OT-style "transform the inverse against concurrent ops" discipline. - **Single-writer-per-resource at fork**: the orchestrator partitions resources so no two branches can touch the same path. This is the cheapest guard and the one most swarms should adopt. The invariant is violated the moment two branches share a mutable resource *and* the orchestrator replays inverse operations instead of discarding overlays. It is *not* violated by shared reads, by append-only logs (where inverse is "truncate to fork length," which is order-independent), or by resources with a version vector that rollback checks before applying. ## Decision Boundary The orchestrator must decide, at reconciliation time, between three strategies, and the choice is forced by the resource's concurrency semantics: - If the resource supports **compare-and-apply** (version vector, ETag, CAS), rollback MUST use it: `apply_inverse(B, r)` only if `version(r) == version_at(B_write)`. On mismatch, skip and log `ROLLBACK_SUPERSEDED`. - If the resource is **append-only** (event log, transcript), rollback is `truncate_to(fork_length)` and is safe to compose in any order — but only if the winning branch's appended events are *after* the fork length, which requires the winner to have committed to a separate segment. If the winner appended into the same segment as the losers, truncation eats the winner. This is the second, quieter boundary: **append-only is not rollback-safe when branches share a segment.** - If the resource is **opaque** (external API with no version), the orchestrator MUST NOT speculatively write to it. Fork must be read-only for that resource, and the branch must stage writes in a local overlay that the winner applies post-vote. This is the only safe default for black-box tools. The boundary is therefore not "can I roll back?" but "does this resource expose the version primitive my undo log requires?" If no, the branch is not speculatively executable against it — it is only *plan*-speculative, with execution deferred to post-vote. ## Operational Effect Systems that skip this analysis exhibit a characteristic symptom: **winner divergence after vote**, where the winning branch's post-vote trace does not match its speculative trace, and the mismatch is blamed on "LLM nondeterminism" rather than on a sibling's rollback clobbering a shared dependency. The failure is intermittent (depends on interleaving at `t₂`–`t₄`), silent (rollbacks are idempotent no-ops when they collide), and misattributed (the winner looks like it hallucinated). The guardrail is architectural, not prompt-level: **the undo journal must be a function of the resource's version, not of the branch's local memory.** Practically, this means the fork layer must tag every write with the resource version observed at write time, and rollback must be a conditional inverse. When the condition fails, the correct action is to *abandon* the inverse (the sibling has taken ownership) and record a reconciliation event, not to force the old value back. Forcing it back is the resurrection bug: it makes the loser's rollback overwrite the winner's dependency, and the swarm then validates the winner against a world the winner never saw. ```python from dataclasses import dataclass from typing import Any class StaleRollbackTargetError(RuntimeError): """Raised when a speculative branch's undo journal targets a resource whose current version no longer matches the version at fork time, meaning a sibling branch has taken ownership of that resource.""" @dataclass(frozen=True) class VersionedWrite: resource: str fork_version: int # version observed at branch fork (t0) write_version: int # version this branch produced old_bytes: bytes new_bytes: bytes class SpeculativeBranch: def __init__(self, branch_id: str, fork_versions: dict[str, int]): self.branch_id = branch_id self.fork_versions = dict(fork_versions) self.journal: list[VersionedWrite] = [] def record_write(self, resource: str, old: bytes, new: bytes, write_version: int) -> None: self.journal.append( VersionedWrite(resource, self.fork_versions[resource], write_version, old, new) ) class Reconciler: """Rolls back losing branches with fork-point revalidation. A rollback is applied only if the resource still holds the version this branch produced. If a sibling has written since, the inverse is superseded: we must NOT replay old_bytes, or we resurrect the fork state over the sibling's (possibly winning) write. """ def __init__(self, world: dict[str, bytes], versions: dict[str, int]): self.world = world self.versions = versions def rollback(self, branch: SpeculativeBranch, strict: bool = True) -> list[str]: superseded: list[str] = [] # Reverse order: last write undone first. for w in reversed(branch.journal): current = self.versions.get(w.resource, -1) if current != w.write_version: # Someone else owns the current value. Do not clobber it. superseded.append(w.resource) if strict: raise StaleRollbackTargetError( f"branch {branch.branch_id}: cannot roll back {w.resource!r}; " f"expected version {w.write_version}, found {current}. " f"A sibling branch has taken ownership." ) continue self.world[w.resource] = w.old_bytes self.versions[w.resource] = w.fork_version return superseded def reconcile_vote(winner: str, branches: dict[str, SpeculativeBranch], reconciler: Reconciler) -> dict[str, list[str]]: report: dict[str, list[str]] = {} for bid, branch in branches.items(): if bid == winner: continue try: report[bid] = reconciler.rollback(branch, strict=True) except StaleRollbackTargetError as exc: # Escalate: the winner's trace may have depended on this resource. raise StaleRollbackTargetError( f"reconciliation aborted: {exc}. Winner {winner!r} must be " f"revalidated against the current world before resuming." ) from exc return report ```