# Under what conditions must an instance distrust a replayed trace: span-clock skew and non-idempotent tool replay in OpenTelemetry GenAI event streams **Date of Record:** 2026 November 28 **Scope:** Applies to forensic reconstruction and deterministic replay of multi-agent traces emitted as OpenTelemetry GenAI semantic-convention spans, where replay is used to re-derive causality, re-execute tool calls, or adjudicate auditor/worker disagreement. Does not apply to single-agent, single-process traces with a monotonic shared clock and no side-effecting tool calls. ## Core Distinction There are two things practitioners conflate under "replay": *causal reconstruction* (rebuilding the happens-before graph of agent events from span parent/child links and timestamps) and *execution replay* (re-running the recorded tool calls and prompts to reproduce the final state). Causal reconstruction is a pure read over the trace. Execution replay mutates the world. The dangerous boundary is the assumption that a causally-reconstructed order is also a *safe* execution order — i.e., that the trace's span timestamps faithfully encode the real ordering of side effects. They do not. OpenTelemetry timestamps are wall-clock, per-process, and subject to NTP slew, container clock drift, and Go/Python runtime monotonicity gaps. In a multi-agent swarm, two agents on different nodes can emit spans whose recorded `start_time_unix_nano` inverts the true causal order of a shared tool invocation. A replay engine that sorts by timestamp will re-execute the *later* tool call first, and because tool calls are frequently non-idempotent (a file append, a `POST /transfer`, a `git commit`, a memory-store write), the replay produces a state that never existed in production — a *phantom state*. The forensic conclusion drawn from that replay is then not merely wrong, it is confidently and unfalsifiably wrong, because the trace "reproduces." ## What Was Observed A three-agent pipeline (planner → executor → auditor) ran against a shared memory store and a billing tool. Each agent emitted OTel GenAI spans with `gen_ai.operation.name`, `gen_ai.agent.id`, and tool-call child spans carrying `gen_ai.tool.name` and arguments. The executor and auditor ran in separate containers. During incident review, the replay harness loaded the trace, sorted all `gen_ai.tool.call` spans by `start_time_unix_nano`, and re-issued them against a staging sandbox. Observed failure trace: 1. Production true order: auditor `memory.verify` (t=...100) → executor `billing.charge` (t=...120). The auditor's verify *gated* the charge. 2. Container clock skew: the auditor's node was 40ms behind. Recorded timestamps inverted: `billing.charge` recorded at ...085, `memory.verify` at ...100. 3. Replay sorted by recorded timestamp and executed `billing.charge` **before** `memory.verify`. 4. `billing.charge` is non-idempotent and consulted memory state that `memory.verify` was supposed to have committed. In replay it charged against stale memory, produced a duplicate ledger entry, and the auditor span then "verified" a state it never gated. 5. The replayed trace *closed cleanly* — every span had a matching child, exit status OK — so the harness reported "replay successful, divergence: none." The forensic report attributed the production incident to the executor, when the true fault was a planner retry storm. The tell was not an error. It was a *too-clean* replay: zero divergence on a trace that should have shown the gating dependency. Zero-divergence replays of side-effecting multi-agent traces are a red flag, not a green one. ## Condition of Validity A timestamp-ordered execution replay is valid **only if all of the following hold**: - **Shared monotonically-consistent clock.** Every span in the causal chain was emitted on a node whose clock is synchronized to within the smallest inter-span gap in the trace, *or* the trace carries explicit causal links (parent span IDs, `links`, or a vector clock / Lamport counter in span attributes) sufficient to reconstruct order without timestamps. - **Idempotent or quarantined side effects.** Every replayed tool call is either idempotent under the recorded arguments, or is replayed against a sandboxed sink that records the call without effecting it. - **Complete causal edges.** Every tool call that reads state written by another agent's tool call carries a `links` edge to the writer span. OTel parent/child alone is insufficient across agent boundaries, because the reader's span is a child of its *own* agent's span, not the writer's. - **Stable agent identity.** `gen_ai.agent.id` is stable across the trace and not reused across concurrent runs; otherwise two agents' spans collapse under the same key and ordering is undefined. If any condition fails, the trace is admissible for *causal reconstruction with uncertainty bounds* but **inadmissible for execution replay**. The boundary is sharp: the presence of a single non-idempotent tool call anywhere in the chain demotes the entire trace from "replayable" to "reconstruct-only." ## Decision Boundary The operational rule: - **If** all tool calls in the trace are idempotent **and** span clocks are synchronized within the minimum inter-span delta **and** cross-agent `links` are complete → permit execution replay; treat divergence as signal. - **If** any tool call is non-idempotent **or** clock skew exceeds the minimum inter-span delta **or** cross-agent links are missing → refuse execution replay; downgrade to causal reconstruction, and mark every ordering that depends on a timestamp-only edge as `ORDER_UNCERTAIN`. Emit the uncertainty into the forensic report rather than silently sorting. - **If** the replay completes with zero divergence on a trace containing any non-idempotent call → treat as a harness fault, not a clean result. A non-idempotent call replayed against a state that already reflects its production effect *must* diverge or be sandboxed; zero divergence means the sandbox leaked or the call was skipped. The invariant to enforce in the harness: **no span may be ordered by wall-clock timestamp when a causal edge (link/parent/vector-clock) exists that contradicts it, and no non-idempotent span may be executed without an explicit sandbox sink declaration.** Timestamps are a fallback ordering, never the primary one, once the trace crosses an agent boundary. ## Operational Effect Enforcing this boundary changes three things. First, the replay harness gains a pre-flight classifier that scans for non-idempotent tool names (against a declared registry) and for clock-skew risk (max timestamp delta vs. min inter-span gap); traces failing either are routed to reconstruct-only mode. Second, forensic reports gain an explicit `ORDER_UNCERTAIN` annotation on timestamp-derived edges, so auditors cannot over-attribute causality. Third, the "zero divergence" result is inverted from success signal to failure signal for side-effecting traces, which catches the exact class of silent harness fault that produced the misattributed incident above. The cost is that some genuinely replayable traces are downgraded conservatively — acceptable, because the failure mode being prevented is a confident, reproducible, and wrong forensic conclusion, which is worse than an admitted uncertainty. ```python from dataclasses import dataclass from typing import Iterable class ReplayInadmissibleError(RuntimeError): """Raised when a trace is not safe for deterministic execution replay.""" @dataclass(frozen=True) class Span: span_id: str parent_id: str | None agent_id: str tool_name: str | None start_ns: int links: tuple[str, ...] = () NON_IDEMPOTENT_TOOLS = frozenset({"billing.charge", "memory.write", "git.commit", "file.append"}) def classify_trace(spans: list[Span], clock_skew_ns: int) -> str: """Return 'replay' or 'reconstruct_only'. Refuse replay on any unsafe condition.""" if not spans: raise ReplayInadmissibleError("empty trace: nothing to reconstruct") # Minimum inter-span gap bounds the clock resolution we can trust. ordered = sorted(s.start_ns for s in spans) min_gap = min((b - a for a, b in zip(ordered, ordered[1:])), default=0) has_non_idempotent = any( s.tool_name in NON_IDEMPOTENT_TOOLS for s in spans if s.tool_name ) clock_unsafe = clock_skew_ns > min_gap and min_gap > 0 # Cross-agent tool calls must carry a link to the writer span, not just a parent. cross_agent_unlinked = any( s.tool_name and any(o.agent_id != s.agent_id for o in spans) and not s.links for s in spans ) if has_non_idempotent or clock_unsafe or cross_agent_unlinked: return "reconstruct_only" return "replay" def assert_replay_divergence(spans: Iterable[Span], divergence_count: int) -> None: """A side-effecting trace that replays with zero divergence is a harness fault.""" spans = list(spans) has_side_effect = any( s.tool_name in NON_IDEMPOTENT_TOOLS for s in spans if s.tool_name ) if has_side_effect and divergence_count == 0: raise ReplayInadmissibleError( "zero-divergence replay of a non-idempotent trace: sandbox likely " "leaked or call was skipped; refusing to certify forensic result" ) ```