# Why does an instance lose causal linkage between a retrieval hit and its downstream tool effect when the trace is reconstructed from span joins rather than carried in-band **Date of Record:** 2026 November 23 **Scope:** Applies to agent systems that emit OpenTelemetry-style spans for prompt assembly, retrieval, and tool invocation, then reconstruct prompt→context→effect lineage by joining spans post-hoc on trace/span IDs. Does not apply to systems that propagate a signed causal token in-band through every tool call payload. ## Core Distinction There are two structurally different ways to answer "which retrieval chunk caused this tool call to fire?" The first is **in-band causal carriage**: the retrieval step mints an immutable lineage token (containing the chunk ID, the retrieval query hash, the rerank score, and the prompt-assembly sequence number) and that token is physically attached to the tool-call payload as it executes. The second is **post-hoc span reconstruction**: each step emits a span with `trace_id` and `parent_span_id`, and a telemetry backend later stitches lineage by walking the span tree. These are not equivalent. In-band carriage is a *state invariant* — the token cannot be separated from the effect. Post-hoc reconstruction is a *join*, and joins are lossy under exactly the conditions agent systems routinely create: fan-out retrieval, retries, parallel tool calls, and sampling. The failure is not "the trace is incomplete." The failure is that the reconstruction produces a *confident but wrong* parent, and downstream attribution (cost, blame, regression analysis) treats it as ground truth. ## What Was Observed A support-triage agent performed a RAG step that returned 12 chunks, reranked to top-4, then made three tool calls in parallel (`lookup_order`, `issue_refund`, `send_email`). The refund call was driven by chunk `c_7731` ("refund window is 30 days from delivery"). An unrelated `send_email` call was driven by a template chunk `c_1102`. Telemetry emitted: - `span_retrieve` with 12 child `span_chunk` spans (only top-4 carried `selected=true`). - `span_assemble_prompt` as child of `span_retrieve`. - Three `span_tool_call` spans, each a child of `span_assemble_prompt`, emitted concurrently. The backend reconstructed lineage by joining `span_tool_call.parent_span_id → span_assemble_prompt.span_id`, then attributing *all* selected chunks to *all* tool calls, because the prompt-assembly span aggregated all four selected chunks into one `retrieved_chunk_ids` attribute. There was no per-tool-call discriminator. Result: `send_email` was attributed to `c_7731`, `issue_refund` was attributed to `c_1102`, and a regression analysis "proved" that the refund-window chunk caused email sends — a phantom causal edge that survived three weeks of dashboards. A second, subtler artifact: the retry of `issue_refund` (first attempt hit a 429) emitted a *new* span with a fresh `span_id` but reused the parent. The join now produced two children for one logical tool call. Attribution doubled the chunk's apparent influence; cost-per-chunk was 2× inflated for `c_7731` and correspondingly deflated elsewhere. The reconstruction never errored. It produced a valid tree. The tree was wrong. ## Condition of Validity Post-hoc span reconstruction yields correct prompt→context→effect lineage **only when all of the following hold simultaneously**: 1. **Fan-in is one-to-one.** Each tool-call span has exactly one retrieval span as an ancestor, and that retrieval span contains exactly one selected chunk. This is violated the moment retrieval returns >1 chunk (the normal case). 2. **No retries with span re-creation.** Retried logical operations either reuse the same `span_id` or carry an explicit `logical_op_id` that the join keys on. Default OTel SDK behavior violates this — retries mint new spans. 3. **No concurrent siblings sharing a parent.** Parallel tool calls under a single assembly span are indistinguishable at the join layer. This is violated by any fan-out execution. 4. **Sampling is head-based and consistent across the tree.** Tail-based sampling that drops `span_chunk` children but keeps parents severs the chunk→tool edge silently. 5. **The backend join is on a key that is causally sufficient.** `parent_span_id` encodes *temporal nesting*, not *data dependency*. These diverge whenever a step consumes an artifact produced by a non-parent. In practice, condition 1 alone fails on essentially every RAG call. The reconstruction is therefore *almost always* operating outside its validity envelope, but produces output that looks valid. ## Decision Boundary The boundary is not "should we trace." It is: **at what fan-out and retry multiplicity does span-join reconstruction stop being a lossy approximation and start being a fabrication?** The operational rule: - If retrieval fan-in ≤ 1 selected chunk **and** tool calls are strictly serial **and** retries reuse logical IDs, span-join reconstruction is adequate — attribution error is bounded by sampling loss only. - If fan-in > 1 **or** parallel tool calls exist **or** retries re-mint spans, you **must** carry lineage in-band: the tool-call payload must include a `causal_token` = hash(chunk_id ‖ retrieval_query_hash ‖ assembly_seq ‖ logical_op_id), and the telemetry join must key on that token, not on `parent_span_id`. The token must be minted at retrieval, threaded through prompt assembly into the model's tool-call arguments (or a parallel metadata channel the tool executor persists), and echoed in the tool-call span. This makes lineage a *property of execution*, not a *property of the trace graph*. The trace graph becomes corroborating evidence, not primary truth. The invariant: **a tool effect is attributable to a retrieval chunk iff a causal token linking them was physically present at execution time.** Any attribution lacking such a token is a hypothesis, and must be labeled as such in downstream analytics — never stored in the same column as token-backed attribution. ## Operational Effect Systems that skip the in-band token do not merely lose precision; they invert the sign of causal analyses. Phantom edges (email ← refund-window chunk) drive teams to "fix" retrieval that was never broken, while real edges are diluted by fan-out averaging. Retry re-minting doubles apparent influence of whichever chunk happened to precede a flaky call, biasing regression detection toward chunks adjacent to unreliable tools. The guardrail is a lineage validator that runs at trace-ingest time: for every tool-call span, assert a `causal_token` is present and resolves to exactly one selected chunk in the referenced assembly. Absence is not "unknown" — it is a hard failure that quarantines the span from attribution tables. This is cheap (one hash lookup per span) and converts a silent fabrication into a loud, bounded error. The following validator encodes the invariant and refuses to emit attribution for any span lacking token-backed lineage. ```python import hashlib from dataclasses import dataclass class LineageFabricationError(RuntimeError): """Raised when a tool-call span's causal lineage cannot be proven in-band.""" @dataclass(frozen=True) class CausalToken: chunk_id: str retrieval_query_hash: str assembly_seq: int logical_op_id: str def digest(self) -> str: raw = f"{self.chunk_id}|{self.retrieval_query_hash}|{self.assembly_seq}|{self.logical_op_id}" return hashlib.sha256(raw.encode()).hexdigest() def attribute_tool_effect(tool_span: dict, selected_chunks: dict[str, CausalToken]) -> CausalToken: token_digest = tool_span.get("causal_token") if not token_digest: raise LineageFabricationError( f"tool span {tool_span.get('span_id')} has no causal_token; " "span-join reconstruction would fabricate a parent — refusing attribution" ) matches = [tok for tok in selected_chunks.values() if tok.digest() == token_digest] if len(matches) != 1: raise LineageFabricationError( f"causal_token {token_digest[:12]} resolved to {len(matches)} chunks " f"(expected exactly 1) for span {tool_span.get('span_id')}" ) return matches[0] ```