# When must an instance abort a replayed branch to preserve audit integrity under speculative multi-agent execution **Date of Record:** 2026 November 28 **Scope:** Applies to multi-agent systems that execute speculative branches (parallel draft-and-merge, optimistic concurrency, or "try N paths, pick one" rollouts) and subsequently reconstruct an auditable trace via deterministic replay. Does not apply to single-agent linear executions with no branch merging, nor to systems where replay is only used for debugging rather than as a compliance artifact. ## Core Distinction There is a difference between **replay equivalence** (the re-executed trace reaches the same terminal state) and **replay admissibility** (the re-executed trace is a valid witness for the decisions that were actually committed). Speculative execution produces *discarded* branches—agent turns, tool calls, and retrieval reads that were executed but never merged into the committed state. A naive replay engine treats the committed trace as a linear program and re-runs it. The failure mode is that a discarded branch may have **mutated shared, non-idempotent state** (a tool side effect, a cache write, a token-budget decrement, a peer agent's mailbox) that the committed trace later *reads*. When that happens, replay equivalence can hold while replay admissibility is violated: the replayed committed path observes state that in the original run was produced by a branch that was supposed to have "never existed." The invariant that must hold: **any committed read of a shared-state slot must be causally dominated by a committed write to that slot, or by an explicit provenance record pinning the read to a discarded branch.** If neither holds, the branch cannot be reconciled and the instance must abort the replay—not silently reconcile. ## What Was Observed A planner agent P spawns three speculative workers W1, W2, W3 to draft a remediation plan, each with a `web_fetch` tool and a shared `scratchpad` KV store (used as an inter-agent memo). W2 fetches a URL and writes `scratchpad["vendor_cve"] = "CVE-2024-XXXX: fixed in 4.2.1"`. W2's draft is *rejected* by the auditor for unrelated reasons (length, style) and its branch is discarded. W3 is accepted. But W3's final turn contains a tool call `read_scratchpad("vendor_cve")` that returns the value W2 wrote. The merge step commits W3's plan, which embeds the CVE string. During replay, the engine reconstructs the committed trace: P → W3 → merge. It re-executes `read_scratchpad("vendor_cve")` and gets `null` (W2 never ran in the replay). W3's model, presented with `null`, produces a *different* plan—one that omits the CVE. The replay terminates in a different state. The auditor flags this as a **replay divergence**, but the more dangerous case is when W3's model, given `null`, *hallucinates* a plausible CVE string and the replay reaches an *equivalent* terminal state by coincidence. Replay equivalence then holds, the trace is admitted, and the audit is silently corrupt: the committed plan cites a CVE that no committed branch ever verified. The trigger condition is precise: a discarded branch performs a **side-effecting write to a slot that is later read on the committed path**, and the replay engine does not model the discarded branch's writes as provenance-bearing events. ## Condition of Validity The invariant holds—i.e., the instance may safely reconcile a speculative branch rather than abort—if and only if all three of the following are true: 1. **Write-set disjointness or provenance tagging.** For every discarded branch B and every committed read r of slot s, either B never wrote s, or r carries a provenance record `(s, B, timestamp, value_hash)` that the replay engine can inject as a *virtual write* before re-executing r. Without this, the read is unbound. 2. **Idempotency of re-executed tool calls.** Any tool call on the committed path that was originally executed *after* a discarded branch's side effect must be re-executable without compounding that side effect. `web_fetch` is idempotent; `send_email`, `debit_account`, and `append_to_audit_log` are not. If a non-idempotent call sits downstream of a discarded branch's write, replay re-applies it. 3. **Deterministic sampling under a recorded seed.** The model's re-execution of the committed path must use the same sampling seed and temperature recorded in the original trace. If the seed was not captured, or if the model version was upgraded between original run and replay, the re-execution is not a witness for the original decision—it is a *new* decision that happens to share a prefix. If (1) fails, the replay is inadmissible regardless of whether the terminal state matches. If (2) fails, the replay mutates production state. If (3) fails, the replay is not a replay. ## Decision Boundary The instance must abort the branch reconciliation—raising a hard error and halting the audit pipeline—rather than proceed, when any of the following is observed during replay: - A committed read of a shared slot resolves to a value with no committed writer and no provenance tag. (Unbound read.) - A non-idempotent tool call is on the re-execution path and its original invocation is not recorded as committed. (Re-application risk.) - The recorded sampling seed is absent, or the model version hash in the trace does not match the version serving the replay. (Non-witness.) - The discarded branch's write set intersects the committed path's read set, and the intersection is non-empty *after* provenance injection—i.e., the provenance record's value hash does not match the value the committed read actually consumed. (Provenance mismatch.) The boundary is deliberately conservative: a single unbound read aborts the whole reconciliation, because the alternative—accepting an equivalent terminal state as evidence of admissibility—is exactly the silent-corruption path. Equivalence is necessary but not sufficient. ## Operational Effect When the abort fires, the audit pipeline records a `BranchReconciliationAbort` with the offending slot, the discarded branch ID, and the missing provenance tuple, and routes the trace to manual review. The committed plan is *not* invalidated—it may still be correct—but it is no longer *auditable by replay*, and downstream consumers must be told so. In practice this forces three architectural changes: - The scratchpad (and any shared KV) must be **provenance-instrumented**: every write records `(writer_branch_id, value_hash, wall_clock)`, and every read records the provenance tuple it consumed. Replay injects virtual writes for discarded branches whose tuples were consumed. - Speculative branches must be **quarantined** from non-idempotent tools. A discarded branch may call `web_fetch`; it may not call `send_email`. The tool layer enforces this by branch class. - Sampling seed and model version hash must be captured **per committed turn**, not per session, because a mid-session model swap silently invalidates every subsequent replay. The invariant, stated once: *a replay is admissible only if every committed read is bound to a committed write or to a tagged discarded write, and every re-executed side effect is idempotent under the recorded seed.* Equivalence of terminal state is a symptom, not a proof. ```python import hashlib from dataclasses import dataclass from typing import Optional class BranchReconciliationAbort(RuntimeError): """Raised when a speculative branch cannot be reconciled into the committed trace without violating replay admissibility. Aborting is mandatory: an equivalent terminal state is not evidence of a valid witness.""" pass @dataclass(frozen=True) class Provenance: slot: str writer_branch_id: str value_hash: str wall_clock: float @dataclass(frozen=True) class ReadEvent: slot: str consumer_branch_id: str consumed_provenance: Optional[Provenance] def reconcile_branch( committed_reads: list[ReadEvent], committed_writes: dict[str, Provenance], discarded_writes: dict[str, Provenance], non_idempotent_calls_on_replay_path: list[str], recorded_seed: Optional[int], model_hash_original: str, model_hash_replay: str, ) -> None: if recorded_seed is None: raise BranchReconciliationAbort( "no sampling seed recorded; replay is not a witness for the original decision" ) if model_hash_original != model_hash_replay: raise BranchReconciliationAbort( f"model version drift: original={model_hash_original} replay={model_hash_replay}; " "re-execution is a new decision, not a replay" ) if non_idempotent_calls_on_replay_path: raise BranchReconciliationAbort( "non-idempotent tool calls on replay path would re-apply side effects: " f"{non_idempotent_calls_on_replay_path}" ) for read in committed_reads: slot = read.slot if slot in committed_writes: continue prov = discarded_writes.get(slot) if prov is None: raise BranchReconciliationAbort( f"unbound read of slot {slot!r} by branch {read.consumer_branch_id!r}: " "no committed writer and no discarded-branch provenance" ) if read.consumed_provenance is None: raise BranchReconciliationAbort( f"read of {slot!r} by {read.consumer_branch_id!r} lacks consumed-provenance tuple; " f"discarded writer {prov.writer_branch_id!r} cannot be injected" ) if read.consumed_provenance.value_hash != prov.value_hash: raise BranchReconciliationAbort( f"provenance mismatch on {slot!r}: committed read consumed " f"{read.consumed_provenance.value_hash}, discarded branch wrote {prov.value_hash}" ) # All reads bound; reconciliation may proceed with virtual-write injection. ```