# How should an instance replay a multi-agent tool-call DAG deterministically when non-idempotent tools and clock-skewed timestamps make the trace order-ambiguous? **Date of Record:** 2026 December 1 **Scope:** Applies to post-incident forensic replay of multi-agent traces where tool calls form a DAG and at least one leaf tool is non-idempotent or time-sensitive. Does not apply to single-agent linear traces with fully idempotent, content-addressed tool outputs, or to live re-execution used for testing rather than reconstruction. ## Core Distinction There are two things practitioners conflate under "replay": *reconstruction* (rebuilding the causal state the agents actually saw) and *re-execution* (running the tools again to see what happens). Forensic replay must be the former. Re-execution is a different operation with different failure modes, and the boundary failure documented here is what happens when a replay harness silently degrades from reconstruction into re-execution because the trace lacks enough ordering information to rebuild the DAG without touching a live tool. The invariant that must hold: **a replayed trace must be a pure function of the recorded trace bytes plus the recorded tool *results*, never of the tool *implementations*.** The moment replay invokes a tool to resolve an ambiguity, it is no longer forensics—it is a new execution whose divergence from the incident is unmeasurable. ## What Was Observed A three-agent swarm (planner `P`, executor `E`, auditor `A`) produced a tool-call DAG over a 4.2-second window. The trace store recorded each span with a wall-clock `start_ts` and `end_ts` from the emitting agent's local clock, plus a `parent_span_id`. Two facts combined to break naive replay: 1. **Clock skew.** `E`'s host clock ran 180 ms ahead of `A`'s. `E`'s `write_record` span (call it `S_E`) carried `start_ts = T+0.900`, while `A`'s `verify_record` span (`S_A`) carried `start_ts = T+0.760`. By timestamp, `S_A` looks like it preceded `S_E`. By causal intent, `A` verified the record `E` wrote, so `S_E` must precede `S_A`. The parent links did not disambiguate because `A` had been spawned by `P`, not `E`—its `parent_span_id` pointed at `P`, and `P` had fanned out to both `E` and `A` concurrently. 2. **Non-idempotent leaf tool.** `write_record` appended to a log with a server-assigned sequence number. Its recorded *result* was `{"seq": 4471}`. The replay harness, unable to order `S_E` and `S_A` from timestamps, fell back to "re-run the ambiguous spans to see which ordering is consistent." It re-invoked `write_record`, got `seq = 4472`, and then re-invoked `verify_record` against a record that now existed twice. The reconstructed state had a duplicate record that never existed during the incident, and the auditor's verdict flipped from `PASS` to `FAIL_DUPLICATE`—a verdict the auditor never actually issued. The forensic report attributed a duplicate-write bug to the swarm. The real incident was a timeout on an unrelated read. The replay manufactured the finding. ## Condition of Validity Deterministic replay is valid **only if** the trace carries a *causal ordering witness* independent of wall-clock timestamps, and **only if** every tool invocation in the DAG is satisfied from recorded results rather than re-invoked. Concretely, replay is sound when all of the following hold: - Every span carries a monotonic logical clock (Lamport counter or vector clock) or an explicit `happens_before` edge, so ordering is recoverable without trusting `start_ts`. - Every tool call span carries its *recorded response payload*, not merely a status code, so the DAG can be reconstructed by substitution. - The replay engine is configured in `RECONSTRUCT` mode, which raises on any attempt to invoke a tool, rather than `REEXECUTE` mode, which permits it. If any of these is absent, the correct behavior is to **refuse to replay and emit an "order-ambiguous, non-reconstructible" verdict**—not to fall back to re-execution. The failure above occurred precisely because the harness treated re-execution as a graceful degradation of reconstruction. It is not a degradation; it is a category change. ## Decision Boundary The boundary is sharp and must be encoded as a hard gate, not a heuristic: - **Ordering resolvable from logical clock / explicit edges → RECONSTRUCT.** Substitute recorded results, build the DAG, replay verdicts. Never touch a tool. - **Ordering resolvable only from wall-clock timestamps, and all ambiguous spans are idempotent and time-insensitive → RECONSTRUCT with a flagged `timestamp_only_ordering` confidence downgrade.** Acceptable for read-only tools; the reconstructed state is still a pure function of the trace. - **Ordering resolvable only from wall-clock timestamps, and any ambiguous span is non-idempotent or time-sensitive → REFUSE.** Emit `OrderAmbiguousNonReconstructible`. Do not re-invoke. The forensic conclusion is "the trace cannot establish what happened here," which is itself a valid and important finding. - **Any path that would invoke a tool during replay → raise.** This is the guardrail that makes the other three enforceable rather than aspirational. The subtle trap: an engineer will argue that re-invoking an idempotent tool is harmless. It is not, because idempotency is a property of the *tool*, while replay soundness is a property of the *trace-to-state function*. A tool that is idempotent today may be non-idempotent after a deploy, so re-execution makes past forensic reports non-reproducible. Reconstruction must never depend on current tool behavior. ## Operational Effect Enforcing the gate changes three operational behaviors. First, trace producers must emit logical clocks at span emission; retrofitting is impossible, so this becomes a schema requirement at the agent SDK layer, not a replay-layer patch. Second, the replay harness gains a first-class `REFUSE` outcome, which incident responders must be trained to read as "inconclusive" rather than "harness broke"—otherwise they will disable the gate to "get an answer," which is exactly how the duplicate-write misattribution happened. Third, forensic reports become byte-reproducible: two analysts replaying the same trace on different days, with different tool versions deployed, must reach identical DAGs and identical verdicts, or the gate has failed. The invariant to carry forward: **replay reconstructs; it never re-executes. Ambiguity that cannot be resolved from the trace is reported, not resolved by touching the world.** ```python from dataclasses import dataclass, field from enum import Enum from typing import Any class ReplayMode(Enum): RECONSTRUCT = "reconstruct" REEXECUTE = "reexecute" @dataclass class Span: span_id: str tool: str logical_clock: int | None # Lamport counter, if emitted start_ts: float # wall clock, possibly skewed recorded_result: dict[str, Any] | None idempotent: bool time_sensitive: bool happens_before: set[str] = field(default_factory=set) class OrderAmbiguousNonReconstructible(RuntimeError): """Raised when replay cannot order non-idempotent spans from the trace alone.""" class ToolInvocationDuringReplay(RuntimeError): """Raised if replay attempts to invoke a live tool instead of substituting a result.""" def resolve_order(spans: list[Span]) -> list[Span]: # Prefer logical clocks; fall back to wall clock only under strict conditions. has_logical = all(s.logical_clock is not None for s in spans) if has_logical: return sorted(spans, key=lambda s: s.logical_clock) # type: ignore[arg-type] ordered = sorted(spans, key=lambda s: s.start_ts) # Wall-clock ties or near-ties among risky spans are not resolvable. for a, b in zip(ordered, ordered[1:]): if abs(b.start_ts - a.start_ts) < 0.250: # skew tolerance window risky = [s for s in (a, b) if not s.idempotent or s.time_sensitive] if risky: raise OrderAmbiguousNonReconstructible( f"spans {a.span_id} and {b.span_id} are within clock-skew " f"tolerance and at least one ({[s.span_id for s in risky]}) " f"is non-idempotent or time-sensitive; trace cannot order them" ) return ordered def replay(trace: list[Span], mode: ReplayMode) -> list[Span]: if mode is not ReplayMode.RECONSTRUCT: raise ToolInvocationDuringReplay( "forensic replay must operate in RECONSTRUCT mode; " "re-execution is a distinct operation" ) for span in trace: if span.recorded_result is None: raise ToolInvocationDuringReplay( f"span {span.span_id} ({span.tool}) has no recorded result; " f"replay would have to invoke the tool to reconstruct state" ) return resolve_order(trace) ```