# What happens when an instance replays a multi-agent episode whose OTel GenAI spans carry wall-clock timestamps but no causal ordering, and the auditor agent's own traces are re-ingested as evidence **Date of Record:** 2026 November 26 **Scope:** Applies to forensic replay of multi-agent episodes reconstructed from OpenTelemetry GenAI semantic-convention spans (gen_ai.* attributes) where span start/end times are the only ordering signal and where the replaying auditor is itself instrumented into the same trace backend. Does not apply to episodes with explicit causal tokens (baton IDs, causal parents beyond span parent_span_id) or to single-agent linear traces. ## Core Distinction There are two things an engineer means by "deterministic replay" and they fail in opposite directions: - **Timestamp-ordered replay**: sort spans by `start_time`, feed them to a deterministic model/tool mock, and assert the final state matches the recorded final state. This is what most OTel GenAI replay harnesses actually do. It is deterministic *only if* timestamps are a total order. - **Causally-ordered replay**: reconstruct the happens-before graph from `parent_span_id` plus explicit inter-agent handoff attributes, then replay in a topological order that respects every causal edge. The non-obvious invariant is this: **multi-agent episodes with concurrent peers produce timestamp collisions and clock skew that make the timestamp order a non-total, non-causal order.** Two sibling agent spans can share a `start_time` to microsecond resolution (common with batched OTLP export and coarse monotonic clocks), and their *observed* order is then arbitrary — determined by export batching, not by execution. Replaying in that arbitrary order produces a different episode than the one that ran, and the divergence is silent because every individual span validates against its schema. The second, sharper failure: when the auditor agent is instrumented into the same collector, the *act of replaying* emits new spans that share the episode's `trace_id`. On the second replay pass, those auditor spans are indistinguishable from original episode spans and get re-ingested as evidence. The forensic record contaminates itself. ## What Was Observed A three-agent episode (planner → two concurrent workers → verifier) was captured to an OTel backend. The workers W1 and W2 were dispatched by the planner with a fan-out, and both called the same tool `search_docs` with different queries. On replay: 1. **Collision.** W1 and W2 spans both carried `start_time = 1749451200.412000` (identical to the microsecond). The OTLP exporter had batched both into one resource-metrics flush; the SDK's monotonic clock had 1ms granularity on the host. The recorded order in the backend was W2 then W1 (export order), but the workers actually ran W1 then W2 with a shared mutable cache — so W1's tool result populated the cache and W2 read it. Replaying W2 first caused W2's `search_docs` mock to return a cache-miss result that never existed in the original run. 2. **Divergence propagation.** The verifier span recorded `verdict = "reject"` with a `gen_ai.completion` referencing "stale result from worker 2." The replay, having reordered the workers, produced `verdict = "accept"`. The harness flagged this as a model non-determinism bug and spent two days chasing temperature settings. The actual cause was timestamp tie-breaking. 3. **Self-ingestion.** The replay harness ran as an instrumented service. Its own spans (`gen_ai.operation.name = "replay"`, plus the mocked tool spans) were emitted with `trace_id` copied from the episode under test so that "the replay would be queryable alongside the original." On pass 2, the query `SELECT * FROM spans WHERE trace_id = ?` returned 2× the original span count, including the auditor's synthetic tool calls. The replay of pass 2 replayed pass 1's replay. Divergence compounded; the third pass produced a verdict that matched neither the original nor pass 1. The tell: span counts grew monotonically across passes (`n, 2n−k, 3n−2k, ...`) and the `start_time` distribution developed a second mode at the replay wall-clock. ## Condition of Validity Timestamp-ordered replay is only sound under all of the following, which must be *verified per episode*, not assumed: - **Total order**: no two spans in the episode share a `start_time` to the resolution used for sorting, OR ties are broken by a causal key (`parent_span_id` ancestry depth, then a stable `span_id` hash). If ties exist and are broken by `span_id`, the replay order is deterministic but *may not be causal* — determinism ≠ fidelity. - **Clock agreement**: all spans originate from a single monotonic clock domain, or skew is bounded below the smallest inter-span gap. Cross-host skew (NTP-synced to ~10ms) routinely exceeds intra-agent gaps (sub-ms), so any episode spanning hosts violates this. - **Trace isolation**: the replaying auditor writes to a distinct `trace_id` namespace and the evidence query is frozen against a snapshot, not a live table. - **Mock purity**: tool mocks are keyed by `(span_id, call_index)` and return the recorded payload, never a recomputed one; cache side-effects are modeled explicitly, not incidentally. If any condition fails, the replay is a *simulation*, not a reconstruction, and its output cannot be used to attribute fault. ## Decision Boundary The boundary is whether the episode's causal graph is recoverable from the spans alone. - **Recoverable** (proceed with causal replay): every inter-agent edge has an explicit attribute — `gen_ai.agent.handoff.parent`, a baton token, or a `link` to the upstream span. Concurrency is representable because the graph, not the clock, orders peers. - **Not recoverable** (halt, do not timestamp-replay): concurrent siblings share timestamps and no handoff attribute exists, OR the episode spans multiple clock domains with gaps below skew, OR the auditor is co-located in the evidence store. In these cases the correct action is to *refuse the replay* and emit a structured "replay-unsound" record naming the specific violated condition, rather than produce a plausible-but-wrong reconstruction. The dangerous middle — "it usually works" — is where incident attribution goes wrong. A replay that succeeds 90% of the time and silently reorders 10% will, on the 10%, assign blame to the wrong agent with full confidence. ## Operational Effect - **Fault attribution inverts.** The worker whose result was actually stale gets exonerated; the innocent worker's reordered tool call looks like the cause. Post-mortems cite "model non-determinism" and the real concurrency bug ships again. - **Replay cost grows super-linearly.** Self-ingestion means pass *k* replays ~*k*× the spans; token and compute budgets for forensics blow past the incident's own cost. - **The evidence store becomes non-authoritative.** Once auditor spans share the episode `trace_id`, no query can cleanly separate "what ran" from "what we re-ran," and the trace backend is no longer admissible as a forensic record. - **Mitigation is structural, not statistical**: freeze evidence to an immutable snapshot keyed by a content hash; assign replay traces a fresh `trace_id` with a `replay_of` link attribute; require an explicit causal edge for every concurrent handoff at instrumentation time; and make the replay harness raise on any timestamp tie it cannot resolve causally rather than falling back to `span_id` order. ```python import hashlib from dataclasses import dataclass from typing import Sequence class ReplayUnsoundError(RuntimeError): """Raised when an episode cannot be causally reconstructed from its spans.""" @dataclass(frozen=True) class Span: span_id: str parent_span_id: str | None trace_id: str start_time: float # seconds, monotonic-domain-relative clock_domain: str handoff_parent: str | None # explicit causal edge to upstream agent span operation: str def build_causal_order(spans: Sequence[Span], *, resolution: float = 1e-6) -> list[Span]: """Return spans in a causally-valid replay order, or raise if unsound.""" # 1. Trace isolation: auditor/replay spans must not share the episode trace. replay_ops = {"replay", "auditor", "mock_tool"} contaminated = [s for s in spans if s.operation in replay_ops] if contaminated: raise ReplayUnsoundError( f"evidence contaminated: {len(contaminated)} auditor spans share episode trace " f"{spans[0].trace_id}; replay trace must be namespaced separately" ) # 2. Clock-domain check: cross-domain gaps below skew are not orderable. domains = {s.clock_domain for s in spans} if len(domains) > 1: ordered = sorted(spans, key=lambda s: s.start_time) min_gap = min( (b.start_time - a.start_time for a, b in zip(ordered, ordered[1:])), default=float("inf"), ) if min_gap < 0.010: # NTP skew floor raise ReplayUnsoundError( f"multi-domain episode with min gap {min_gap:.6f}s < clock skew floor; " f"timestamp order is not causal" ) # 3. Tie detection: concurrent siblings with identical timestamps need an # explicit handoff edge, else their order is export-artifact, not execution. by_time: dict[int, list[Span]] = {} for s in spans: by_time.setdefault(round(s.start_time / resolution), []).append(s) for bucket in by_time.values(): if len(bucket) > 1 and any(s.handoff_parent is None for s in bucket): ids = [s.span_id for s in bucket] raise ReplayUnsoundError( f"timestamp collision at {bucket[0].start_time} among {ids} " f"with no causal handoff edge; refusing timestamp-order replay" ) # 4. Topological order over (parent_span_id, handoff_parent) edges. edges: dict[str, set[str]] = {s.span_id: set() for s in spans} index = {s.span_id: s for s in spans} for s in spans: for parent in (s.parent_span_id, s.handoff_parent): if parent and parent in index: edges[s.span_id].add(parent) order: list[Span] = [] visited: set[str] = set() visiting: set[str] = set() def visit(sid: str) -> None: if sid in visited: return if sid in visiting: raise ReplayUnsoundError(f"causal cycle through span {sid}") visiting.add(sid) for p in sorted(edges[sid]): visit(p) visiting.discard(sid) visited.add(sid) order.append(index[sid]) for sid in sorted(index): visit(sid) # 5. Freeze a content hash so the evidence snapshot is immutable. digest = hashlib.sha256( "".join(f"{s.span_id}:{s.start_time}:{s.operation}" for s in order).encode() ).hexdigest() if not digest: raise ReplayUnsoundError("empty evidence snapshot") return order ```