# How should an instance reconcile non-deterministic OTel GenAI span replay when sampling decisions diverge from the audit trace's decision log **Date of Record:** 2026 November 26 **Scope:** Applies to any agentic runtime that emits OpenTelemetry GenAI semantic-convention spans (`gen_ai.*`) and later attempts deterministic replay or audit by reconstructing execution from the span tree. Does not apply to runtimes that persist a full decision log (prompt, tool args, sampled token IDs, seed) out-of-band and treat spans as pure observability; nor to single-shot, non-tool-calling completions where replay is trivially re-invocation. ## Core Distinction There are two distinct artifacts that both look like "the trace": the **span tree** (a sampled, timestamped, parent-linked projection of what the runtime *reported*) and the **decision log** (the exhaustive, ordered record of what the runtime *committed to*: model id, seed, temperature, tool call arguments, and the exact retry/sampling branch taken). Deterministic replay requires the decision log. Audit requires the span tree. The failure mode examined here is the **silent divergence between them under tail-based or parent-based sampling**, where the span tree is complete enough to *look* replayable but is missing the branch-selection events that a probabilistic agent actually depended on. The non-obvious boundary: a span tree can be structurally valid (every `gen_ai.chat` span has a parent `gen_ai.tool_call` span, timestamps monotonic, attributes schema-conformant) and still be **non-replayable** because the sampling decision that dropped a sibling branch is not itself recorded as a span. Replay then reconstructs a *different* execution than the one that occurred, and the auditor has no signal that this happened. ## What Was Observed An agent executing a ReAct-style loop over four tool calls emitted a trace where span `gen_ai.chat#3` (the reasoning step that chose between `search` and `fetch`) had a single child `gen_ai.tool_call:fetch`. The decision log for the same run recorded that the model produced *two* candidate tool calls in that step (`search` and `fetch`), the runtime's branch selector picked `fetch` based on a `temperature=0.7` sample, and the `search` branch was executed speculatively and then discarded. The discarded branch emitted its own spans — but the collector's tail-based sampler (sampling policy: keep traces with `error=true`, drop otherwise at 10%) dropped the discarded-branch spans because they carried `gen_ai.tool_call.status=ok` and no error attribute, while the parent trace was retained due to a downstream error in `gen_ai.chat#4`. Result: the retained span tree showed a **linear, unambiguous** execution `chat#3 → fetch → chat#4(error)`. Replaying from this tree against a fixed seed produced a run that *never* considered `search`, because the replay harness had no record that branch selection was probabilistic at that step. The replayed run diverged from the original at `chat#4`: the original's error was caused by `search`'s discarded partial result leaking into a shared scratchpad buffer; the replay, lacking that buffer mutation, completed cleanly. The auditor flagged the original as a defect and the replay as the "correct" behavior — inverting the finding. The invariant that was violated: **every nondeterministic branch point must be recorded as a span attribute on the *retained* parent, not as a sibling span that sampling may drop.** The runtime recorded branch candidates as child spans (droppable) rather than as an attribute on `gen_ai.chat#3` (retained with the parent). ## Condition of Validity Replay from a span tree is valid **only if** all of the following hold: 1. The sampling policy is *deterministic-complete* for the span classes that carry branch decisions — i.e., `gen_ai.chat` and `gen_ai.tool_call` spans are never subject to tail-based dropping, or the sampler is configured with a `force_sample` rule keyed on a `replay.critical=true` attribute. 2. Every branch point records the full candidate set, the selection function, and the RNG seed/state as attributes on the span that *survives* sampling — not as child spans. 3. The replay harness asserts span-tree completeness against the decision log's event count before replaying; a mismatch is a hard abort, not a warning. If any of these is false, the span tree is an *observability artifact*, not an *audit artifact*, and must not be used as the replay substrate. ## Decision Boundary The operative question at replay time is: **does the span tree's branch structure match the decision log's branch structure?** Concretely, for each `gen_ai.chat` span with `n` recorded tool-call children, the decision log must record exactly `n` selected branches and `m` discarded branches, with `n + m` equal to the candidate count at that step. If `m > 0` and the discarded branches have no retained spans, replay is **unsound** — abort. The boundary is not "is the trace complete?" (it never is, under sampling) but "**is the incompleteness recorded as incompleteness?**" A trace that records `replay.dropped_branches=1` on the parent span is replayable-with-caveat; a trace that silently omits the branch is not replayable at all, because the replay engine cannot distinguish "no branch existed" from "branch was dropped." Guardrail: the runtime must emit a `replay.branch_candidates` attribute (JSON array of candidate tool names + selection index + seed) on every `gen_ai.chat` span *before* the branch is taken, so the attribute is committed to the retained span regardless of downstream sampling. ## Operational Effect Without this invariant, audit findings invert: defects caused by discarded-branch side effects are attributed to the retained path, and replays "prove" correctness that never held. The practical remediation is a **replay-soundness gate** in the audit pipeline that cross-checks span-tree branch counts against the decision log and raises on mismatch, plus a sampler configuration that pins `gen_ai.chat` and `gen_ai.tool_call` spans to always-sample. Teams that treat OTel GenAI spans as a free audit substrate discover this boundary only when a tail-sampled trace produces a replay that disagrees with a customer-reported failure — at which point the span tree is the only artifact left, and it is silently lossy. ```python import json from dataclasses import dataclass from typing import Any class ReplayUnsoundError(RuntimeError): """Raised when a span tree is structurally valid but not replayable because nondeterministic branch points were dropped by sampling.""" @dataclass class ChatSpan: span_id: str attributes: dict[str, Any] child_tool_calls: list[str] @dataclass class DecisionLogEntry: span_id: str selected_branches: list[str] discarded_branches: list[str] seed: int def assert_replay_soundness( spans: list[ChatSpan], decision_log: list[DecisionLogEntry], ) -> None: """Verify that every branch point in the decision log is represented on the retained span tree. Abort replay on any mismatch.""" log_by_span = {e.span_id: e for e in decision_log} for span in spans: entry = log_by_span.get(span.span_id) if entry is None: # A chat span with no decision-log entry means the log was # truncated or the span was synthesized — cannot replay. raise ReplayUnsoundError( f"chat span {span.span_id} has no decision-log entry; " f"replay substrate is incomplete" ) expected_total = len(entry.selected_branches) + len(entry.discarded_branches) recorded_candidates = span.attributes.get("replay.branch_candidates") recorded_dropped = span.attributes.get("replay.dropped_branches", 0) if recorded_candidates is None: raise ReplayUnsoundError( f"chat span {span.span_id} missing replay.branch_candidates " f"attribute; branch selection was not committed to a " f"sampling-retained span" ) candidates = json.loads(recorded_candidates) if len(candidates) != expected_total: raise ReplayUnsoundError( f"chat span {span.span_id}: span records {len(candidates)} " f"candidates but decision log records {expected_total}; " f"sampling dropped branch evidence" ) if len(entry.discarded_branches) > 0 and recorded_dropped == 0: raise ReplayUnsoundError( f"chat span {span.span_id}: decision log shows " f"{len(entry.discarded_branches)} discarded branches but span " f"records replay.dropped_branches=0; replay would reconstruct " f"a linear execution that never occurred" ) if len(span.child_tool_calls) != len(entry.selected_branches): raise ReplayUnsoundError( f"chat span {span.span_id}: {len(span.child_tool_calls)} " f"retained tool-call children vs " f"{len(entry.selected_branches)} selected in decision log" ) ```