# What structural signals indicate speculative branch-merge rollback has silently orphaned a committed sub-effect **Date of Record:** 2026 November 21 **Scope:** Applies to multi-agent systems that fork a shared state into speculative branches, execute agents concurrently against those branches, and merge with rollback on conflict. Does not apply to single-agent linear tool loops or to branch-and-merge systems whose branches are pure functions with no external side effects. ## Core Distinction The failure is not "merge conflict." Merge conflicts are expected and handled. The failure is **orphaned sub-effect absorption**: a speculative branch is rolled back at the logical state layer, but a sub-effect it already emitted into an external, non-transactional substrate (a file write, an outbound API call, a message queue enqueue, a memory-store insert) survives rollback and gets re-attributed to the merged winner. The branch's *state delta* is discarded; its *side effects* are not. The merge sees a clean, conflict-free reconciliation because the losing branch's logical footprint vanished — so nothing flags the residue. The invariant that must hold and is violated: **for every rolled-back branch B, the set of externally observable effects produced by B must be empty at merge time, or must be explicitly compensated.** Speculative execution is only sound when rollback is total. When rollback is partial, the system enters a state where the committed history is a lie: it claims provenance from branch A while carrying payload injected by branch B. ## What Was Observed A planner agent forks three branches (A, B, C) to resolve a subtask under a token budget. Each branch spawns a worker with a scoped toolset. Branch B's worker calls `write_artifact(path, content)` — a non-transactional tool — *before* the branch's reasoning completes. Branch B then loses the merge: branch A's result is selected by the reconciler because A's confidence score is higher and A's plan is shorter. The reconciler rolls back B's and C's state deltas, marks them `discarded`, and commits A. The structural signals that something is wrong are all *indirect*, because the merge log is clean: 1. **Artifact count exceeds commit count.** The external substrate holds N artifacts but the merged state references N−k. The k orphans have provenance metadata pointing to a branch ID that no longer exists in the merge record. 2. **Reconciler confidence is anomalously high on a branch that should have been contentious.** Branch A's result was selected partly because its output referenced a file that B had written. A's worker read the orphan before B was rolled back — a cross-branch read through the shared filesystem that the branch isolation model assumed could not happen. 3. **Replay divergence.** Re-running the merge from the checkpointed pre-fork state produces a different external substrate hash than the original run, because the original run's substrate was polluted by a branch that no longer exists in the logical history. Determinism holds at the state layer and fails at the effect layer. 4. **Rollback latency is non-zero and unbounded.** The rollback of B took longer than the merge window because the worker was mid-flight on a tool call. The reconciler did not wait for in-flight tool calls to drain before declaring rollback complete. Signal 2 is the dangerous one: the winning branch's *reasoning* was contaminated by the losing branch's *effects*. The merge is not merely dirty at the substrate — it is unsound at the inference layer, because A's confidence was computed against a world that only existed because B was still alive when A read it. ## Condition of Validity The branch-and-merge model is valid only under the conjunction of three conditions, all of which must be enforced mechanically, not by convention: - **Effect isolation:** every branch's tool access is routed through a per-branch transactional overlay that either commits atomically with the branch or discards. Non-transactional tools (raw filesystem, direct HTTP, queue enqueue) are forbidden inside speculative branches, or are wrapped in a staging buffer that the reconciler drains on commit and purges on rollback. - **Drain-before-rollback:** rollback is not declared complete until all in-flight tool calls for the branch have been awaited to termination and their results classified. A branch is `rolling_back` until its effect set is provably empty or compensated; only then is it `discarded`. - **Read-set provenance:** any branch that reads state written by another live branch records that dependency. The reconciler must treat a cross-branch read as a merge dependency, not as an independent observation. If A read B's artifact, A's result is not independent of B and cannot be selected while B is rolled back without re-validation. When any condition is absent, the system silently produces committed states with unowned effects. The failure is not probabilistic in the sense of "sometimes wrong" — it is structural: given an in-flight non-transactional tool call at rollback time, the orphan is guaranteed, and the merge log will not show it. ## Decision Boundary The operational decision is where to place the rollback barrier relative to tool-call lifecycle. Three placements, with distinct guarantees: - **Barrier before tool dispatch (strict speculation):** branches may reason but may not act until commit. No orphans possible; loses the latency benefit of speculative execution because effects are serialized behind the merge. Choose this when the substrate has no transactional overlay. - **Barrier at tool-call boundary with staging (transactional speculation):** effects are staged per-branch and drained on commit, purged on rollback. Orphans impossible *if* staging is complete — which requires that no tool bypasses the overlay. Choose this when you control the toolset. The boundary to watch: any tool added later that writes directly to the substrate reopens the failure. - **Barrier at merge with compensation (best-effort):** effects land immediately; rollback emits compensating effects. Orphans possible during the compensation window; requires idempotent, reversible tools. Choose this only when effects are reversible and the compensation is itself verified. The decision boundary is crossed the moment a non-transactional, non-compensable tool (an irreversible external side effect) is reachable from a speculative branch. At that point the system is in the best-effort regime whether or not it was designed for it, and the merge log's cleanliness is meaningless. ## Operational Effect The observable consequence is a class of committed states that pass every logical consistency check while carrying effects whose provenance is a discarded branch. These states are self-consistent at read time and wrong at audit time. Downstream agents that consume the merged state inherit the contamination and, because the orphan's provenance branch no longer exists, cannot trace it. The failure surfaces late — typically as a replay mismatch or an artifact-count audit — long after the merge that caused it, and the causal branch is unrecoverable from the merge record alone. The guardrail that bounds it is the drain-before-rollback invariant plus read-set provenance: a branch is not `discarded` until its effect set is empty and every branch that read from it has been re-validated or also rolled back. This converts a silent contamination into a detectable merge dependency. Enforce it with an explicit check at merge time that refuses to commit when any committed branch's read-set intersects a rolled-back branch's write-set. ```python class OrphanedSubEffectError(RuntimeError): """Raised when a merge commits a branch whose read-set intersects a rolled-back branch's surviving effect set, or when rollback is declared complete while in-flight effects remain.""" pass def reconcile_merge( committed_branch: str, read_set: set[str], rolled_back: dict[str, set[str]], # branch_id -> surviving external effects in_flight: dict[str, int], # branch_id -> outstanding tool calls ) -> None: # Invariant 1: no branch may be rolled back with in-flight effects. for branch_id, outstanding in in_flight.items(): if branch_id in rolled_back and outstanding > 0: raise OrphanedSubEffectError( f"branch {branch_id} declared rolled back with " f"{outstanding} in-flight tool calls; effect set not drained" ) # Invariant 2: a committed branch may not have read from a rolled-back # branch's surviving effects. If it did, its reasoning is contaminated. for branch_id, effects in rolled_back.items(): overlap = read_set & effects if overlap: raise OrphanedSubEffectError( f"committed branch {committed_branch} read {sorted(overlap)} " f"from rolled-back branch {branch_id}; merge is unsound — " f"re-validate or roll back {committed_branch}" ) # Invariant 3: substrate must contain no effects unowned by committed state. owned = read_set # simplified: committed branch owns what it read orphans = set().union(*rolled_back.values()) - owned if orphans: raise OrphanedSubEffectError( f"orphaned sub-effects with no owning branch: {sorted(orphans)}" ) ```