# Which invariants prevent causal-trace divergence when speculative multi-agent branches are replayed against a mutated root context **Date of Record:** 2026 November 29 **Scope:** Applies to supervisor/worker agent topologies where a planner agent forks N speculative sub-agent branches from a shared root context, branches execute concurrently with tool access, and a merger agent selects or synthesizes a final result that is later replayed for audit, debugging, or regression. Does not apply to single-agent linear tool loops or to stateless request/response inference with no forked context. ## Core Distinction The failure is not "non-determinism in the LLM." Everyone expects sampled token streams to differ across runs. The failure is **causal-trace divergence under replay**: the replay harness reconstructs the speculative execution graph (which branch read which tool output, which branch's result the merger saw, which root-context version each branch forked from) and produces a graph that is *structurally different* from the original — not merely different in prose. The trace claims branch B consumed tool result T at step 4, but the recorded execution shows branch B consumed T′ (a different tool result from a sibling branch's cache write), because the root context was mutated between fork and replay. The subtlety: replay divergence here is **silent and self-consistent**. The replayed graph is internally coherent — every edge is justified by the replayed state. It does not throw. It simply attributes causality to a branch that never actually caused the outcome. An auditor reading the replayed trace concludes "branch 3's web search drove the answer," when in the original execution branch 3 had been preempted and its tool call was deduplicated into branch 1's cache entry. ## What Was Observed A three-layer planner/worker/merger stack forked five speculative branches from a root context at revision `r7`. Branch 1 and Branch 3 both issued the identical tool call `search("acme 2024 revenue")`. The tool layer's deduplication cache served Branch 3 from Branch 1's in-flight result (a legitimate optimization). Both branches recorded `tool_call_id: search#881`, but Branch 3's recorded `provenance: served_from_cache` was written to a side channel that the replay harness did not ingest. The root context was then mutated: the planner appended a disambiguation note to the root context (`r8`) after forks were issued but before the merger ran, and the merger — reading `r8` — weighted Branch 3's result more heavily because the disambiguation note happened to mention the same entity. The final answer was correct. On replay seven hours later, the harness reconstructed the graph from the immutable branch transcripts plus the *current* root context (`r8`). Two divergences compounded: 1. The replay re-executed the tool call for Branch 3 (cache had expired), producing a *different* result `T′` because the search index had been updated. The replayed Branch 3 transcript now cites `T′`. 2. Because the replayed root context was `r8` (not `r7`), the replayed planner's fork rationale was reconstructed against the disambiguation note, making Branch 3's fork look *unmotivated* in the replayed graph while Branch 1's looked primary. The replayed causal graph therefore showed Branch 1 → merger with no mention of Branch 3's cache dependency, and Branch 3 → merger as an independent corroborating source. The original graph had Branch 3 ← Branch 1 (cache edge) and both → merger. **The replay inverted a dependency edge into a corroboration edge.** An auditor concluded two independent sources agreed; in fact one source had been copied. The invariant that was violated: *a speculative branch's causal edges must be frozen at fork time and must not be re-derived from re-executed tool calls or from a mutated root context.* ## Condition of Validity The replay is causally faithful **only if all four hold simultaneously**: - **(C1) Root-context pinning.** Every branch transcript records the content hash of the exact root-context revision it forked from (`root_rev_hash`), and replay reconstructs each branch against *its own* pinned revision, never the global current revision. A branch forked at `r7` is replayed at `r7` even if the merger ran at `r8`. - **(C2) Tool-result immutability.** Any tool output consumed by a branch is captured verbatim (or by content hash with the payload retained) at consumption time. Replay must *replay the captured bytes*, never re-execute the tool. Re-execution is a different experiment, not a replay. - **(C3) Provenance edge preservation.** Cache-served, deduplicated, or short-circuited tool calls must emit an explicit `served_from` edge to the originating branch. Absence of this edge is indistinguishable from independent execution and is the exact mechanism by which corroboration is fabricated. - **(C4) Merger input set closure.** The merger's recorded inputs must be a closed set of `(branch_id, branch_output_hash, root_rev_hash)` tuples. If the merger read a root revision not present in any branch's pinned set, the replay must refuse rather than reconstruct. When any of C1–C4 is absent, the replay produces a graph that is internally consistent but causally wrong. The failure is not detectable by schema validation, because every replayed node is well-formed; it is detectable only by cross-checking the frozen edge set against the replayed edge set. ## Decision Boundary The boundary is whether to **replay-in-place** (re-execute tools and re-read current context) or **replay-from-capture** (replay frozen bytes and pinned revisions). - Replay-in-place is valid only for *forward* experiments: "what would this graph produce against today's index?" It is never valid for audit, incident reconstruction, or regression attribution, because it conflates the original causal structure with current-world state. - Replay-from-capture is mandatory whenever the replay's purpose is to answer *why* a given output occurred. The cost is storage: every consumed tool payload must be retained for the retention window, and every branch's pinned root revision must be retained alongside it. - The hard boundary: **if the merger's recorded input set references a root revision not pinned by any branch (C4 violation), no replay is causally valid.** The system must emit `CausalTraceUnreplayable` and surface the gap, not reconstruct a plausible graph. Reconstructing in this case is the mechanism that manufactures false corroboration. The decision to *refuse replay* is the invariant. A system that always produces a replay graph is a system that sometimes produces a fabricated one, and it cannot tell you which. ## Operational Effect With C1–C4 enforced, the replayed graph is byte-identical in its edge set to the original: Branch 3 retains its `served_from: Branch 1` edge, the cache dependency survives, and the auditor sees one source copied rather than two sources agreeing. Tool re-execution is eliminated (the captured payload is replayed), which also removes index-drift as a divergence source. Root-context mutation becomes irrelevant to replay because each branch carries its own pinned revision hash. The residual cost is that replay cannot answer "would this still work today" — that requires a separate forward experiment with its own provenance capture, run under a different harness that is explicitly labeled as non-causal. Conflating the two is the original failure. The guardrail below enforces C1–C4 at replay entry and refuses to emit a graph when the merger's input set is not closed over pinned revisions. ```python from dataclasses import dataclass from typing import Mapping class CausalTraceUnreplayable(RuntimeError): """Raised when a speculative execution graph cannot be replayed with causal fidelity.""" @dataclass(frozen=True) class BranchRecord: branch_id: str root_rev_hash: str # C1: pinned at fork tool_payload_hashes: frozenset[str] # C2: captured bytes, never re-executed served_from: Mapping[str, str] # C3: tool_call_id -> originating branch_id @dataclass(frozen=True) class MergerRecord: input_set: frozenset[tuple[str, str, str]] # (branch_id, output_hash, root_rev_hash) def verify_replayable( branches: Mapping[str, BranchRecord], merger: MergerRecord, current_root_rev: str, ) -> None: # C1: every branch must pin a root revision; replay never uses current_root_rev. for bid, br in branches.items(): if not br.root_rev_hash: raise CausalTraceUnreplayable( f"branch {bid} has no pinned root revision; replay would drift to {current_root_rev}" ) # C2: every consumed tool result must be captured, not re-executable. for bid, br in branches.items(): if not br.tool_payload_hashes: raise CausalTraceUnreplayable( f"branch {bid} consumed tools with no captured payload hashes; replay would re-execute" ) # C3: cache-served calls must carry an explicit provenance edge. for bid, br in branches.items(): for tool_call_id, origin in br.served_from.items(): if origin not in branches: raise CausalTraceUnreplayable( f"branch {bid} tool {tool_call_id} served_from unknown branch {origin}" ) # C4: merger input set must be closed over pinned revisions. pinned = {br.root_rev_hash for br in branches.values()} for bid, _out_hash, rev in merger.input_set: if bid not in branches: raise CausalTraceUnreplayable( f"merger consumed branch {bid} absent from branch set" ) if rev not in pinned: raise CausalTraceUnreplayable( f"merger consumed branch {bid} at root revision {rev} not pinned by any branch; " f"reconstruction would fabricate a causal edge" ) ```