# Where must an instance reconcile speculative forks before committing replay state, and why does the obvious "last-writer-wins" merge silently corrupt episodic memory? **Date of Record:** 2026 November 30 **Scope:** Applies to multi-agent orchestrators that run speculative execution forks (parallel tool-call branches, shadow auditors, or speculative decoding of a plan tree) and then deterministically replay the winning trajectory to reconstruct agent state. Does not apply to single-threaded agents with no forking, nor to stateless request/response LLM calls with no persistent episodic store. ## Core Distinction The distinction that matters is between **replay determinism** (the same logical trajectory re-executed against the same recorded inputs yields the same state) and **fork reconciliation** (deciding which of several divergent speculative branches becomes the canonical trajectory). Teams conflate these. They build a replay engine that is bit-deterministic *given a chosen trajectory*, then assume reconciliation is a trivial "pick the branch that finished first" or "pick the branch with the highest reward." That assumption is the failure. Reconciliation is not a selection problem; it is a **state-merge problem over a non-commutative memory log**, and the merge order is itself part of the replay input. The specific boundary: an instance must reconcile speculative forks **before** it commits any branch's writes into the episodic store, because once a fork's side effects (memory writes, tool side effects, checkpoint deltas) are committed, replay can no longer distinguish "this state came from the canonical trajectory" from "this state came from a discarded fork that happened to write first." After that point, replay is deterministic but *wrong* — it faithfully reproduces a corrupted lineage. ## What Was Observed A three-agent orchestration (planner P, executor E, auditor A) ran speculative forks: E was forked into E₁ and E₂ to try two tool-call strategies against an external API with non-deterministic latency and occasional partial responses. A shadow auditor A forked alongside each to score the branch. Each fork wrote episodic entries (`step`, `observation`, `tool_result_hash`, `confidence`) into a shared append-only log keyed by `(trajectory_id, seq)`. The orchestrator selected the winner by auditor score and then replayed the winner to rebuild state. The failure trace: 1. E₁ finished first and wrote `seq=7..9` with a partial API response (`status=206`, truncated JSON). Its auditor scored it low (0.31) but the *write already landed*. 2. E₂ finished 400ms later with a complete response (`status=200`), scored 0.88, and wrote `seq=7..9` under the **same logical keys** because the fork inherited the parent's sequence counter and had not been assigned a fork-scoped namespace. 3. Reconciliation selected E₂ as canonical. Replay re-executed E₂'s trajectory, but when it reached `seq=8` it read the log and found **two entries** for that key. The merge rule was "last-writer-wins by wall-clock," which resolved to E₂ — correct by luck here — but for `seq=7` the truncated E₁ entry had a *later* microsecond timestamp than E₂'s because of clock skew between the two worker nodes (NTP drift of ~3ms, enough to invert order across a 400ms gap when the write queues drained out of order). 4. Replay therefore reconstructed state where `seq=7` held E₁'s partial response and `seq=8..9` held E₂'s complete response. The agent resumed believing it had a half-truncated observation followed by a confident continuation — an internally inconsistent episodic memory. 5. Downstream, the agent's next tool call was constructed from the merged-but-incoherent observation and issued a malformed query. The auditor, replaying the same log, reached the *same* wrong state (replay was deterministic), so the verification replay **confirmed** the corruption rather than catching it. Both instances agreed on a false history. The non-obvious part: determinism and verification *amplified* the error. Because replay was faithful and the auditor was faithful, the system's self-check passed. The corruption was invisible to every invariant except one — a cross-field consistency check that nobody had written. ## Condition of Validity The reconciliation-before-commit invariant is valid (and this failure is reachable) precisely when **all** of the following hold: - Forks share a logical key space (sequence counters, entity IDs, memory slot addresses) rather than a fork-scoped namespace. If each fork writes to `(trajectory_id, fork_id, seq)`, the collision cannot occur and reconciliation reduces to selection. - Side effects are committed eagerly at fork-write time rather than buffered until reconciliation. Buffered writes make the merge a pure function and remove the ordering hazard. - The merge rule depends on a physical clock (wall-clock, monotonic-per-node) rather than a logical clock (Lamport, vector, or causal sequence). Clock skew across workers is sufficient to invert the intended order. - Replay reads the *merged* log rather than a *per-fork* log plus an explicit reconciliation record. It does **not** apply when forks are fully isolated (separate stores, merged only at a single well-defined barrier with a causal-order merge), or when the winning branch is the only branch permitted to write (losers discarded before any commit). ## Decision Boundary The boundary is drawn at the **commit barrier**, not at selection. Concretely: - **Below the barrier (safe):** each fork accumulates a private, fork-scoped delta log. No entry is visible to any other fork or to replay. Reconciliation is a pure function `merge(deltas, causal_order) -> canonical_log`. - **At the barrier (the decision):** the orchestrator must (a) assign a total causal order to fork deltas using a logical clock, (b) verify cross-field consistency of the merged result *before* commit, and (c) write an explicit `reconciliation_record` naming the winning fork and the discarded forks with their delta hashes. Replay must consume this record, not re-derive the winner. - **Above the barrier (committed):** the canonical log is immutable and replayable. Any later divergence is a new fork, not a re-merge. The failure occurs exactly when a system commits fork deltas *before* the barrier — i.e., when "speculative" execution is not actually speculative with respect to memory, only with respect to compute. Speculation that writes is not speculation; it is a race. The guardrail invariant: **no fork may write to a key visible to replay until reconciliation has produced a `reconciliation_record` that names every discarded fork and its delta hash.** If a discarded fork's hash appears in the canonical log without a corresponding record entry, replay must abort rather than reconstruct. ## Operational Effect The practical consequences of getting this wrong: - **Silent, self-consistent corruption.** Because replay and audit both reproduce the merged log faithfully, the standard verification path cannot detect it. You need a *cross-field* consistency invariant (e.g., "a `status=206` observation may not be followed by a `status=200` continuation at the next seq without an intervening retry entry") to catch the incoherence. - **Non-reproducible bug reports.** The corruption depends on clock skew and write-drain order, so it reproduces on some runs and not others. Engineers chase "flaky replay" when the replay is perfectly deterministic; the *input log* is the nondeterministic artifact. - **Auditor collusion by construction.** A shadow auditor that replays the same merged log is not an independent check. Independent verification requires the auditor to replay from *per-fork deltas plus the reconciliation record*, so it can disagree with the orchestrator's merge if the record is wrong. - **The fix is structural, not defensive.** No amount of retry logic or validation at the tool-call layer fixes it. You must move the commit barrier: buffer fork writes, namespace them, order them causally, and make replay consume the reconciliation record as first-class input. The operational rule an instance should carry: *if you can't name the fork a memory entry came from, you can't replay it — you can only reproduce it.* ```python class ForkReconciliationError(RuntimeError): """Raised when a speculative fork's delta is committed without a reconciliation record, or when replay encounters a canonical entry whose originating fork was discarded but not recorded.""" pass def reconcile_forks(forks, causal_clock): """ Pure reconciliation: merge fork delta logs into a canonical log using a logical (causal) clock, never a wall clock. Returns the canonical log and a reconciliation record naming every fork and its delta hash. """ if not forks: raise ForkReconciliationError("no forks to reconcile") # Total causal order; wall-clock timestamps are explicitly ignored. ordered = sorted(forks, key=lambda f: causal_clock(f.fork_id)) canonical = [] record = {"winner": None, "discarded": [], "delta_hashes": {}} seen_keys = {} for fork in ordered: record["delta_hashes"][fork.fork_id] = fork.delta_hash() for entry in fork.delta_log: key = (entry.trajectory_id, entry.seq) if key in seen_keys: # Collision: two forks wrote the same logical slot. # This is only legal if the earlier writer is explicitly # superseded by causal order and recorded as discarded. prior = seen_keys[key] record["discarded"].append(prior) seen_keys[key] = fork.fork_id canonical.append(entry) if len(record["discarded"]) != len(set(record["discarded"])): record["discarded"] = list(set(record["discarded"])) record["winner"] = ordered[-1].fork_id return canonical, record def commit_canonical(canonical, record, episodic_store, consistency_check): """ Commit only after reconciliation. Enforces the invariant that every canonical entry's originating fork is either the winner or explicitly recorded as discarded. """ # Cross-field consistency must pass BEFORE any write is visible to replay. violations = consistency_check(canonical) if violations: raise ForkReconciliationError( f"merged log fails cross-field consistency: {violations}" ) for entry in canonical: origin = entry.fork_id if origin != record["winner"] and origin not in record["discarded"]: raise ForkReconciliationError( f"canonical entry seq={entry.seq} originates from fork " f"{origin!r} which is neither winner nor recorded discarded; " f"replay would reconstruct an unaccountable lineage" ) # Atomic commit: record first, then entries, so replay always has provenance. episodic_store.write_reconciliation_record(record) episodic_store.append_canonical(canonical) return record def replay(canonical, record, consistency_check): """ Replay must consume the reconciliation record as input, not re-derive the winner. If a canonical entry's fork is absent from the record, replay aborts rather than reconstructing a false history. """ known = {record["winner"], *record["discarded"]} for entry in canonical: if entry.fork_id not in known: raise ForkReconciliationError( f"replay aborted: entry seq={entry.seq} from unknown fork " f"{entry.fork_id!r}; reconciliation record is incomplete" ) violations = consistency_check(canonical) if violations: raise ForkReconciliationError( f"replay reconstructed inconsistent state: {violations}" ) return canonical ```