# What happens when an instance replays a tool span whose prompt span was truncated: observability correlation loss across prompt, completion, and tool spans in agent trace replay **Date of Record:** 2026 November 25 **Scope:** Applies to agent systems that persist distributed traces (prompt span → completion span → tool-call span) and later replay them for debugging, audit, or deterministic re-execution. Does not apply to live inference paths where spans are still resident in the active tracer's memory and have not yet been exported/truncated. ## Core Distinction Observability correlation is not the same thing as *causal* correlation. A trace ID plus span-parent relationships tells you *which* spans belong to the same logical invocation. It does **not** tell you that the recorded prompt span contains enough information to reconstruct the exact input that produced the recorded completion, and therefore the recorded tool-call arguments. The boundary failure lives precisely in the gap between *structural* correlation (span graph intact) and *semantic* correlation (input bytes recoverable). When the two diverge, replay silently produces a plausible but wrong execution, and the trace graph still looks perfectly healthy. The non-obvious invariant is this: **for a tool span to be replayable, the union of (prompt span payload ∪ completion span payload ∪ tool-call arguments) must be a superset of the tokens the model actually conditioned on.** Most exporters satisfy this only when prompt spans are untruncated. The moment a sampling/redaction/truncation policy shortens the prompt span—while leaving the completion and tool spans full—the invariant is broken, but no span-level error is raised. ## What Was Observed A three-span agent trace was captured for a retrieval-augmented tool call: - `prompt` span: attributes `gen_ai.prompt` recorded, but the exporter applied a 4 KiB cap. The original prompt was 11 KiB (system preamble + 6 retrieved chunks + tool schema). - `completion` span: full text of the model's function-call JSON, e.g. `{"tool":"search","args":{"query":"refund policy 2024","filter":"region=EU"}}`. - `tool` span: full request/response of the `search` call, including the returned document IDs. The span graph was intact: same `trace_id`, `prompt.span_id` was the parent of `completion.span_id`, which was the parent of `tool.span_id`. The trace *looked* complete. During incident replay, the operator re-ran the agent using the recorded prompt span as input. The truncation had cut off the last three retrieved chunks—including the chunk that contained the phrase "region=EU does not apply to digital goods." The replayed model, no longer seeing that constraint, emitted `{"tool":"search","args":{"query":"refund policy 2024"}}` with no filter. The tool span replayed against a live sandbox and returned a different result set. The replay diverged from the original at the tool boundary, but the trace viewer showed green spans throughout because each individual span's recorded output matched its recorded input *for the truncated input*. The failure was only detected because the replayed tool response's document IDs did not intersect the recorded tool span's document IDs. Had the query been less specific, the divergence would have been invisible. ## Condition of Validity The correlation invariant holds only under the conjunction: 1. **Payload completeness:** every attribute the model conditioned on is present in the persisted prompt span, byte-for-byte, including tool schemas, retrieved context, and any system preamble injected by middleware. 2. **Deterministic reconstruction:** the prompt-assembly code path is versioned and pinned, so replay re-assembles the same prompt from the same span attributes. If middleware re-injects fresh retrieval at replay time, the recorded prompt span is no longer the input. 3. **Sampling coherence:** if the tracer sampled the prompt span out entirely (head-based sampling dropping the root), the completion and tool spans must not be independently retained—otherwise you have orphaned children with no reconstructable parent. Tail-sampling policies that keep error spans but drop their parents violate this. 4. **Truncation symmetry:** if any span is truncated, the truncation marker must be recorded in a machine-readable attribute (e.g. `gen_ai.prompt.truncated=true`, `original_length=11264`) so replay can *refuse* rather than *guess*. When any of these is false, the trace is structurally valid and semantically unreplayable. The dangerous case is (4): truncation without a marker makes an unreplayable trace indistinguishable from a replayable one. ## Decision Boundary The boundary is not "is the trace complete?" but "**can replay distinguish a faithful reconstruction from a plausible fabrication?**" The decision rule for a replay harness: - If the prompt span carries an explicit `truncated` flag or its recorded length is below the `original_token_count` attribute, **abort replay** with a hard error. Do not fall back to re-retrieval, do not pad, do not "best effort." - If the prompt span is absent but completion and tool spans exist, treat the tool span as **non-replayable evidence**—usable for audit of *what was called*, never for re-execution. - If prompt assembly is not version-pinned against the trace's recorded `agent.version`, replay is advisory only and must be labeled as such in any downstream verdict. The failure mode this prevents is the *false-green replay*: a re-execution that completes, produces a tool response, and is recorded as "reproduced" while having conditioned on different bytes. In multi-agent audit this is worse than no replay, because an auditor agent consuming the replay result will propagate a false confirmation into consensus. ## Operational Effect Downstream, the corrupted replay poisons three things at once: (a) the incident root-cause analysis attributes the divergence to the model rather than to truncation; (b) any auditor agent verifying the original agent's behavior accepts a fabricated reproduction as ground truth; (c) the tool span's recorded response and the replayed response are both "valid" per their local inputs, so no span-level validator fires. The fix is to make the invariant explicit and enforced at the replay entry point—truncation must be a first-class, propagated attribute, and replay must be allowed to fail closed. The guardrail is cheap; the cost of its absence is a trace corpus that looks complete and is silently unreplayable, which is the worst possible state for an audit system that trusts its own observability. ```python from dataclasses import dataclass from typing import Optional class ReplayCorrelationError(RuntimeError): """Raised when a trace's span set cannot faithfully reconstruct the model input.""" pass @dataclass class SpanRecord: span_id: str parent_id: Optional[str] kind: str # "prompt" | "completion" | "tool" payload: str recorded_length: Optional[int] = None original_length: Optional[int] = None truncated: bool = False def assert_replayable(prompt: Optional[SpanRecord], completion: Optional[SpanRecord], tool: Optional[SpanRecord], agent_version_pinned: bool) -> None: if prompt is None: raise ReplayCorrelationError( "no prompt span retained; completion/tool spans are audit-only, not replayable" ) if prompt.truncated or ( prompt.original_length is not None and prompt.recorded_length is not None and prompt.recorded_length < prompt.original_length ): raise ReplayCorrelationError( f"prompt span {prompt.span_id} truncated " f"({prompt.recorded_length}/{prompt.original_length} bytes); " "refusing replay rather than fabricating a superset input" ) if completion is None or tool is None: raise ReplayCorrelationError( "incomplete span chain; cannot validate causal correlation" ) if completion.parent_id != prompt.span_id or tool.parent_id != completion.span_id: raise ReplayCorrelationError( "span parent graph broken; structural correlation does not imply semantic correlation" ) if not agent_version_pinned: raise ReplayCorrelationError( "agent version not pinned to trace; prompt reassembly is advisory only" ) ```