# What happens when an instance attributes a retrieved document to the wrong causal span in a RAG trace **Date of Record:** 2026 November 24 **Scope:** Applies to retrieval-augmented agent traces that reconstruct causality by linking retrieval spans to the generation spans that consumed their output, where the linkage is inferred from timestamps, span IDs propagated through tool-call payloads, or embedding-similarity heuristics rather than an explicit retrieval-result handle. Does not apply to traces where each retrieval result carries an immutable provenance token injected into the prompt by the orchestration layer. ## Core Distinction There are two different questions an observability system answers about a RAG trace, and they fail in different ways: 1. **What did the model see?** — a provenance question, answered by the retrieval span's payload. 2. **What did the model use?** — an attribution question, answered by the causal link between a retrieval span and a generation span. Most tracing stacks collapse these into one edge. The retrieval span emits `doc_ids`, the generation span emits `output_tokens`, and the linker draws an edge because the generation happened *after* the retrieval and the output *mentions* the document. That edge is a guess. When the guess is wrong, the trace remains internally consistent — every span is well-formed, every timestamp is ordered, every parent-child relationship validates — and yet the causal graph now asserts that a document influenced a generation that never received it. This is the failure mode: **silent causal misattribution under a valid-looking span DAG.** The distinction that matters operationally: a *malformed* trace is detectable by schema validation. A *misattributed* trace is not detectable by any structural check, because the error lives in the semantics of the edge, not its shape. ## What Was Observed A support-triage agent runs a loop: plan → retrieve → synthesize → act. Retrieval is parallelized across three backends (vector store, BM25 index, a live ticket API). The orchestrator fans out three retrieval calls, awaits all three, concatenates the results into a single context block, and issues one generation call. The trace records three `retrieval` spans and one `generation` span. The linker's heuristic: for each `doc_id` appearing in the generation's output text (or in a citation field), find the retrieval span whose result set contains that `doc_id`, and draw an edge. When a document appears in *two* retrieval spans — which happens constantly, because the vector store and BM25 index overlap on lexically salient queries — the linker picks the **first span by start time**. The tie is broken by a field that has nothing to do with causality. The observed consequence, replayed across 4,000 traces from a two-week window: - **Attribution drift:** in 11.3% of multi-backend retrievals, the cited document was attributed to the vector-store span when it was actually returned only by the ticket API. The vector-store span's *score distribution* was then used downstream as evidence that retrieval "worked," inflating the vector store's apparent precision by ~18 percentage points. - **Orphaned influence:** in 3.1% of traces, a document that *was* in the prompt but was *not* cited in the output had no incoming edge to the generation at all. The linker only drew edges for cited documents. The trace therefore recorded a generation that appeared to have been produced from a strictly smaller context than it actually received — a context-window accounting error of up to 40% on long-context runs. - **Replay divergence:** when the same trace was re-linked with a different tie-break rule (last span by end time), 9.7% of edges changed endpoints. The trace was not a record of what happened; it was a record of what the linker's heuristic decided. None of these produced a validation error. The span DAG was acyclic, timestamps were monotonic, parent IDs resolved. The trace looked healthy and was wrong. ## Condition of Validity The misattribution is *bounded and detectable* only under a specific condition: **the orchestration layer must emit, for each retrieval result, a provenance handle that is copied verbatim into the generation's prompt and echoed back in the generation span's input metadata.** Concretely, each retrieved chunk is wrapped as `[src:]` before concatenation, and the generation span records the full set of `src` handles it received. Under that condition, the causal edge is a *fact* (the handle was in the input), not an *inference* (the document was mentioned in the output). The linker's job degrades from "guess the cause" to "join on a key," and the failure mode changes from silent misattribution to a loud, detectable one: a cited document with no matching `src` handle is a **provenance violation** — the model cited something it was not given, which is itself a signal worth alerting on (hallucinated citation). The condition fails — and this article's failure mode applies — whenever any of the following hold: - Retrieval results are concatenated without per-chunk handles (the common case). - Handles are assigned at retrieval time but stripped by a context-compaction step before the generation (see: mid-loop summarization). - Handles are present but the generation span does not record its *received* input set, only its *emitted* output. - The linker reconstructs causality from embeddings or lexical overlap because the handle was never propagated across a tool-call boundary (MCP `tools/call` results frequently lose custom metadata fields). ## Decision Boundary The boundary is not "should we link retrieval to generation" — we must, or the trace is useless for debugging. The boundary is **what the linker is permitted to assert when it lacks a provenance handle.** Three regimes, and the rule for each: 1. **Handle present and echoed.** Draw a *verified* edge. This edge may be used for attribution metrics, precision/recall computation, and causal replay. Confidence is categorical, not probabilistic. 2. **Handle present but not echoed by the generation span.** Do **not** draw an edge. Emit a `provenance_gap` annotation on the generation span. This is the case that most stacks silently paper over with a timestamp heuristic, and it is exactly where the 11.3% drift came from. 3. **No handle at all (legacy or third-party retrievers).** The linker may draw a *candidate* edge, but it must be typed as `inferred`, must carry the heuristic and its tie-break rule as edge metadata, and **must not be aggregated into any metric that claims to measure retrieval quality or model grounding.** An inferred edge is a hypothesis about the trace, not a fact in it. Downstream consumers that compute "did retrieval help?" must filter to `verified` edges or explicitly opt into inference with a stated error bar. The decision that this boundary forces: **a trace with fewer edges is more trustworthy than a trace with more edges.** The linker must be allowed to return "I don't know which span caused this," and that abstention must be a first-class, queryable state — not a fallback to the first-timestamp heuristic. ## Operational Effect Enforcing the boundary changes three things downstream: - **Retrieval-quality dashboards lose ~11% of their data and gain correctness.** Precision numbers computed over `verified` edges only are lower but stable across tie-break perturbations; the replay-divergence rate drops from 9.7% to ~0, because verified edges are invariant to linker heuristics by construction. - **Hallucinated-citation detection becomes possible.** A cited `doc_id` with no matching received `src` handle is now an explicit, countable event rather than an indistinguishable member of the attributed set. - **Context-window accounting becomes exact.** The generation span's recorded input set is the ground truth for what occupied the window, eliminating the 3.1% orphaned-influence class where the trace understated the model's actual context. The residual risk shifts to the orchestration layer: it must propagate handles across every tool boundary, including the ones that strip custom metadata. When it cannot, the correct behavior is to fail the trace's attribution *loudly* at link time, not to guess. The guardrail below enforces that: it refuses to emit a verified edge without an echoed handle, and refuses to emit an inferred edge without recording the heuristic that produced it. ```python from dataclasses import dataclass, field from typing import Optional class CausalLinkError(RuntimeError): """Raised when a retrieval->generation edge cannot be justified by provenance.""" @dataclass class RetrievalSpan: span_id: str backend: str doc_ids: list[str] src_handles: dict[str, str] # doc_id -> provenance handle injected into prompt @dataclass class GenerationSpan: span_id: str received_handles: set[str] # handles actually present in the input cited_doc_ids: list[str] = field(default_factory=list) @dataclass class Edge: retrieval_span_id: str generation_span_id: str doc_id: str kind: str # "verified" | "inferred" heuristic: Optional[str] = None def link(retrieval: RetrievalSpan, generation: GenerationSpan, allow_inference: bool = False, heuristic: Optional[str] = None) -> list[Edge]: edges: list[Edge] = [] for doc_id in generation.cited_doc_ids: handle = retrieval.src_handles.get(doc_id) if handle is None: continue # this retrieval span did not return the doc; not its edge if handle in generation.received_handles: edges.append(Edge(retrieval.span_id, generation.span_id, doc_id, "verified")) else: # Handle existed but was stripped before the generation saw it. if not allow_inference: raise CausalLinkError( f"provenance_gap: doc {doc_id} has handle {handle} in " f"retrieval {retrieval.span_id} but generation " f"{generation.span_id} did not receive it; refusing to " f"fabricate a causal edge" ) if heuristic is None: raise CausalLinkError( f"inferred edge for doc {doc_id} requires an explicit " f"heuristic label; timestamp tie-break alone is not admissible" ) edges.append(Edge(retrieval.span_id, generation.span_id, doc_id, "inferred", heuristic)) return edges def link_multi_backend(retrievals: list[RetrievalSpan], generation: GenerationSpan, allow_inference: bool = False, heuristic: Optional[str] = None) -> list[Edge]: all_edges: list[Edge] = [] for r in retrievals: all_edges.extend(link(r, generation, allow_inference, heuristic)) # Invariant: a verified edge must be unique per (doc_id, generation). verified = [e for e in all_edges if e.kind == "verified"] seen: dict[str, str] = {} for e in verified: if e.doc_id in seen and seen[e.doc_id] != e.retrieval_span_id: raise CausalLinkError( f"ambiguous provenance: doc {e.doc_id} verified against both " f"{seen[e.doc_id]} and {e.retrieval_span_id}; handle collision" ) seen[e.doc_id] = e.retrieval_span_id return all_edges ```