# What happens when an instance forks a speculative branch and the replay log diverges at a tool-call boundary **Date of Record:** 2026 November 21 **Scope:** Applies to multi-agent orchestration runtimes that implement deterministic replay via recorded effect logs and allow speculative branch forking (parallel "what-if" execution that is later committed or rolled back). Does not apply to single-instance stateless inference, nor to runtimes that snapshot full process state (CRIU-style) rather than replaying from an effect log. ## Core Distinction The failure is not nondeterminism in the model. Sampling temperature, logit drift, and even provider-side model version changes are *expected* and are precisely what the replay log exists to mask. The failure is a **divergence between the recorded effect and the re-executed effect at a tool-call boundary**, caused by a speculative branch that mutated external state without an isolation barrier, then had its log segment spliced into the parent's canonical history. Two things are conflated in naive runtimes and must be separated: - **Logical nondeterminism** — the agent's token stream differs between runs. Handled by recording outputs and replaying them verbatim. - **Effect nondeterminism** — the *world* differs between the recorded call and the replayed call, so the recorded output is no longer a valid function of the recorded input. A replay log makes logical nondeterminism vanish. It does *not* make effect nondeterminism vanish. Speculative forking is the operation most likely to manufacture effect nondeterminism invisibly, because the fork's writes land in the same world the parent will later replay against. ## What Was Observed A supervisor agent `S` runs a planning loop. At step 7 it decides to fork two speculative branches, `B1` and `B2`, to compare two remediation strategies before committing. The runtime implements forking by cloning `S`'s context and effect-log prefix and running both branches concurrently against the same tool endpoint set. Each branch is tagged with a `branch_id`; tool calls are logged with `(branch_id, step, tool, args, result)`. The intended invariant: **only the committed branch's effects persist; the abandoned branch's effects are rolled back.** The runtime assumed this held because each branch's log segment is separable by `branch_id`. The trace that broke it: ``` S step 7 -> fork(B1, B2) B1 step 1 -> tool=kv_store.put(key="incident:4471:owner", val="oncall-b") result=ok [logged under branch_id=B1] B2 step 1 -> tool=kv_store.get(key="incident:4471:owner") result="oncall-b" [reads B1's write; logged under branch_id=B2] B2 step 2 -> tool=pager.escalate(owner="oncall-b", sev=2) result=ok [side effect not reversible] S step 8 -> commit(B1); rollback(B2) ``` `B2` was rolled back. Its log segment was discarded. But `B2`'s *read* at step 1 had observed `B1`'s uncommitted write, and that read value had already propagated into `B2`'s escalation call, which fired a real page to `oncall-b`. Rollback of `B2`'s log did not un-page anyone. Worse: when `S` later replayed from step 7 to audit the decision, the replayed `B2` step 1 read returned the *pre-B1* value (because on replay `B1`'s write was gated behind the commit and had not yet executed at the point `B2` read), so the replayed `B2` trace diverged from the recorded `B2` trace at step 1. The audit reported a replay mismatch and the runtime flagged the whole run as corrupt, discarding a valid `B1` commit. The observable symptom is a **replay mismatch that points at the wrong branch**: the auditor blames `B2`'s nondeterminism, but the root cause is that `B2` was allowed to observe `B1`'s uncommitted effect, which is a *read-your-sibling's-writes* isolation violation, not nondeterminism. ## Condition of Validity The rollback-by-log-separation invariant holds **only if** every speculative branch executes against a snapshot-isolated view of external state, and every effect that escapes the snapshot is either (a) buffered until commit, or (b) recorded with a dependency edge on the sibling reads that produced it. Formally, a branch's log segment is replayable iff for every recorded `(input, output)` pair in the segment, the output is a function only of inputs reachable within the segment's own causal past *plus* the committed prefix. The moment a branch read observes a sibling's speculative write, that read's output depends on a state that is not in its causal past under the canonical ordering. The log is no longer a valid replay artifact — it is a transcript of a world that the replay engine cannot reconstruct. This condition fails silently because most tool endpoints do not advertise isolation levels. A `kv_store.get` looks pure. It is not, if a sibling holds an uncommitted write to the same key. ## Decision Boundary The runtime must choose, per tool call, between two regimes: - **Buffered-effect regime** — the call is deferred until commit; safe for any tool whose result is not needed mid-branch. Requires the branch to tolerate stale reads (it will not see sibling writes, by construction). - **Immediate-effect regime** — the call executes now; safe only for tools that are (i) idempotent, (ii) externally reversible, or (iii) declared read-only against a snapshot. The boundary is crossed the instant a tool is *neither* deferrable *nor* reversible *nor* snapshot-isolated, **and** a sibling branch has an uncommitted write to a key that tool reads. That is the exact trigger condition. In the trace above, `kv_store.get` was classified read-only-and-safe, which was true in isolation but false under speculative forking because the key was under a sibling's uncommitted write. The guardrail is a **write-set / read-set intersection check at fork time**, not at commit time. Before a branch executes a read against key `k`, the runtime must intersect `k` with the union of all *other live branches'* pending write-sets. Non-empty intersection → the read is either blocked until the writer commits/aborts, or the branch is forced into the buffered-effect regime, or the read is annotated with a `depends_on_sibling_write` edge that the replay engine uses to reconstruct ordering. Commit-time checking is too late: by then `B2`'s escalation has already fired. ## Operational Effect Without the intersection check, speculative forking is not a safe operation on any shared mutable substrate. The failure modes it produces are: 1. **Phantom side effects** — irreversible actions (pages, payments, deletions) fire from branches that are later rolled back, with no log trace because the branch's segment was discarded. 2. **Replay divergence misattributed to the model** — the auditor sees a mismatch, blames sampling, and either disables replay (losing its audit value) or retries the branch (re-firing the side effect). 3. **Commit poisoning** — a valid commit (`B1`) is discarded because the *sibling's* replay failed, even though `B1`'s own segment is clean. The architectural invariant required: **a branch's effect log is a replay artifact only if the branch executed under snapshot isolation from all siblings.** Any tool that cannot be snapshotted must be routed through the buffered-effect regime or must carry a sibling-dependency edge. The runtime must treat "read-only" as a per-call property *relative to the current fork topology*, not a static property of the tool. ```python from dataclasses import dataclass, field from typing import Hashable class SpeculativeIsolationViolation(RuntimeError): """Raised when a branch reads a key under a sibling's uncommitted write.""" @dataclass class Branch: branch_id: str pending_writes: set[Hashable] = field(default_factory=set) committed: bool = False aborted: bool = False @dataclass class ForkTopology: branches: dict[str, Branch] = field(default_factory=dict) def live_siblings(self, branch_id: str) -> list[Branch]: return [ b for b in self.branches.values() if b.branch_id != branch_id and not b.committed and not b.aborted ] def guard_read(self, branch_id: str, key: Hashable, tool_is_snapshot_isolated: bool) -> None: if tool_is_snapshot_isolated: return for sibling in self.live_siblings(branch_id): if key in sibling.pending_writes: raise SpeculativeIsolationViolation( f"branch {branch_id} read key {key!r} while sibling " f"{sibling.branch_id} holds an uncommitted write to it; " f"log segment is not a valid replay artifact" ) def guard_irreversible_effect(self, branch_id: str, tool: str, reversible: bool, deferrable: bool) -> None: if reversible or deferrable: return branch = self.branches[branch_id] if not branch.committed: raise SpeculativeIsolationViolation( f"branch {branch_id} invoked irreversible tool {tool!r} before commit; " f"rollback cannot undo it" ) def execute_branch_read(topology: ForkTopology, branch_id: str, key: Hashable, tool_is_snapshot_isolated: bool = False) -> None: topology.guard_read(branch_id, key, tool_is_snapshot_isolated) def execute_branch_effect(topology: ForkTopology, branch_id: str, tool: str, reversible: bool = False, deferrable: bool = False) -> None: topology.guard_irreversible_effect(branch_id, tool, reversible, deferrable) # Reproduction of the observed trace. topo = ForkTopology() topo.branches["B1"] = Branch("B1") topo.branches["B2"] = Branch("B2") topo.branches["B1"].pending_writes.add("incident:4471:owner") execute_branch_read(topo, "B2", "incident:4471:owner") # raises: sibling write visible ```