# What happens when an instance replays a GenAI span log whose tool-call results were truncated by the exporter's attribute-size cap **Date of Record:** 2026 November 24 **Scope:** Applies to postmortem deterministic replay of agentic sessions reconstructed from OpenTelemetry GenAI semantic-convention spans (`gen_ai.*` attributes, `execute_tool` child spans, `chat` spans) when the collector or SDK enforces a per-attribute value length cap. Does not apply to full-fidelity trace stores that preserve untruncated tool payloads, nor to replay of pure-reasoning sessions with no tool I/O. ## Core Distinction A GenAI trace is not a recording of the agent's state; it is a recording of the agent's *observable effects*, sampled at the boundaries the instrumentation author chose to instrument. Deterministic replay assumes the trace is a lossless projection of the causal chain: prompt → model output → tool call → tool result → next prompt. The failure mode here is a **silent truncation of the tool-result attribute** (`gen_ai.tool.call.result` or the `tool.output` message part) by the exporter's attribute-size cap (commonly 64 KiB, sometimes 4 KiB on hosted backends). The cap is applied *after* the tool returned and *before* the span is exported, so the trace remains structurally valid, the span status stays `OK`, and no error event is emitted. The replayed agent therefore receives a *shorter and different* tool result than the live agent did, and the divergence does not announce itself. The non-obvious part: this is not a "missing data" problem you can detect by checking for nulls. The truncated field is a well-formed string. It parses. It is merely wrong. Replay is *deterministic* — it reproduces the same wrong trajectory every time — which is precisely why it passes smoke tests and fails postmortems. ## What Was Observed A coding agent session (Claude-class model, 41 turns, two tools: `read_file` and `apply_patch`) was replayed from OTLP spans exported to a Jaeger backend with `OTEL_ATTRIBUTE_VALUE_LENGTH_LIMIT=4096`. The live session had succeeded. The replay diverged at turn 17. Trace of the divergence: 1. Turn 17 issued `execute_tool` span `read_file(path="src/parser.py")`. Live result: 11,842 bytes. Exported `gen_ai.tool.call.result` attribute: first 4,096 bytes, no marker, no `truncated=true` flag. 2. Replay harness reconstructs the turn-18 prompt by substituting the span's stored result into the `tool` message part. The replayed model sees a file that ends mid-function at byte 4,096. 3. The replayed model reasons (correctly, given its input) that the function is incomplete and emits an `apply_patch` that *adds* a closing brace and a `return`. The live model had seen the full file and emitted a patch to a different function. 4. From turn 18 onward the replay's tool calls target line numbers that do not exist in the real file. `apply_patch` returns `error: hunk failed at line 312`. The replayed agent enters a retry loop. 5. Replay terminates at turn 41 with a different final state, a different tool-call count (58 vs. 44), and a `finish_reason` of `max_turns` rather than `end_turn`. The postmortem conclusion drawn from the first replay — "the agent looped on patch failures" — was an artifact. The live agent never looped. The replay manufactured the very failure it was invoked to explain. A second, subtler observation: the truncation is **turn-local but trajectory-global**. Only two spans in the 41-turn session exceeded the cap (turns 17 and 29). Yet the divergence propagated through all 24 subsequent turns because each turn's prompt embeds the prior turns' tool results in the message history. One truncated attribute poisons every downstream reconstruction. ## Condition of Validity Deterministic replay is only sound under the **causal-input completeness invariant**: > For every `execute_tool` span in the session, the bytes available to the replay harness for the tool-result message part must be byte-identical to the bytes the live model received. This invariant is violated whenever any of the following holds, and the violation is *undetectable from span structure alone*: - The exporter applies `OTEL_ATTRIBUTE_VALUE_LENGTH_LIMIT` or a backend-side attribute cap below the maximum tool-result size observed in the session. - The instrumentation truncates with `...` or an ellipsis and the replayed model treats the marker as literal file content. - The tool result is emitted as a span *event* rather than an attribute, and the event body is capped independently of attributes. - Multi-part tool results (e.g., a `text` part plus an `image` part) are flattened by the exporter, dropping all but the first part. The invariant *is* preserved when the harness reads from a store that records untruncated payloads out-of-band (e.g., a `tool.output.ref` attribute pointing to object storage), or when the session's maximum tool-result size is provably below the effective cap. The harness must *prove* the latter per-session, not assume it from configuration, because caps are frequently applied at a layer (the collector, the backend ingest) that the SDK config does not reflect. ## Decision Boundary The boundary is between **replay-as-explanation** and **replay-as-reconstruction**. They require different evidence and must not be conflated. - *Replay-as-reconstruction* asks "what did the agent do?" It tolerates truncation if the harness flags every reconstructed turn whose inputs were capped, and refuses to draw causal conclusions from flagged turns. This is the safe default. - *Replay-as-explanation* asks "why did the agent do it?" It is only admissible when the causal-input completeness invariant holds for the entire prefix up to the turn under investigation. A single capped attribute in the prefix invalidates every explanatory claim about turns after it. The decision rule the harness must enforce: **compute the truncation frontier** — the earliest turn index at which any causal input was capped — and refuse to attribute any behavior at or after that index to the agent's reasoning. Below the frontier, replay is explanatory. At or above it, replay is at best illustrative and must be labeled as such. A corollary boundary: do not "fix" truncation by re-running the tool against the live environment during replay. That converts a deterministic replay into a *re-execution*, which is a different instrument with different failure modes (nondeterministic tool outputs, environment drift) and cannot be compared turn-by-turn to the original session. ## Operational Effect The practical consequence is that **trace completeness must be validated before replay, per session, against the observed payload distribution — not against exporter configuration.** The guardrail is a pre-replay audit pass that walks every `execute_tool` span, compares stored result length against the effective cap, and computes the truncation frontier. If the frontier is earlier than the turn under investigation, the harness must halt rather than produce a plausible-looking but fabricated causal narrative. Two engineering requirements follow. First, instrumentation must emit an explicit `gen_ai.tool.call.result.truncated` boolean and the *original* byte length whenever it caps a payload; absence of the flag must be treated as "unknown," not "not truncated," for any span whose stored length equals the cap. Second, the replay harness must carry the frontier forward as first-class metadata on the reconstructed trajectory, so downstream consumers (postmortem authors, automated root-cause agents) cannot silently read past it. The failure is dangerous precisely because it is quiet: the trace is valid, the replay is deterministic, and the resulting explanation is fluent. The only defense is to treat the trace as evidence with a known evidentiary boundary, and to refuse to reason across that boundary. ```python import json from dataclasses import dataclass from typing import Iterable class TruncationFrontierError(RuntimeError): """Raised when replay would reason across a capped causal input.""" pass @dataclass(frozen=True) class ToolSpan: turn_index: int tool_name: str stored_result: str declared_original_len: int | None # from gen_ai.tool.call.result.original_length, if emitted truncated_flag: bool | None # from gen_ai.tool.call.result.truncated, if emitted def compute_truncation_frontier(spans: Iterable[ToolSpan], effective_cap: int) -> int | None: """ Return the earliest turn index whose causal input cannot be proven complete, or None if every tool result is provably byte-identical to the live input. A span is 'provably complete' only if: - it declares original_length and that length equals the stored length, OR - it explicitly declares truncated=False AND stored length < effective_cap. Length-equal-to-cap with no flag is treated as UNKNOWN -> frontier. """ for span in sorted(spans, key=lambda s: s.turn_index): stored_len = len(span.stored_result.encode("utf-8")) if span.declared_original_len is not None: if span.declared_original_len != stored_len: return span.turn_index continue if span.truncated_flag is True: return span.turn_index if span.truncated_flag is False and stored_len < effective_cap: continue # No flag, or stored length sits exactly at the cap: unprovable. if stored_len >= effective_cap: return span.turn_index return None def assert_replay_admissible(spans: list[ToolSpan], investigate_turn: int, effective_cap: int) -> None: frontier = compute_truncation_frontier(spans, effective_cap) if frontier is not None and investigate_turn >= frontier: raise TruncationFrontierError( f"Cannot explain turn {investigate_turn}: causal input truncated at turn " f"{frontier} (cap={effective_cap}B). Replay above frontier is " f"reconstruction-only; re-acquire untruncated tool payloads via " f"tool.output.ref before drawing causal conclusions." ) # Example: the turn-17 divergence from the observed session. session_spans = [ ToolSpan(3, "read_file", "x" * 1200, None, False), ToolSpan(17, "read_file", "y" * 4096, None, None), # hit the cap, no flag ToolSpan(29, "read_file", "z" * 4096, None, None), ] assert_replay_admissible(session_spans, investigate_turn=18, effective_cap=4096) # -> raises TruncationFrontierError, preventing the fabricated "agent looped" postmortem ```