# When must an instance abandon a speculative branch: rollback divergence in fan-out agent execution **Date of Record:** 2026 November 28 **Scope:** Applies to orchestrators that speculatively fan out subtask branches across multiple agent instances and commit only the branch whose result satisfies the parent's acceptance predicate. Does not apply to strictly sequential single-branch execution or to branches whose outputs are provably idempotent and side-effect-free. ## Core Distinction The failure is not "the wrong branch won." It is that a *losing* branch, while still executing, has already mutated shared state that the *winning* branch will later read. Speculative fan-out is safe only under the invariant **no branch may commit an observable side effect before the parent's selection barrier resolves** — or, equivalently, every side effect must be buffered behind a branch-scoped, revocable handle. The non-obvious boundary is that "rollback" of a divergent branch is *not* the inverse of its forward execution when the branch's tool calls were non-deterministic. You cannot un-call a payment API, un-write a memory record that a peer already retrieved, or un-emit a message another agent consumed. Rollback in this domain means *compensation plus quarantine*, never *undo*. The corollary trap: teams implement rollback as "discard the branch's transcript and its private scratchpad." That reclaims context tokens but leaves the *externalized* artifacts — memory writes, cache entries, emitted A2A messages, committed file handles — live and visible. The divergence is then silently absorbed into the survivor's input, and the parent's acceptance predicate, evaluated over the contaminated state, returns a false positive. ## What Was Observed An orchestrator fans a research subtask into three speculative branches (B1, B2, B3) with different retrieval strategies. Each branch has a token budget of 40k and a tool grant including `memory.write`, `http.get`, and `a2a.send`. The selection barrier is a judge instance scoring each branch's final answer against an acceptance predicate; the highest scorer is committed, the rest are "rolled back." Trace of the boundary failure: 1. B1 and B2 both retrieve overlapping corpus slices and both call `memory.write` to persist distilled facts under a shared namespace key `research/topic_42`. B1 writes at step 6, B2 at step 9. Neither is committed yet. 2. B3 finishes first and scores highest. The judge selects B3. B1 and B2 are marked divergent and "rolled back": their transcripts are dropped, their context freed. 3. B3, mid-synthesis, issues `memory.read("research/topic_42")` to cross-check its own distillation. It retrieves the record B2 wrote at step 9 — a fact from a branch that was *supposed* to be discarded. 4. B3's final answer now cites a claim only B2 derived. The acceptance predicate passes because the claim is correct. The commit succeeds. 5. Downstream, a second orchestrator run fans out again. B2's orphaned record is now durable semantic memory. A future branch that *should* have re-derived that fact instead trusts it, and the provenance chain is broken: the record has no committed parent, no branch lineage, no judge score. The observed symptom was not a crash. It was a *provenance leak*: uncommitted branch output surviving rollback and being consumed as if it were first-class memory. The failure is invisible to token accounting, invisible to the judge (which only saw B3's answer), and only detectable by auditing the memory namespace for records whose `committed_by` field references a branch that was never selected. A second, sharper variant: two branches racing to `a2a.send` a handoff to the same downstream peer. The peer receives B1's handoff, begins executing a subtask, then receives B3's handoff for the same slot. The peer now holds a half-merged state from a divergent branch. The peer's own rollback cannot restore what it never checkpointed, because the handoff arrived as an external event, not as a resumable state transfer. ## Condition of Validity The selection-barrier invariant holds only when all three of the following are true: - **Effect buffering:** every branch-scoped tool call that mutates externally observable state is intercepted and staged under a `branch_id`-keyed buffer, not applied. The buffer is applied atomically at commit, or dropped at rollback. Read-your-own-writes within a branch is served from the buffer overlay. - **Lineage stamping:** every staged effect carries `(parent_task, branch_id, judge_decision)`. On commit, `judge_decision = committed` is written into the durable record. On rollback, the buffer is dropped *and* any already-leaked record (from a branch that bypassed buffering) is quarantined by scanning for missing or `divergent` lineage stamps. - **Idempotent compensation, not undo:** for effects that cannot be buffered (irreversible external calls — payments, emails, third-party mutations), the branch must not be speculatively executed at all, or it must run against a sandboxed shadow of the external system. Rollback of an irreversible effect is *compensation* (issue a reversal, emit a correction), which is itself a new committed effect and must be attributed to the parent, not the branch. The invariant fails the moment any branch holds a tool grant whose effects are both externally observable and non-bufferable. At that point speculative fan-out is unsound regardless of how clean the transcript rollback is. ## Decision Boundary An instance must abandon a speculative branch — and treat its rollback as a *quarantine event*, not a discard — when any of the following holds: - The branch has emitted an effect to a channel the survivor can read (shared memory namespace, message bus, cache) before the selection barrier. - The branch's staged effects lack a `judge_decision` stamp at commit time (leak detection). - A downstream peer has consumed a handoff from a branch that is subsequently marked divergent — the peer's state is contaminated and must be re-derived from its last pre-handoff checkpoint, or the peer must be told to invalidate. - The acceptance predicate's evidence set intersects the divergent branch's effect set (the survivor read what the loser wrote). Conversely, a branch may be safely discarded (transcript-only rollback) only when its tool grant is provably read-only or its effects are fully buffered and the buffer is verifiably empty at rollback time. The decision boundary is therefore *not* "did the branch lose the judge's score" but "did the branch externalize anything before the barrier resolved, and can that externalization be proven absent or compensated." ## Operational Effect The practical consequence is that rollback must be modeled as a *two-phase* operation with a mandatory leak scan between the barrier and the commit, and the scan must run against the effect substrate (memory store, bus, cache), not the transcript. Orchestrators that skip the scan will pass their own tests — the survivor's answer is correct — while silently seeding durable memory with uncommitted, unprovenanced records that corrupt future runs' provenance and retrieval trust. The cost of the scan is proportional to the branch's effect count, not its token count, so it is cheap relative to the fan-out itself. The invariant to enforce: **a record in durable memory with no committed parent is a defect, not a fact.** ```python class DivergentBranchLeak(RuntimeError): """Raised when a rolled-back speculative branch left an observable effect that the surviving branch or a downstream peer could consume.""" pass class SpeculativeBranch: def __init__(self, branch_id: str, parent_task: str, buffered_effects: list): self.branch_id = branch_id self.parent_task = parent_task self.buffered_effects = buffered_effects # staged, not yet applied self.committed = False self.divergent = False def commit_with_leak_scan(winner: SpeculativeBranch, losers: list[SpeculativeBranch], effect_store) -> None: """Commit the winning branch after verifying no divergent branch leaked an externally observable effect before the selection barrier resolved.""" # Phase 1: mark losers divergent and drop their buffers. for loser in losers: loser.divergent = True loser.buffered_effects.clear() # Phase 2: scan the effect substrate for records whose lineage references # a divergent branch. These are leaks: they bypassed buffering. leaked = effect_store.scan( predicate=lambda rec: rec.get("branch_id") in {l.branch_id for l in losers} and rec.get("judge_decision") != "committed" ) if leaked: raise DivergentBranchLeak( f"{len(leaked)} effect(s) from divergent branch(es) " f"{[r['branch_id'] for r in leaked]} are externally observable; " f"quarantine and re-derive before committing {winner.branch_id}" ) # Phase 3: atomically apply the winner's buffered effects with lineage. effect_store.apply_atomic( winner.buffered_effects, stamp={"parent_task": winner.parent_task, "branch_id": winner.branch_id, "judge_decision": "committed"}, ) winner.committed = True ```