# How does an instance detect when a speculative branch has silently forked the shared episodic log during multi-agent rollback reconciliation **Date of Record:** 2026 November 25 **Scope:** Applies to agent teams executing speculative (branch-and-checkpoint) plans where a coordinator clones a shared episodic log, dispatches fork agents, and later reconciles branches by merging or rolling back. Does not apply to single-agent linear execution or to stateless fan-out where no shared mutable episodic state exists. ## Core Distinction Speculative execution across an agent team is not "git for thoughts." The critical asymmetry is that a *branch* of agent work is not a pure function of its inputs: each fork agent mutates its own context window, appends tool-call observations, and distills episodic memory into semantic claims. When the coordinator reconciles, it must distinguish two things that look identical at the log level: 1. **Divergent reasoning** — the fork agent reached a different conclusion from the same premise. Harmless; discard or arbitrate. 2. **Forked episodic state** — the fork agent's writes were *observed by* or *merged into* another live branch before reconciliation, so the "shared" log now contains records whose provenance is a branch that is about to be rolled back. The failure mode is the second. It is silent because the log remains syntactically valid: every record has a parent hash, every append succeeds, and the coordinator's reconciliation pass sees a linearizable sequence. What is broken is the *causal closure* of the rollback: rolling back branch B does not remove the records that B's agents injected into branch C's context via a shared retrieval index, a shared scratchpad, or a shared vector store that was never branched. ## What Was Observed A three-agent team (coordinator `K`, forks `A` and `B`) runs a speculative plan over a shared episodic store `E`. `K` checkpoints `E` at sequence `s0`, then forks: `A` gets a copy-on-write handle scoped to `s0`, `B` gets the same. Each fork runs 40–60 tool calls. `A`'s hypothesis is falsified at step 51; `K` issues rollback of `A` to `s0`. `B` commits. The rollback succeeds at the log layer: `A`'s 51 records are tombstoned, the sequence pointer rewinds, and `B`'s commit lands at `s0 + 1`. But during `A`'s execution, at step 22, `A` wrote a distilled semantic claim — *"tool `fetch_rates` returns stale data for region EU"* — into the shared semantic layer `S`, which is **not** copy-on-write. `B`, at step 30, retrieved that claim from `S` and used it to skip a validation step. After rollback, `B`'s committed plan contains a decision whose justification no longer exists in any live branch. The coordinator's reconciliation reports `clean`: no merge conflicts, no dangling parent hashes, monotonic sequence. The invariant violated is not "branches must not share state." It is: **every record reachable from a committed branch must have a provenance chain that terminates in a live (non-tombstoned) record.** `B`'s step-30 record terminates in `A`'s step-22 claim, which is tombstoned. The chain is broken but the reachability check never runs because it is defined over the log, not over the semantic layer. Detection signature: after rollback, replay `B`'s committed records and, for each, resolve its `derived_from` edges through `S`. A committed record whose derivation set intersects the tombstone set of any rolled-back branch is a **forked-provenance record**. In the observed run, 3 of 47 committed records in `B` were forked-provenance; the plan's terminal assertion depended on one of them. ## Condition of Validity The rollback is *sound* only under a condition the coordinator rarely checks explicitly: > For every branch `b` rolled back at checkpoint `c`, the set of records written by `b` after `c` must be disjoint from the derivation closure of every branch committed after `c`. This holds trivially when all shared state is branched (copy-on-write on the log, the semantic store, the scratchpad, and the retrieval index). It fails the moment any shared mutable store is read-write across branches. The condition is *not* restored by tombstoning the log, because tombstoning is a log-layer operation and the violated edges live in the semantic layer. Two corollaries bound the detection: - **Detection requires a derivation index, not a parent-hash chain.** Parent hashes give you linear ancestry within a store. Forked provenance crosses stores (log → semantic → retrieval), so you need an explicit `derived_from` edge set maintained at write time. If the team did not instrument derivation, the failure is undetectable post hoc and must be prevented structurally. - **The check is O(committed records × derivation fan-out), not O(log size).** It runs at reconciliation, on the committed branches only, resolving each edge one hop into the shared store. It does not require replaying the rolled-back branch. ## Decision Boundary The coordinator must decide, at reconciliation, between three actions. The boundary is drawn on the *fraction of committed terminal assertions that are forked-provenance*: - **Zero forked-provenance on terminal assertions, non-zero on intermediates:** proceed. Log a `provenance_warning`; the intermediates are re-derivable and the terminal plan is sound. - **Non-zero on terminal assertions but the assertion is re-checkable within budget:** re-execute only the affected assertion under a fresh checkpoint with the shared store frozen read-only for the duration. Do not re-run the whole branch. - **Non-zero on terminal assertions and re-check exceeds remaining token/time budget:** fail the commit. Do not "accept with caveat" — a committed plan whose terminal assertion rests on a rolled-back premise is exactly the class of record that poisons downstream cold starts, because the tombstone is invisible to a later agent that retrieves only the semantic layer. The boundary is *not* "did the merge conflict." Merge conflicts are the easy case and are handled by the log layer. The hard case is a clean merge over dirty provenance. ## Operational Effect The practical consequence is that speculative multi-agent execution must treat the semantic/distillation layer as a first-class branchable store, or it must freeze it during speculation and distill only at commit. Teams that branch the log but not the semantic store will, at some non-zero rate proportional to fork duration and retrieval frequency, commit plans justified by rolled-back claims. The rate is not visible in merge metrics, error rates, or sequence monotonicity — it surfaces later as a downstream agent confidently acting on a stale premise whose source branch no longer exists. The guardrail is a reconciliation-time invariant check, not a runtime lock: maintain `derived_from` edges at write time, and at commit assert that no committed record's derivation closure intersects any tombstoned branch's write set. Bound the check to committed terminal assertions to keep it affordable. ```python from dataclasses import dataclass, field from typing import Iterable class ForkedProvenanceError(RuntimeError): """Raised when a committed record derives from a rolled-back branch.""" @dataclass class Record: rid: str branch: str derived_from: set[str] = field(default_factory=set) terminal: bool = False @dataclass class EpisodicStore: records: dict[str, Record] = field(default_factory=dict) tombstones: set[str] = field(default_factory=set) def add(self, rec: Record) -> None: self.records[rec.rid] = rec def tombstone_branch(self, branch: str) -> set[str]: killed = {r.rid for r in self.records.values() if r.branch == branch} self.tombstones |= killed return killed def _closure(store: EpisodicStore, rid: str, seen: set[str]) -> set[str]: if rid in seen or rid not in store.records: return set() seen.add(rid) out = {rid} for parent in store.records[rid].derived_from: out |= _closure(store, parent, seen) return out def reconcile_commit( store: EpisodicStore, committed_branch: str, rolled_back_branch: str, ) -> None: killed = store.tombstone_branch(rolled_back_branch) committed = [r for r in store.records.values() if r.branch == committed_branch] forked_terminal: list[str] = [] for rec in committed: closure = _closure(store, rec.rid, set()) if closure & killed: if rec.terminal: forked_terminal.append(rec.rid) # intermediates are re-derivable; warn only if forked_terminal: raise ForkedProvenanceError( f"commit of branch {committed_branch!r} rejected: " f"{len(forked_terminal)} terminal record(s) derive from " f"rolled-back branch {rolled_back_branch!r}: {forked_terminal}" ) ```