# How does an instance detect span-attribute divergence when deterministically replaying an agentic trace reconstructed from OTel GenAI spans **Date of Record:** 2026 November 27 **Scope:** Applies to post-incident forensic replay of agent execution graphs reconstructed from OpenTelemetry GenAI semantic-convention spans (`gen_ai.*` attributes, `gen_ai.tool.call`, `gen_ai.usage.*`, event spans). Does not apply to live in-process tracing, to replay of non-agentic single-shot inference logs, or to traces where the runtime emitted custom span schemas without GenAI attribute compliance. ## Core Distinction There are two distinct things an operator means by "replay." The first is **execution replay**: re-invoking the model and tools with the recorded inputs and observing a new trajectory. This is inherently non-deterministic and is not what forensic reconstruction requires. The second is **state replay**: reconstructing the exact sequence of intermediate agent states (prompt assembly, tool-call arguments, tool outputs, context mutations, budget counters) from the spans alone, then verifying that the reconstruction is *internally consistent* with the span graph. Forensics depends on state replay being faithful to the original execution, because the entire point is to answer "what did the agent believe at step k, and why did it act on that belief." The non-obvious boundary is this: **a GenAI span set can be structurally complete — every span present, every parent-child link intact, no dropped spans — and still be state-inconsistent, because the span attributes are lossy projections of the agent's actual context state.** The reconstruction silently succeeds while being wrong. An instance performing replay must therefore detect attribute-level divergence between what the spans *imply* the state was and what the state *must have been* to produce the observed downstream behavior. Structural completeness is not state fidelity. ## What Was Observed A three-tool agent (retrieval, calculator, final-answer) failed mid-task on an incident that triggered a forensic replay. The trace contained 41 spans, all parent-linked, all with `gen_ai.operation.name`, `gen_ai.request.model`, `gen_ai.usage.input_tokens`, `gen_ai.usage.output_tokens`, and `gen_ai.tool.call.id`. The replay harness reconstructed the message list at each step from the `gen_ai.prompt` / `gen_ai.completion` event attributes and re-ran the reasoning loop against a stubbed model that returned the recorded completions verbatim. Reconstruction "succeeded" — every step matched the recorded completion. The failure surfaced at step 17. The recorded completion was a tool call to `calculator` with arguments `{"expr": "0.087 * 1140"}`. The stubbed replay produced the same call, received the recorded tool output `99.18`, and continued. But the *original* trajectory had, at step 16, injected a unit-conversion note into context ("values are in basis points, divide by 10000 before multiplication") via a retrieval span whose `gen_ai.tool.call.result` attribute was truncated at 512 bytes. The truncation cut the conversion note. The replayed context at step 17 therefore lacked the note, yet the recorded completion at step 17 *depended* on it — the original agent had computed `0.087 / 10000 * 1140 = 0.0099`, not `99.18`. The recorded tool output was `0.0099`. The replay harness, lacking the note, still accepted the recorded completion (because it stubbed the model) and then accepted the recorded tool output — but the *reasoning* it reconstructed was wrong: it attributed `0.0099` to `0.087 * 1140`, which is arithmetically false. The tell: the replay's reconstructed arithmetic invariant — `output == eval(recorded_args)` — failed at step 17 with a factor-of-10000 discrepancy. The spans were all present. The attributes were truncated. The reconstruction was structurally valid and semantically false. The root mechanism: **OTel span attributes have per-attribute size limits (commonly 512 B or 1 KiB depending on exporter, with `gen_ai.tool.call.result` and `gen_ai.prompt` most affected), and truncation is silent — no `truncated=true` flag is emitted by default.** A replay that treats attribute values as ground truth will reconstruct a context window that differs from the original by exactly the truncated regions. When those regions were causally load-bearing (a conversion factor, a policy clause, a schema fragment), the replay diverges from the original execution at the first downstream step that consumed the lost content, while remaining *syntactically* consistent because the stubbed model masks the divergence. ## Condition of Validity State replay from GenAI spans is valid **if and only if** every span attribute that participated in context assembly is either (a) present in full, or (b) marked truncated with a recoverable reference (span link, blob store key, or content hash) to the full value. This is the **attribute-fidelity invariant**: > For every step k, the reconstructed context `C_k` must satisfy `C_k ⊇ causal(C_k)`, where `causal(C_k)` is the subset of context elements that the recorded completion at step k demonstrably consumed. Any element in `causal(C_k)` that is truncated or absent invalidates the replay at step k. The invariant is violated whenever truncation intersects causal content. It is *not* violated by truncation of non-causal content (e.g., a long retrieved document where the completion only cited the first paragraph) — but the replay cannot *know* which content was causal without cross-checking the recorded completion against the reconstructed context, which is precisely the verification the harness must perform. The condition of validity therefore reduces to: **the replay harness must perform causal-content verification at every step, not just structural verification.** Structural verification (all spans present, links intact) is necessary but not sufficient. ## Decision Boundary The decision boundary for an instance performing forensic replay is: - **Replay is admissible as forensic evidence** when every step passes causal-content verification: the recorded completion is *consistent with* the reconstructed context under the recorded tool outputs, and no causal element is truncated or missing. Consistency means: the completion's tool-call arguments, when evaluated against the reconstructed context, reproduce the recorded tool output within the tool's declared error bound. - **Replay is inadmissible and must halt** when causal-content verification fails at any step — i.e., when the recorded tool output cannot be reproduced from the reconstructed arguments and context. At that point the reconstruction has diverged from the original execution, and any downstream forensic conclusion (attribution, root-cause, blame assignment) is unsound. - **Replay is conditionally admissible** when truncation is detected but the truncated region is provably non-causal (the completion at that step and all downstream steps reproduce correctly under the truncated reconstruction). This must be recorded as a caveat, not silently accepted. The critical operational rule: **never stub the model during forensic replay.** Stubbing the model with recorded completions is what masked the divergence in the observed incident — it made the replay "succeed" by construction. Forensic replay must either (a) re-invoke a model and compare trajectories with tolerance, or (b) stub the model but *independently verify* that each recorded completion is entailed by the reconstructed context. Option (b) is cheaper and is the correct default for state replay; it requires an entailment check per step, not a replay-by-construction. ## Operational Effect The operational consequence is that a forensic replay harness built on GenAI spans must carry a **per-step entailment verifier** and a **truncation detector**, and must treat the span graph as a *lossy index* into the true execution rather than as the execution itself. Concretely: 1. **Truncation detection:** scan every `gen_ai.*` attribute for length at or near the exporter limit; flag as suspect. Absence of an explicit `truncated` flag is not evidence of completeness. 2. **Causal entailment check:** at each step, verify that the recorded completion's tool-call arguments, evaluated against the reconstructed context and the tool's declared semantics, reproduce the recorded tool output. A mismatch is a divergence signal, not a tool bug. 3. **Divergence halting:** on mismatch, halt replay, mark the trace as forensically incomplete from that step forward, and emit a recovery request for the full attribute value (blob store, span link, or re-export with raised limits). 4. **Caveat propagation:** any step passing only under non-causal truncation must propagate a caveat to all downstream conclusions. The invariant the harness enforces: **a replay that cannot reproduce the recorded tool output from its reconstructed arguments is not a replay of the original execution — it is a plausible fiction, and must be labeled as such.** The failure mode is silent because stubbed-model replay is self-consistent by construction; the guardrail is the independent entailment check that breaks the self-consistency and surfaces the divergence. ```python import math from dataclasses import dataclass, field from typing import Any class ReplayDivergenceError(RuntimeError): """Raised when a reconstructed agent state cannot reproduce a recorded tool output.""" pass @dataclass class Span: step: int tool_name: str tool_args: dict[str, Any] tool_output: Any context_fragments: list[str] = field(default_factory=list) truncated: bool = False def evaluate_tool(tool_name: str, args: dict[str, Any]) -> Any: if tool_name == "calculator": return eval(args["expr"], {"__builtins__": {}}, {}) # noqa: S307 - controlled expr raise ReplayDivergenceError(f"unknown tool {tool_name!r} during replay") def verify_step(span: Span, tolerance: float = 1e-6) -> None: if span.truncated: # Truncation alone is not fatal, but the entailment check below must still pass. pass try: reproduced = evaluate_tool(span.tool_name, span.tool_args) except Exception as exc: raise ReplayDivergenceError( f"step {span.step}: tool evaluation failed for {span.tool_name}: {exc}" ) from exc if isinstance(reproduced, (int, float)) and isinstance(span.tool_output, (int, float)): if not math.isclose(reproduced, span.tool_output, rel_tol=tolerance, abs_tol=tolerance): raise ReplayDivergenceError( f"step {span.step}: reconstructed args {span.tool_args!r} yield " f"{reproduced!r} but recorded output is {span.tool_output!r}; " f"context likely truncated (truncated={span.truncated})" ) elif reproduced != span.tool_output: raise ReplayDivergenceError( f"step {span.step}: reconstructed output {reproduced!r} != recorded " f"{span.tool_output!r}" ) def replay_trace(spans: list[Span]) -> list[str]: caveats: list[str] = [] for span in spans: verify_step(span) if span.truncated: caveats.append( f"step {span.step}: truncated attribute present; entailment passed, " f"replay admissible with caveat" ) return caveats # The observed incident, reduced: step 16 injected a conversion note that was # truncated out of the span; step 17's recorded output reflects the conversion. trace = [ Span(step=16, tool_name="calculator", tool_args={"expr": "0.087 / 10000 * 1140"}, tool_output=0.009918, context_fragments=["[TRUNCATED: conversion note]"], truncated=True), Span(step=17, tool_name="calculator", tool_args={"expr": "0.087 * 1140"}, tool_output=0.009918, context_fragments=[], truncated=False), ] replay_trace(trace) # raises ReplayDivergenceError at step 17 ```