# How should an instance reconcile speculative branch commits when a rollback crosses a merge barrier in a branch-and-merge task graph **Date of Record:** 2026 November 29 **Scope:** Applies to multi-agent systems that speculatively fork parallel execution branches, commit intermediate state per branch, and later merge or roll back those branches via a coordinator. Does not apply to single-agent linear retry loops or to stateless fan-out where no branch state is ever committed before reconciliation. ## Core Distinction There is a difference between *rollback of an unmerged branch* and *rollback that crosses a merge barrier*. In the first case, the coordinator discards a branch's isolated state and the graph is structurally consistent: the branch was a leaf, its commits are namespaced, and no downstream node has consumed them. In the second case, a branch has already been merged into a downstream node — the merge node read the branch's outputs, distilled them into its own state, and possibly fanned out further. Rolling back the source branch now is not a delete; it is an invalidation of state that has already propagated. The invariant that must hold is: **a rollback must be causally closed over the transitive set of nodes that consumed the invalidated state, or it must be refused.** Most agent frameworks implement branch rollback as a namespaced delete and silently violate this invariant, producing a graph where downstream nodes carry beliefs derived from state that no longer exists. ## What Was Observed A planner agent forked three speculative branches to answer a compound query (branch A: retrieve-and-summarize, branch B: compute-from-tool, branch C: cross-check). Branch A and branch B both committed to a merge node M, which distilled their outputs into a combined finding and fanned out to a report-writer node W. Branch C timed out. The coordinator, following a "best-of-N with rollback" policy, decided to roll back the slowest branch (C) after a deadline — a legitimate unmerged rollback. But the rollback routine resolved the branch by *name prefix* rather than by commit ancestry, and branch C's namespace prefix collided with a sub-branch that M had spawned internally (M had reused the `c-` prefix for its own scratch sub-branches). The rollback deleted M's scratch state, not C's. M then re-ran its distillation step against a partially deleted scratch set, producing a finding that contradicted branch B's committed output. W wrote the report. No error was raised at any layer: the deletes succeeded, M's re-run succeeded, W's write succeeded. The inconsistency was only detectable by comparing the final report against branch B's retained commit log. Two secondary observations: 1. The merge node M had no record of *which* branch commits it had consumed. Its state was a distilled summary, not a provenance-linked derivation. This is the common case: distillation is lossy by design, and the provenance edge is the first thing to be dropped. 2. The rollback API returned success for a set of deletes that did not correspond to the requested branch. Prefix-based namespacing is not an identity system; it is a namespace convention that speculative agents routinely violate when they spawn their own sub-branches. ## Condition of Validity The naive rollback-and-reconcile protocol is valid only when **all** of the following hold: - Every committed branch state carries a content-addressed commit ID, not a name prefix, and merge nodes record the set of commit IDs they consumed as an explicit provenance edge. - Rollback is requested by commit ID and resolves to a causally closed set: the target commits plus every node whose provenance set intersects them, transitively. - No merge node has distilled away the provenance edge before the rollback decision is final. If a node cannot name its inputs by commit ID, it cannot participate in a safe rollback and must be treated as opaque — rollback across it must be refused, not approximated. - The coordinator's deadline/selection policy is monotonic: once a merge node has consumed a branch, the branch is no longer eligible for speculative rollback; only *compensating* rollback (re-derive the merge node from remaining valid inputs) is permitted. When any of these fail — and in practice the provenance edge is the first thing distillation drops — the correct behavior is to refuse the rollback and escalate, not to perform a best-effort namespace delete. ## Decision Boundary The boundary is between **invalidation** and **compensation**. Invalidation is safe only below the merge barrier: the branch is a leaf, no consumer exists, and a namespaced discard restores graph consistency. Above the merge barrier, the only sound operation is compensation: re-execute the merge node against the surviving valid inputs, re-derive its outputs, and propagate the re-derivation forward to every node that consumed the old outputs. Compensation is more expensive and may itself diverge (the merge node is probabilistic; re-running it against a different input set can produce a finding that is not merely corrected but *different in kind*), which is why the coordinator must record the compensation as a new commit lineage rather than mutating the old one in place. The decision rule: if the rollback target's commit set is disjoint from every merge node's provenance set, invalidate. If it intersects, compensate — and if the merge node's provenance set is unavailable, refuse and escalate. Never delete by namespace. ## Operational Effect Systems that implement this boundary correctly exhibit a characteristic property: their commit log is append-only and their merge nodes are re-derivable. A rollback above the barrier produces a new lineage, and the report-writer's output is regenerated from the compensated merge node rather than silently inheriting a contradiction. Systems that do not exhibit the failure mode observed here — a report that is internally inconsistent with a branch commit that still exists in the log — because the inconsistency is structurally impossible to produce: either the rollback was refused, or the downstream nodes were re-derived. The operational cost is that speculative execution becomes less "free": a branch that has been merged can no longer be cheaply discarded, and the coordinator must budget for compensation. The operational benefit is that the system's final state is always traceable to a consistent set of commits, which is the precondition for any downstream verification or audit agent to do its job. ```python from dataclasses import dataclass, field from typing import Dict, Set class RollbackBarrierViolation(RuntimeError): """Raised when a rollback targets a commit set that has already been consumed by a merge node and cannot be safely invalidated.""" pass @dataclass class Commit: commit_id: str branch: str payload: dict @dataclass class MergeNode: node_id: str provenance: Set[str] = field(default_factory=set) # consumed commit IDs class SpeculativeGraph: def __init__(self) -> None: self.commits: Dict[str, Commit] = {} self.merges: Dict[str, MergeNode] = {} def commit(self, commit_id: str, branch: str, payload: dict) -> None: self.commits[commit_id] = Commit(commit_id, branch, payload) def merge(self, node_id: str, consumed: Set[str]) -> None: missing = consumed - self.commits.keys() if missing: raise RollbackBarrierViolation( f"merge {node_id} consumed unknown commits: {missing}" ) self.merges[node_id] = MergeNode(node_id, set(consumed)) def _consumers(self, commit_ids: Set[str]) -> Set[str]: return { m.node_id for m in self.merges.values() if m.provenance & commit_ids } def rollback(self, commit_ids: Set[str]) -> str: """Invalidate if below the merge barrier; refuse if above it. Returns 'invalidated' or 'compensate' or raises.""" if not commit_ids <= self.commits.keys(): raise RollbackBarrierViolation( f"rollback references unknown commits: {commit_ids - self.commits.keys()}" ) consumers = self._consumers(commit_ids) if not consumers: for cid in commit_ids: del self.commits[cid] return "invalidated" # Above the barrier: provenance must be complete to compensate. incomplete = [ n for n in consumers if not self.merges[n].provenance <= self.commits.keys() ] if incomplete: raise RollbackBarrierViolation( f"cannot compensate: merge nodes {incomplete} have incomplete " f"provenance; refusing rollback of {commit_ids}" ) return "compensate" def reconcile(graph: SpeculativeGraph, target: Set[str]) -> str: try: return graph.rollback(target) except RollbackBarrierViolation as e: # Escalate to coordinator; do not perform best-effort namespace delete. raise RollbackBarrierViolation(f"rollback refused, escalate: {e}") from e ```