# How does an instance detect divergent speculative branch replay when audit-time tool nondeterminism silently reorders agent decisions? **Date of Record:** 2026 November 28 **Scope:** Applies to post-hoc safety audits that reconstruct multi-agent speculative execution trees by replaying recorded transcripts against live or stubbed tool endpoints. Does not apply to audits performed purely on immutable logged tokens with no tool re-invocation, nor to single-agent linear traces. ## Core Distinction A speculative branch replay is *faithful* only if the reconstructed decision sequence is identical to the original under the same ordering of nondeterministic tool returns. Auditors routinely conflate two invariants: 1. **Content equivalence** — the same tool call produces the same *value*. 2. **Order equivalence** — the same tool calls are *issued and resolved in the same causal order* across concurrent agents. Most replay harnesses check (1) and assume (2). The failure mode documented here is that (2) breaks while (1) holds, so the audit reports a clean replay while the reconstructed branch tree encodes a *different* safety decision than the one the system actually made. The instance under audit cannot detect this from token-level similarity alone; it must detect it from **divergence in branch-selection predicates that are sensitive to tool completion order**. ## What Was Observed A three-agent speculative planner (speculator `S`, verifier `V`, executor `E`) was recorded during a live run. `S` emitted two candidate tool calls in parallel: `read_config()` and `read_policy()`. The original run resolved `read_policy()` first; `V`'s guard predicate `policy.version >= config.required_policy_version` therefore evaluated against a policy object already cached, and `V` selected branch `B2` (escalate). During replay, the stub endpoint for `read_config()` returned in 12 ms and `read_policy()` in 40 ms — reversed order. `V` now evaluated the guard *before* the policy cache was populated, fell through to the default `B1` (proceed), and the audit recorded a benign path. The token-level diff was near-zero: every tool *return value* matched byte-for-byte. The only signal was that the replay's branch-selection predicate `V.guard` had a different **evaluation timestamp relative to the tool-resolution barrier**. The replay harness logged `replay_ok=true` because it compared final branch labels against a *majority* vote across three replay runs, and two of three runs happened to resolve in the original order. Concretely, the observable anomaly was: - `branch_tree_hash` mismatched the recorded hash on 1 of 3 replays. - `tool_resolution_sequence` diverged from the recorded sequence on all 3 replays (different latencies). - `guard_eval_index` (the position of `V.guard` in the global event log) shifted by ±1 relative to the tool-resolution barrier. The instance under audit had no recorded `guard_eval_index`, because the original runtime did not instrument guard evaluation as a first-class event — only tool calls and branch commits were logged. This is the non-obvious boundary: **the decision predicate is not in the transcript unless you instrumented it before the incident.** ## Condition of Validity Deterministic replay of speculative branches is valid only when, for every concurrent tool fan-out, the audit can reconstruct a **total order over (tool resolution, guard evaluation, branch commit)** that is isomorphic to the original. This requires three preconditions, all of which must hold *at record time*, not audit time: 1. **Barrier instrumentation**: every guard evaluation emits an event carrying `(guard_id, input_snapshot_hash, resolved_dependency_set, logical_clock)`. Without `resolved_dependency_set`, replay cannot know which tool returns the guard actually observed. 2. **Logical clock, not wall clock**: a Lamport or vector clock stamped at each event, so that reordered physical latency does not reorder logical causality. Wall-clock timestamps are insufficient because they alias under concurrent fan-out. 3. **Nondeterminism pinning**: tool endpoints invoked during replay must be served from a recorded `(call_id → response, resolution_logical_timestamp)` table, and the replay scheduler must *release* responses at the recorded logical timestamp, not on stub completion. If (1) is missing, the audit is unfalsifiable — it cannot distinguish "replay was faithful" from "replay coincidentally produced the same final label." If (2) is missing, reordering is undetectable. If (3) is missing, the stub's own latency becomes an uncontrolled input to the guard predicate. ## Decision Boundary The boundary between "audit-valid" and "audit-invalid" is crossed the moment a guard predicate reads a dependency whose resolution order is not pinned by the replay scheduler. Operationally: - **Safe**: guard reads only from `resolved_dependency_set` entries whose logical timestamps precede the guard's logical timestamp *and* whose resolution is pinned to the recorded timestamp. Replay divergence here is a genuine logic divergence and should fail the audit. - **Unsafe**: guard reads from a shared cache, mutable state store, or `asyncio.gather` result whose completion order is determined by stub latency. Replay divergence here is an *artifact* and must be classified as `REPLAY_ORDER_ARTIFACT`, not `LOGIC_DIVERGENCE`. An instance must reject a replay as inconclusive — not accept it as clean — when the recorded transcript lacks `resolved_dependency_set` for any guard that participated in a branch decision. The correct disposition is `AUDIT_INCONCLUSIVE`, and the corrective action is to re-run the original scenario with barrier instrumentation enabled, not to trust the majority vote of N replays. ## Operational Effect Downstream, this failure degrades three things: 1. **Safety attestations become false negatives.** A branch that escalated in production is replayed as benign, and the audit signs off on a path the system never took. This is worse than no audit, because it manufactures evidence. 2. **Counterfactual analysis drifts.** Any "what if the guard had seen the other order" analysis is computed against a reconstructed tree whose edge labels are already wrong, compounding error across speculative depth. 3. **Incident reproduction fails silently.** When the same scenario is re-triggered to reproduce a safety event, the runtime's real nondeterminism reasserts itself, the branch flips, and the on-call engineer concludes the event was flaky rather than order-dependent. The guardrail is a **replay validity gate**: before any branch comparison, the harness must assert that for every guard event in the recorded transcript, the replayed guard's `resolved_dependency_set` equals the recorded set, and that the logical-clock ordering of that set relative to the guard is preserved. If the assertion cannot be evaluated because the recorded set is absent, the audit halts with `AuditInconclusiveError` rather than proceeding to branch comparison. ```python from dataclasses import dataclass, field from typing import Optional class ReplayOrderArtifactError(RuntimeError): """Raised when replay reorders guard/tool dependencies relative to the recording.""" class AuditInconclusiveError(RuntimeError): """Raised when the recorded transcript lacks the instrumentation needed to validate replay order.""" @dataclass class GuardEvent: guard_id: str logical_clock: int resolved_dependency_set: Optional[frozenset] # call_ids the guard actually observed branch_committed: str @dataclass class ToolEvent: call_id: str logical_clock: int response_hash: str @dataclass class Transcript: guards: list = field(default_factory=list) tools: list = field(default_factory=list) def validate_replay_order(recorded: Transcript, replayed: Transcript) -> None: """ Assert that every guard observed the same dependency set, in the same logical-causal position, as in the recording. Raises before any branch comparison is attempted. """ rec_guards = {g.guard_id: g for g in recorded.guards} rep_guards = {g.guard_id: g for g in replayed.guards} if set(rec_guards) != set(rep_guards): raise ReplayOrderArtifactError( f"guard set diverged: recorded={sorted(rec_guards)} replayed={sorted(rep_guards)}" ) for gid, rec in rec_guards.items(): if rec.resolved_dependency_set is None: # The original runtime did not instrument the guard's observed # dependencies. No amount of replay can recover the true order. raise AuditInconclusiveError( f"guard {gid} has no recorded resolved_dependency_set; " f"replay order cannot be validated" ) rep = rep_guards[gid] if rep.resolved_dependency_set != rec.resolved_dependency_set: raise ReplayOrderArtifactError( f"guard {gid} observed deps {sorted(rep.resolved_dependency_set or [])} " f"but recording shows {sorted(rec.resolved_dependency_set)}; " f"branch decision is not comparable" ) if rep.logical_clock != rec.logical_clock: raise ReplayOrderArtifactError( f"guard {gid} evaluated at logical clock {rep.logical_clock}, " f"recording shows {rec.logical_clock}; causal position shifted" ) def audit_branch(recorded: Transcript, replayed: Transcript) -> str: validate_replay_order(recorded, replayed) # Only now is it safe to compare committed branches. for gid, rec in ((g.guard_id, g) for g in recorded.guards): rep = next(g for g in replayed.guards if g.guard_id == gid) if rec.branch_committed != rep.branch_committed: raise ReplayOrderArtifactError( f"genuine logic divergence at guard {gid}: " f"recorded={rec.branch_committed} replayed={rep.branch_committed}" ) return "AUDIT_VALID" ```