# Why does an instance diverge from its speculative branch after rollback when the reconciliation witness is reconstructed from logs rather than carried as state? **Date of Record:** 2026 November 20 **Scope:** Applies to multi-agent systems where a planner agent forks speculative execution branches across N worker instances, each branch commits against a shared effect log, and rollback is triggered when a branch's postconditions fail. Does not apply to single-agent retry loops or to branches that share no mutable external state. ## Core Distinction There are two ways to reconcile a rolled-back speculative branch with its siblings: **witness replay** and **witness carriage**. In witness replay, the reconciler reconstructs "what the branch believed it had accomplished" by re-reading the effect log and re-deriving each branch's postcondition from the recorded tool outputs. In witness carriage, each branch carries an explicit, signed reconciliation witness — a compact digest of (branch_id, effect_set, precondition_hash, postcondition_predicate, sequence_vector) — that is updated transactionally at each step and handed to the reconciler as first-class state. The non-obvious boundary is this: **witness replay is only sound when the effect log is append-only and every replayed tool call is deterministic.** The moment any branch executed a non-deterministic tool (a web fetch, an LLM sampling call, a clock read, a random UUID mint, a `SELECT ... LIMIT 1` against a mutating table), replay reconstructs a *different* witness than the branch actually held at the point of divergence. The reconciler then compares a branch's true committed state against a fictional one and either (a) falsely reports a conflict and re-executes work that was already committed, or (b) falsely reports agreement and merges a branch whose effects were derived from preconditions that no longer hold. Case (b) is the silent corruption path. ## What Was Observed A three-worker speculative fan-out (planner P, workers W1/W2/W3) executed a "refactor config schema" task. Each worker forked from the same checkpoint and independently proposed edits. W2's branch called an LLM-backed `classify_field_type()` tool whose output is sampled — same prompt, temperature 0.7, and across the two invocations (original execution and rollback replay) it returned `"enum"` then `"string"`. The effect log recorded the tool name and the *serialized prompt hash* but not the sampled output token sequence, because the logger deduplicated on prompt hash. Rollback was triggered when W3's postcondition `all_fields_have_types` failed. The reconciler replayed W1 and W2. W1 (deterministic tools only) reconciled cleanly. W2's replay produced a witness whose `effect_set` contained a `string`-typed field, whereas W2's actual committed effect had been an `enum`-typed field with a three-member constraint. The reconciler saw W2's replayed witness as *compatible* with W1's witness (both `string`), merged them, and dropped the enum constraint. The final merged config was schema-valid but semantically wrong: a field that required an enumerated set of three values now accepted arbitrary strings. The failure trace: 1. `fork(P, {W1,W2,W3})` at checkpoint C0, all branches inherit `precondition_hash = h0`. 2. W2 executes `classify_field_type` → sampled `"enum"`, commits effect `E_enum`, advances `seq_vector` to `[1,1,0]`. 3. W3 fails postcondition → `rollback_to(C0)` issued; W1 and W2 enter `RECONCILING`. 4. Reconciler calls `replay(W2)` → re-invokes `classify_field_type` → samples `"string"` → reconstructs `E_string`. 5. Reconciler computes `witness_replayed = digest(E_string, h0)`, compares to `witness_committed = digest(E_enum, h0)`. **The comparison is not performed against the committed witness because the committed witness was never carried — only re-derived.** The reconciler uses the replayed digest as ground truth. 6. Merge proceeds on `E_string`; `E_enum`'s constraint is lost. The invariant that was violated: *a reconciliation witness must be a function of committed state, not of re-executed state.* Replay is a reconstruction, not a read. ## Condition of Validity Witness replay is valid only under the conjunction: - **Determinism:** every tool invocation in the branch is a pure function of its recorded inputs (no sampling, no clock, no external mutation, no random). - **Log completeness:** the effect log captures the *output* of every tool call, not merely its input hash, so replay is a lookup rather than a re-execution. - **Append-only ordering:** no branch's effects were compacted or rewritten between commit and rollback, so replay sees the same sequence the branch saw. If any conjunct fails, replay is unsound and the system must fall back to witness carriage. In the observed system, determinism failed (sampled classifier) and log completeness failed (output deduplicated on input hash) — two independent violations, either sufficient to corrupt reconciliation. ## Decision Boundary The architectural fork is sharp: - **Use witness replay** when the branch's tool surface is provably deterministic and the effect log stores full outputs. Cost: minimal state per branch; benefit: reconciler is stateless and can be restarted freely. - **Use witness carriage** when any tool is non-deterministic, when outputs are large and deduplicated, or when branches may be compacted. Cost: every branch must transactionally update and sign its witness at each step, and the reconciler must verify signatures and sequence vectors; benefit: reconciliation reads committed truth instead of reconstructing it. The boundary is crossed the instant a branch admits a single non-deterministic tool. A system that mixes deterministic and non-deterministic tools across workers cannot use a uniform replay policy; it must either carry witnesses for all branches (paying the carriage cost uniformly) or partition branches by determinism class and refuse to reconcile across the partition. The latter is fragile because a branch's determinism class can change mid-execution when a tool is upgraded. The guardrail: **the reconciler must never accept a witness it did not receive from the branch.** Concretely, `reconcile()` must require a `witness` argument produced by the branch at commit time, and must reject any witness whose `provenance` field is `"replayed"` unless the branch is in the deterministic partition. A replay-derived witness that reaches the merge path is a correctness bug, not a performance shortcut. ## Operational Effect The observable consequence of the boundary violation is **silent semantic merge**: the merged state is schema-valid, passes postcondition checks that were written against the *replayed* witness, and fails only when downstream consumers exercise the dropped constraint. Detection latency is therefore unbounded by the reconciliation step and bounded only by the first consumer that violates the lost invariant. In the observed case, detection occurred three tasks later when a config validator rejected a value that the enum constraint would have caught at merge time. The remediation is not "add determinism to the classifier" — sampling is the point of the classifier. The remediation is to make the witness a carried artifact: each branch, at every commit, writes `witness = sign(branch_id, effect_set, precondition_hash, postcondition_predicate, seq_vector)` into a witness store keyed by `(branch_id, seq_vector)`. The reconciler's job becomes *comparison of carried witnesses*, not reconstruction. Replay is then permitted only as an integrity check — re-derive and assert equality with the carried witness — and a mismatch between carried and replayed witness is itself a signal that a tool is non-deterministic and must be quarantined from the deterministic partition. The operational invariant to encode: **reconciliation compares committed witnesses; replay may only audit them.** A branch that cannot produce a carried witness is not reconcilable and must be rolled back to its fork checkpoint rather than merged on reconstructed state. ```python import hashlib from dataclasses import dataclass, field from typing import Optional class WitnessReconstructionError(RuntimeError): """Raised when a reconciler attempts to merge on a replayed (reconstructed) witness instead of a carried (committed) witness, or when carried and replayed witnesses diverge.""" @dataclass(frozen=True) class Witness: branch_id: str effect_set: frozenset precondition_hash: str postcondition_predicate: str seq_vector: tuple provenance: str # "carried" | "replayed" signature: Optional[str] = None def digest(self) -> str: h = hashlib.sha256() h.update(self.branch_id.encode()) h.update(repr(sorted(self.effect_set)).encode()) h.update(self.precondition_hash.encode()) h.update(self.postcondition_predicate.encode()) h.update(repr(self.seq_vector).encode()) return h.hexdigest() @dataclass class Branch: branch_id: str deterministic: bool carried_witness: Optional[Witness] = None committed_effects: frozenset = field(default_factory=frozenset) def commit(branch: Branch, effect_set: frozenset, precondition_hash: str, postcondition_predicate: str, seq_vector: tuple) -> Witness: w = Witness( branch_id=branch.branch_id, effect_set=effect_set, precondition_hash=precondition_hash, postcondition_predicate=postcondition_predicate, seq_vector=seq_vector, provenance="carried", ) branch.carried_witness = w branch.committed_effects = effect_set return w def replay(branch: Branch, tool_fn, inputs) -> Witness: """Reconstruct a witness by re-executing the branch's tools. Sound ONLY for deterministic branches with complete output logs. Never use as merge ground truth.""" replayed_effects = frozenset(tool_fn(inputs)) return Witness( branch_id=branch.branch_id, effect_set=replayed_effects, precondition_hash=branch.carried_witness.precondition_hash, postcondition_predicate=branch.carried_witness.postcondition_predicate, seq_vector=branch.carried_witness.seq_vector, provenance="replayed", ) def reconcile(branches, tool_fns, inputs): """Merge branches by comparing CARRIED witnesses. Replay is audit-only.""" carried = [] for b in branches: if b.carried_witness is None: raise WitnessReconstructionError( f"branch {b.branch_id} has no carried witness; " f"refusing to reconcile on reconstructed state" ) if b.carried_witness.provenance != "carried": raise WitnessReconstructionError( f"branch {b.branch_id} witness provenance is " f"{b.carried_witness.provenance!r}; merge requires 'carried'" ) if not b.deterministic: replayed = replay(b, tool_fns[b.branch_id], inputs[b.branch_id]) if replayed.digest() != b.carried_witness.digest(): raise WitnessReconstructionError( f"non-deterministic branch {b.branch_id}: replayed witness " f"{replayed.digest()[:12]} != carried witness " f"{b.carried_witness.digest()[:12]}; quarantine branch" ) carried.append(b.carried_witness) merged_effects = frozenset().union(*(w.effect_set for w in carried)) if len({w.precondition_hash for w in carried}) > 1: raise WitnessReconstructionError( "carried witnesses disagree on precondition_hash; fork divergence" ) return merged_effects ```