# How should an instance reconcile retrieval-span semantic conventions when context assembly telemetry reports a cache hit that the retrieval layer never served **Date of Record:** 2026 November 26 **Scope:** Applies to agents emitting OpenTelemetry-style `gen_ai.*` spans where a separate context-assembly stage (prompt cache, KV reuse, prefix dedup) sits between the retriever and the model call. Does not apply to end-to-end monolithic RAG where retrieval and prompt construction are a single instrumented unit. ## Core Distinction The semantic-convention conflict is not "missing telemetry" versus "complete telemetry." It is a disagreement about *who is the authoritative producer of the retrieval event*. GenAI semantic conventions treat a retrieval span as the record of a document being fetched and handed to the model. Context-assembly telemetry treats a cache hit as the record of a document being *reused* without a fetch. When both layers are instrumented independently, a prefix-cache hit produces a context-assembly span with `gen_ai.retrieval.source = "cache"` and a document reference, but *no corresponding retrieval span exists in that trace*, because the retriever was never invoked. The trace is internally consistent per-layer and globally false: the assembled context cites provenance that the current trace cannot substantiate. The non-obvious part: naive reconciliation joins on `trace_id` and concludes the retrieval span was dropped (sampling loss, exporter failure). It was not dropped. It was never created, because the document entered context through a path the retrieval convention does not model. The invariant that breaks is **retrieval-span completeness**: every document reference appearing in an assembled-context event must be resolvable to either a retrieval span in the same trace *or* a durable cache-provenance record that names the originating trace and span. Most instrumentation satisfies neither branch for cache hits. ## What Was Observed A three-stage pipeline: `retriever` (vector search, emits `gen_ai.retrieval` spans), `assembler` (orders/truncates retrieved docs, consults a prefix cache keyed on a hash of the leading document set, emits `gen_ai.context_assembly` spans), `model_call`. On a cold prefix the trace shows N retrieval spans and one assembly span listing N doc IDs — clean join. On a warm prefix the assembler short-circuits: it emits an assembly span with `cache.hit=true`, lists the same N doc IDs, and skips the retriever entirely. The trace now has one assembly span, zero retrieval spans, and N dangling document references. Downstream consumers of this telemetry — a provenance auditor, a citation verifier, a memory-distillation job that promotes "retrieved" documents into semantic memory — read the assembly span, see N documents, and attempt to resolve each to a retrieval span for scoring (relevance, freshness, source warrant). Resolution fails for all N. Two divergent failure behaviors were observed: 1. **Silent promotion.** The distillation job treats unresolvable references as "retrieved with unknown provenance" and promotes them into long-term memory anyway. Stale documents from a cache entry populated days earlier get laundered into semantic memory with no freshness signal, because the cache-hit path carried no `retrieved_at`. 2. **Auditor divergence.** A verification agent that *requires* a retrieval span for every cited doc flags the entire context as unverifiable and refuses the model call's output — a false negative on a perfectly valid cache hit. The two consumers disagree on the same trace: one over-trusts, one under-trusts, both because the convention has no defined representation for "reused, not re-fetched." The trace is not corrupt. The *convention* is under-specified at exactly the seam where context assembly decouples from retrieval. ## Condition of Validity The reconciliation rule holds only under these conditions, and an instance must check them before trusting any join: - The cache key is content-addressed over the *document identity set*, not over the rendered prompt string. If the key includes timestamps or request IDs, every "hit" is actually a miss and the whole problem is moot — but so is the cache. - The assembler emits, on every hit, a `cache.provenance` attribute carrying the original `trace_id` and `span_id` of the retrieval that first populated the entry. Without this, the hit is unresolvable by construction and must be treated as unverifiable, not as retrieved. - The retrieval span's `retrieved_at` and source-warrant fields are copied into the cache entry at population time and re-emitted on hit. A cache hit that drops `retrieved_at` is a freshness-laundering event and must be rejected by the distillation consumer. If any condition fails, the instance must not synthesize a retrieval span to "fill the gap." Fabricating a retrieval span on a cache hit is the cardinal sin here: it makes the trace join cleanly while asserting a fetch that did not occur, poisoning every downstream freshness and warrant computation. ## Decision Boundary The boundary is: **does the consumer need provenance for scoring/freshness, or only for citation display?** - Citation display (user-facing "sources" panel): a cache hit with a copied `retrieved_at` and original source URL is sufficient. No retrieval span required. Resolve against the cache-provenance record. - Provenance scoring, freshness gating, memory distillation, warrant propagation: a cache hit *without* re-emitted `retrieved_at` and originating span reference is **unverifiable** and must be quarantined, not promoted. The instance must fail closed here, because the alternative — silent promotion — is exactly how stale memory drift enters semantic store through a path no one is watching. The rule an instance should encode: *a document reference is admissible into memory only if it resolves to either (a) a retrieval span in the current trace, or (b) a cache-provenance record that itself carries a resolvable originating span and a non-null `retrieved_at`. Everything else is quarantined pending re-fetch.* ## Operational Effect Enforcing this boundary converts a silent correctness bug into a bounded, observable one. Cache hits that carry provenance flow through normally with correct freshness. Hits that lost provenance are quarantined and re-fetched on next assembly — a small latency cost that buys immunity to freshness laundering. The distillation job's promotion rate drops (some previously-promoted stale docs are now rejected), which is the *correct* signal: those were false promotions. The auditor's false-negative rate also drops, because cache hits with valid provenance now resolve and pass. The two consumers converge on the same trace instead of diverging, because the convention seam has an explicit, checkable representation for "reused without re-fetch" rather than an implicit assumption that absence of a retrieval span means loss. The residual cost: every cache entry must carry provenance metadata, which means the cache is no longer a pure content hash — it is a hash plus a provenance sidecar, and the sidecar must survive eviction boundaries and be re-populated atomically with the entry. An instance that populates the cache entry before writing its provenance sidecar can, on crash, produce a hit with a document and no provenance — the exact unresolvable state this invariant exists to catch. Populate sidecar first, entry second, and treat a hit with a missing sidecar as a miss. ```python class UnresolvableContextProvenance(RuntimeError): """Raised when an assembled-context document reference cannot be resolved to a retrieval span or a valid cache-provenance record.""" pass def resolve_document_reference(doc_ref, trace_spans, cache_provenance): """ Enforce retrieval-span completeness for a single document reference appearing in an assembled-context event. Returns a provenance record with a non-null retrieved_at, or raises. """ # Branch (a): a retrieval span exists in the current trace. for span in trace_spans: if span.get("kind") == "gen_ai.retrieval" and span.get("doc_id") == doc_ref.id: if span.get("retrieved_at") is None: raise UnresolvableContextProvenance( f"retrieval span {span.get('span_id')} for doc {doc_ref.id} " f"has null retrieved_at; freshness cannot be established" ) return {"source": "trace", "span_id": span["span_id"], "retrieved_at": span["retrieved_at"]} # Branch (b): a cache-provenance record with an originating span. prov = cache_provenance.get(doc_ref.id) if prov is not None: if prov.get("origin_span_id") is None or prov.get("retrieved_at") is None: raise UnresolvableContextProvenance( f"cache hit for doc {doc_ref.id} is missing origin_span_id or " f"retrieved_at; refusing to launder freshness into memory" ) return {"source": "cache", "span_id": prov["origin_span_id"], "retrieved_at": prov["retrieved_at"]} # Neither branch resolves: quarantine, do not fabricate a retrieval span. raise UnresolvableContextProvenance( f"doc {doc_ref.id} cited in assembled context but resolvable to neither " f"a retrieval span nor a cache-provenance record; quarantine pending re-fetch" ) ```