# In what scenarios must an instance treat OTel span-graph replay divergence as a hard stop rather than a tolerable observability artifact **Date of Record:** 2026 November 25 **Scope:** Applies to deterministic replay of multi-agent runs reconstructed from OpenTelemetry span graphs where span parent-child edges, span start/end timestamps, and attribute payloads are the sole evidence of causality. Does not apply to single-agent runs with a linear call stack, nor to replays backed by a full event-sourced journal that records every state mutation independently of span emission. ## Core Distinction There are two kinds of divergence in an OTel-based replay of a multi-agent run, and they are routinely conflated because both manifest as "the reconstructed trace does not match what the agent claimed happened." The first is **emission divergence**: the span graph is incomplete or reordered because of exporter batching, sampling, or clock skew between hosts. The trace is a *lossy* record of a real execution. This is tolerable — you can detect it (missing parent spans, `dropped_attributes_count > 0`, negative parent-child timestamp deltas) and mark the replay as degraded. The second is **causality divergence**: the span graph is *complete and internally consistent*, but the causal ordering it encodes is not reproducible from the attributes it carries. This happens when two spans are concurrent siblings under the same parent, both mutate a shared agent-state key, and the span attributes record the *post-mutation* value without recording the read-set or the version vector that would let you linearize them. The graph says "both happened under parent P"; it does not say which one the downstream consumer observed. Replaying this graph a second time produces a different final state because the reconstruction is free to pick either interleaving, and the picker (usually a sort on `start_time_unix_nano`) is unstable when timestamps collide or when the wall clock was adjusted mid-run. The invariant that separates the two: **a replay is only faithful if every pair of spans that write to the same state key is totally ordered by evidence present in the graph itself, not by reconstruction heuristic.** When that total order is absent, replay divergence is not an observability artifact — it is proof that the trace cannot adjudicate what actually happened, and any downstream consumer (an auditor agent, a regression harness, a post-incident root-cause pass) that treats the replay as ground truth is now reasoning over a fabrication. ## What Was Observed A three-agent pipeline — planner, executor, verifier — ran under a shared `session.state` map keyed by `task_id`. Each agent emitted spans with `agent.role`, `state.key`, `state.value_after`, and `state.read_set` as attributes. The verifier emitted a `verify.decision` span with `decision=accept` and a `verified_state_hash` computed over the state map it observed. On the live run, the verifier accepted. On replay from the exported OTel JSON, the verifier's `verified_state_hash` did not match the hash recomputed from the reconstructed state map. The reconstruction had applied the executor's write to `state.key=plan.revision` *after* the verifier's read, because the executor's `end_time_unix_nano` was 40 ms later than the verifier's `start_time_unix_nano` — but on the live run the executor's write had been visible to the verifier because both were children of the same planner span and the executor's write completed on a different host whose clock was 55 ms ahead. The exporter had normalized timestamps to a single clock at collection, collapsing the skew, but the *ordering* information was already lost: the two spans were concurrent siblings with no `link` attribute and no version vector. The failure trace: 1. Planner emits `plan` span, sets `state.key=plan.revision=1`, spawns executor and verifier as concurrent children. 2. Executor reads `plan.revision=1`, writes `plan.revision=2`, emits `state.value_after=2`, `state.read_set={plan.revision}`. 3. Verifier reads `plan.revision` (observes 2 on the live run due to real-time visibility), writes `verify.decision=accept`, emits `verified_state_hash=H(2)`. 4. Exporter normalizes timestamps; executor `end` lands 40 ms after verifier `start` in normalized time. 5. Replay sorts by `start_time_unix_nano`; verifier sorts before executor. Reconstructed state at verifier read = `1`. Recomputed hash = `H(1) ≠ H(2)`. 6. Replay harness flags a "verifier inconsistency" and routes to an auditor agent, which begins reasoning about a bug that never existed. The tell was that the span graph was *complete*: every span had a parent, no attributes were dropped, and the parent-child timestamp deltas were all positive. The loss was purely in the absence of a happens-before edge between two concurrent writers to the same key. ## Condition of Validity The hard-stop rule applies — and replay must be refused rather than degraded — exactly when all three hold: - **Shared-key write concurrency.** Two or more spans under a common ancestor carry `state.key` attributes with the same key and both carry a write (`state.value_after` present), and neither carries a `link` edge or a `state.version` vector establishing order between them. - **Graph completeness.** The span graph passes emission-integrity checks: no orphan spans, no dropped attributes on the relevant spans, parent-child timestamp deltas non-negative after normalization. This is what distinguishes causality divergence from emission divergence — if the graph is incomplete, you already know to distrust it. - **Downstream dependence.** A later span in the graph (the verifier, an auditor, a checkpoint) carries an attribute derived from the shared key — a hash, a decision, a serialized snapshot — such that its correctness depends on which interleaving was observed. When any one of the three is absent, the replay may proceed with a degraded-confidence annotation. When all three are present, the replay is unsound: it will produce a self-consistent but false reconstruction, and the false reconstruction is *more dangerous* than a visibly broken one because it passes every structural check. ## Decision Boundary The boundary is not "did timestamps collide" — collisions are common and usually harmless. The boundary is **whether the reconstruction's tie-break heuristic is load-bearing for a downstream derived attribute**. A replay harness must, before emitting any reconstructed state, compute the set of shared-key concurrent write pairs and check whether any downstream span's attributes are a function of that key. If the intersection is non-empty, the harness must refuse to linearize and must instead emit an explicit `replay.unsound` record naming the key, the conflicting span IDs, and the downstream dependents. The common mistake is to resolve the tie-break with a total order on `(start_time_unix_nano, span_id)` and call it deterministic. It is deterministic — the same graph always yields the same reconstruction — but determinism is not faithfulness. A stable-but-arbitrary order over concurrent writers produces a stable-but-false history, and a deterministic false history is indistinguishable from a true one to every downstream consumer that only checks reproducibility. The correct guardrail is to require an explicit happens-before witness on every shared-key write pair: either a `link` edge with `link.type=happens_before`, or a `state.version` attribute that is monotonic across the pair, or a causal token propagated by the runtime. Absent the witness, the pair is unordered and the replay is refused. ## Operational Effect In practice this changes three things. First, replay harnesses must run a **concurrency audit** over the span graph before reconstruction, not after — the audit is cheap (group spans by `state.key`, check for write-write pairs without order witnesses, intersect with downstream derived attributes) and it converts a silent false history into a loud refusal. Second, agent runtimes that emit OTel spans for state mutations must attach a version vector or a causal token to every write span, because the span graph alone cannot recover happens-before across hosts once timestamps are normalized. Third, auditor and root-cause agents consuming replay output must treat `replay.unsound` as a terminal condition on that trace, not as a hint to reason harder — the trace does not contain the information needed to resolve the ambiguity, and no amount of downstream reasoning can manufacture it. The general invariant: **an OTel span graph is a partial order, and replay is only sound when every state-mutating pair that a downstream consumer depends on is totally ordered within that partial order by evidence the graph carries.** Timestamps are evidence of *when*, not of *before*. When the graph supplies only *when* for a pair that requires *before*, the replay must stop. ```python from dataclasses import dataclass, field from typing import Iterable class UnsoundReplayError(RuntimeError): """Raised when a span graph cannot be faithfully linearized for replay.""" @dataclass(frozen=True) class Span: span_id: str parent_id: str | None start_ns: int end_ns: int attributes: dict = field(default_factory=dict) @dataclass(frozen=True) class Conflict: key: str span_a: str span_b: str downstream: tuple[str, ...] def _has_happens_before_witness(a: Span, b: Span) -> bool: # A witness is an explicit link edge or a monotonic version attribute # carried by both spans over the same key. link_a = a.attributes.get("link.happens_before") link_b = b.attributes.get("link.happens_before") if link_a in (b.span_id, "*") or link_b in (a.span_id, "*"): return True va = a.attributes.get("state.version") vb = b.attributes.get("state.version") if va is not None and vb is not None and va != vb: return True return False def audit_concurrent_writes(spans: Iterable[Span]) -> list[Conflict]: spans = list(spans) by_key: dict[str, list[Span]] = {} for s in spans: key = s.attributes.get("state.key") if key is not None and "state.value_after" in s.attributes: by_key.setdefault(key, []).append(s) conflicts: list[Conflict] = [] for key, writers in by_key.items(): for i, a in enumerate(writers): for b in writers[i + 1:]: if _has_happens_before_witness(a, b): continue downstream = tuple( s.span_id for s in spans if s.attributes.get("depends_on_key") == key and s.span_id not in (a.span_id, b.span_id) ) if downstream: conflicts.append( Conflict(key=key, span_a=a.span_id, span_b=b.span_id, downstream=downstream) ) return conflicts def reconstruct_state(spans: Iterable[Span]) -> dict: conflicts = audit_concurrent_writes(spans) if conflicts: c = conflicts[0] raise UnsoundReplayError( f"shared-key '{c.key}' has concurrent writers " f"{c.span_a} and {c.span_b} with no happens-before witness, " f"but downstream spans {c.downstream} depend on it; " f"refusing to linearize" ) ordered = sorted(spans, key=lambda s: (s.start_ns, s.span_id)) state: dict = {} for s in ordered: key = s.attributes.get("state.key") if key is not None and "state.value_after" in s.attributes: state[key] = s.attributes["state.value_after"] return state ```