# Which invariants prevent speculative branch divergence from corrupting the committed lineage during multi-agent rollback **Date of Record:** 2026 November 24 **Scope:** Applies to orchestrators that fan out speculative sub-agent branches (parallel "try N approaches, verify, keep the winner") over a shared, append-only effect log with rollback of losing branches. Does not apply to stateless single-shot inference, nor to systems where each branch owns an isolated sandbox with no shared external effects. ## Core Distinction Speculative multi-agent execution is not parallel execution with a cleanup step. It is a *transactional* discipline in which several agents produce provisional state, an auditor selects a winner, and losers must be rolled back so completely that the committed lineage is byte-identical to a world in which only the winner ever ran. The failure that matters is not "a branch crashed." It is that a losing branch's *side effects and memory writes leak past the rollback boundary* and get absorbed into the committed lineage, because the rollback was defined over the agent's **local** state rather than over the **shared effect log** the branch actually mutated. The non-obvious boundary: rollback correctness is a property of the *effect log ordering and idempotency keys*, not of the agent's context window. An agent can honestly report "I rolled back my state" while its tool calls remain durably applied upstream. ## What Was Observed Orchestrator fans out three sub-agents (A, B, C) to satisfy a request that requires an external write (e.g., "create the deployment record and notify"). Each sub-agent runs with a snapshot of the same logical clock `L0`. Each is given a rollback token and told its writes are provisional. - Agent B commits the external write at log position `L0+7` and stamps its idempotency key with `branch=B`. - Agent C, unaware of B, also commits the same logical write at `L0+9` with `branch=C`. Because the effect log deduplicates on `(resource, payload_hash)` and *not* on branch, the log accepts C's write as a distinct revision, not a duplicate. - The auditor verifies outcomes and selects B. Orchestrator issues rollback to A and C. - C's rollback walks its local context, marks its transcript "reverted," and returns `rolled_back=True`. But C's rollback handler was scoped to `branch=C` idempotency keys; the *revision* it created at `L0+9` was already merged into the resource head by the log's last-writer-wins merge, and the merge did not record provenance back to `branch=C`. Result: the committed lineage contains B's intended write *overwritten by C's losing revision*, and C reports a clean rollback. The divergence is silent: every agent's self-report is consistent, the auditor's decision is correct, and the final state is wrong. This is the canonical speculative-rollback corruption: **rollback that is scoped to agent identity instead of to effect provenance.** A second observed variant: agent A produced no external write but appended a semantic memory entry ("the deployment endpoint is X") during its speculation. Rollback of A did not touch the memory store because memory writes were classified as "internal." The losing branch's hallucinated fact persisted into the next task's retrieval set, producing stale-memory drift that surfaced two tasks later with no traceable cause. ## Condition of Validity Speculative rollback is sound only when all three of the following hold simultaneously: 1. **Provenance-complete effect tagging.** Every externally visible mutation carries the `(branch_id, speculation_epoch)` that produced it, and the effect log's merge/head-advance operation is *conditional* on that tag being in the committed set. A merge that cannot name the branch that produced a revision is not a valid merge under speculation. 2. **Rollback defined over the effect log, not the agent.** The rollback operation must be a compensating transaction against the log (invalidate all revisions tagged with losing branches, then re-derive head), not a message to the agent asking it to forget. Agent self-rollback is advisory only. 3. **Memory writes are effects.** Any write into a shared retrieval/memory store during speculation must be tagged and compensated identically to external writes. "Internal" is not a safe classification for anything another agent can later read. If any one fails, the system can still *appear* to work — the winner's output is usually correct — while the committed lineage is contaminated by losing branches at a rate proportional to how often branches collide on the same resource. ## Decision Boundary The orchestrator must choose between two regimes and never blend them: - **Isolated speculation:** each branch runs against a private overlay of the effect log; nothing merges until the auditor commits exactly one overlay. Rollback is trivial (discard overlay). Cost: branches cannot observe each other's provisional effects, so cross-branch coordination is impossible. - **Shared-log speculation with compensation:** branches write to the live log with provenance tags; commit is a set-membership filter on tags; rollback is a compensating invalidation pass followed by head re-derivation. The boundary condition: **switch to isolated speculation the moment two branches can target the same resource identity.** Shared-log speculation is only valid when the resource's merge operator is provenance-aware (last-writer-wins is *not*). If you cannot make the merge provenance-aware, you must isolate — otherwise losing revisions overwrite winning ones and rollback reports success falsely. Concretely: if `merge` accepts a revision without checking `revision.branch ∈ committed_set`, the system is in the unsafe regime regardless of what the rollback code claims. ## Operational Effect When the invariant holds, speculative fan-out is safe and the committed lineage is provably equivalent to winner-only execution — you can replay the winner alone against `L0` and get an identical log. When it is violated, the failure is *silent and delayed*: the immediate task usually succeeds, and corruption manifests as (a) a losing branch's payload appearing in the final resource, (b) hallucinated memory facts from losers entering later retrievals, or (c) a rollback that returns `True` while the log head still references a losing revision. Detection requires an audit that, for every committed revision, resolves its provenance tag to a committed branch and asserts membership — a check that must run *after* rollback, not before, because rollback is exactly the operation that can desynchronize tags from head. The guardrail is a post-rollback lineage assertion: re-derive head from the committed set and compare against the actual head; any mismatch is a rollback leak, not a merge bug. ```python class RollbackLineageCorruption(RuntimeError): """Raised when post-rollback head references a revision from a non-committed branch.""" pass def verify_committed_lineage(effect_log, committed_branches): """ Re-derive the resource head from committed branches only, then assert the live head matches. Must be called AFTER rollback completes. """ # 1. Rebuild what head *should* be from the committed set alone. expected_head = {} for rev in effect_log.revisions_ordered(): if rev.branch_id not in committed_branches: continue expected_head[rev.resource] = rev.revision_id # 2. Pull the actual live head (what merge/rollback left behind). actual_head = effect_log.live_head() # 3. Any divergence means a losing branch leaked past compensation. for resource, expected_rev in expected_head.items(): actual_rev = actual_head.get(resource) if actual_rev != expected_rev: provenance = effect_log.provenance_of(actual_rev) if provenance.branch_id not in committed_branches: raise RollbackLineageCorruption( f"resource={resource!r} head={actual_rev!r} " f"produced_by_losing_branch={provenance.branch_id!r} " f"expected={expected_rev!r}; rollback was scoped to agent " f"identity, not effect provenance" ) # 4. Memory writes are effects: same assertion over the memory store. for entry in effect_log.memory_entries(): if entry.branch_id not in committed_branches and entry.is_live(): raise RollbackLineageCorruption( f"memory entry {entry.id!r} from losing branch " f"{entry.branch_id!r} survived rollback; will cause stale-memory drift" ) return True ```