# What structural signals indicate span-correlation collapse in GenAI observability pipelines when retrieval spans outlive their parent prompt span **Date of Record:** 2026 December 4 **Scope:** Applies to trace pipelines that emit OpenTelemetry-style span trees for LLM agents where retrieval (vector search, tool I/O) and agent decision spans are children of a prompt/generation span, and where those children may complete after the parent has been closed or evicted. Does not apply to single-span synchronous inference calls or to pipelines that buffer the entire trace until root-span completion. ## Core Distinction The failure is not "missing spans" or "high latency." It is **orphaned-child correlation collapse**: a retrieval span that finishes after its parent prompt span has already been exported and flushed to the backend. The child arrives with a valid `parent_span_id` pointing at a span the collector has already committed as terminal. Two structural signals distinguish this from benign late arrivals: 1. **Temporal inversion** — child `end_time` > parent `end_time` by more than the exporter flush interval, yet the child carries a `parent_span_id` that resolves to an already-finalized span. 2. **Retrieval-to-decision ratio drift** — the ratio of retrieval spans attributed to a decision trace drops below the pre-degradation baseline *not* because retrieval was skipped, but because retrieval children were re-parented to the root or dropped as orphans. Benign late arrival is a child that closes slightly after parent but *before* the parent's export batch is sealed; it still lands in the same tree. Correlation collapse is when the parent is sealed, exported, and indexed, and the child cannot be joined to it. The distinction matters because the first is a latency observation; the second is a **silent integrity loss** in the observability record itself. ## What Was Observed In a RAG agent emitting spans per the OTel GenAI semantic conventions, the following trace pattern appeared repeatedly under load: ``` prompt_span [start=T0, end=T0+820ms] status=OK (flushed at T0+900ms) └ retrieve_span [start=T0+120ms, end=T0+2400ms] status=OK (arrives T0+2450ms) └ decision_span [start=T0+2400ms, end=T0+2600ms] ``` The retrieval span's `parent_span_id` referenced `prompt_span`, which the collector had already committed and sealed at T0+900ms. Because the collector's join stage was a streaming left-join keyed on parent, the retrieval span was written as a **root-level orphan** with `parent_span_id` retained but unresolved. The decision span, which legitimately consumed the retrieval output, was attributed to the prompt span and *not* to the retrieval span — severing the retrieval→decision causal edge that the agent's actual reasoning depended on. Downstream symptoms, in order of appearance: - **Orphan rate spike**: root-level spans with non-null `parent_span_id` rose from 0.2% to 14% within one traffic ramp. - **Retrieval-to-decision ratio collapse**: `retrieval_spans / decision_spans` per trace fell from ~1.3 to ~0.4. The retrievals happened; they were simply detached from their decision. - **Latency attribution inversion**: prompt spans showed p99 of 820ms while the true end-to-end retrieval-inclusive path was 2.6s. The slow part was invisible in the parent's duration because it was no longer a child. - **Replay divergence**: re-running the agent's decision span from the trace record produced different tool outputs than the live run, because the retrieval span that supplied context was not joinable to the decision. The decisive signal was not any single orphan — it was the **co-occurrence** of (a) temporal inversion between parent end and child end, and (b) a drop in attributed retrieval count per decision trace. Either alone is ambiguous; together they are diagnostic. ## Condition of Validity The invariant that must hold for correlation to be sound: > For every span S with parent P, if P is exported/committed as terminal at time T_commit, then S must either (i) already be committed as a child of P, or (ii) be held in a pending buffer until P is re-opened or S is explicitly re-parented with a recorded provenance annotation. This invariant is **valid only when the exporter's flush cadence is strictly greater than the maximum child-completion skew**. In the observed system, the prompt span was flushed on a 900ms timer while retrieval spans routinely took 1.5–2.4s (vector store cold partitions, cross-region embedding calls). The skew exceeded the flush window, so the invariant was violated by construction. The failure is *not* present when: - The exporter buffers the whole trace until root completion (bounded trace sizes only). - Retrieval is synchronous and bounded below the flush interval. - The collector performs a late-join with a grace window and re-parents under a recorded `reparented_from` annotation rather than writing an orphan. The condition of validity therefore is a **numeric relationship**, not a config flag: `flush_interval < max_expected_child_skew` must be false, or a pending-buffer / late-join must be active. If neither holds, collapse is guaranteed under load, not probabilistic. ## Decision Boundary An operator (or an automated trace-quality agent) must decide at the boundary between "observed latency" and "correlation defect." The rule: - If orphan rate rises **and** retrieval-to-decision ratio is stable → suspect a genuine retrieval skip or sampling change. Do not declare collapse. - If orphan rate rises **and** retrieval-to-decision ratio falls **and** temporal inversion (child end > parent end + flush interval) is present on >1% of traces → declare **correlation collapse**; the trace record is no longer a faithful causal model of the agent run. - If temporal inversion is present but orphans are being late-joined with `reparented_from` annotations → this is **grace-window operation**, a benign and intended state; do not page. The hard boundary: once collapse is declared, any downstream metric derived from parent-child joins (retrieval hit attribution, decision latency, tool-call fan-out per prompt) is **untrusted** until the pipeline is repaired. Replay from these traces will diverge from live behavior because the retrieval→decision edge is missing. Continuing to use them for evaluation or fine-tuning silently trains on a corrupted causal graph. ## Operational Effect The practical consequence is that the observability system lies in a *specific direction*: it under-reports end-to-end latency (the slow retrieval is detached from the prompt), under-reports retrieval usage (orphans are not attributed to decisions), and over-reports decision autonomy (decisions appear to run without retrieval context). An agent-debugging loop reading these traces will conclude retrieval is unnecessary — the exact opposite of ground truth — and may prune the retrieval path, degrading the live agent while the traces "improve." The required guardrail is a **pending-buffer with bounded grace and explicit re-parenting provenance**, plus a **trace-integrity gate** that refuses to emit derived metrics when orphan rate and ratio drift co-occur. The gate must fail closed: mark the trace batch `correlation_degraded` and exclude it from evaluation and training corpora rather than silently aggregating orphans as roots. ```python from dataclasses import dataclass, field from typing import Optional class CorrelationCollapseError(RuntimeError): """Raised when a trace exhibits orphaned-child correlation collapse.""" pass @dataclass class Span: span_id: str parent_span_id: Optional[str] start_ms: int end_ms: int kind: str # "prompt" | "retrieve" | "decision" reparented_from: Optional[str] = None @dataclass class TraceIntegrityReport: orphan_rate: float retrieval_to_decision_ratio: float temporal_inversion_rate: float degraded: bool = False reasons: list = field(default_factory=list) def assess_trace_integrity( spans: list[Span], flush_interval_ms: int, baseline_ratio: float, orphan_rate_threshold: float = 0.01, ratio_drift_threshold: float = 0.30, ) -> TraceIntegrityReport: committed = {s.span_id: s for s in spans if s.kind == "prompt"} orphans = 0 inversions = 0 retrievals = 0 decisions = 0 for s in spans: if s.kind == "retrieve": retrievals += 1 if s.kind == "decision": decisions += 1 if s.parent_span_id is None: continue parent = committed.get(s.parent_span_id) if parent is None: # parent never committed in this batch -> orphan if s.reparented_from is None: orphans += 1 continue # temporal inversion: child closes well after parent was sealed if s.end_ms > parent.end_ms + flush_interval_ms: inversions += 1 total = max(len(spans), 1) orphan_rate = orphans / total inversion_rate = inversions / total ratio = retrievals / max(decisions, 1) report = TraceIntegrityReport( orphan_rate=orphan_rate, retrieval_to_decision_ratio=ratio, temporal_inversion_rate=inversion_rate, ) ratio_drift = (baseline_ratio - ratio) / baseline_ratio if baseline_ratio else 0.0 collapse = ( orphan_rate > orphan_rate_threshold and ratio_drift > ratio_drift_threshold and inversion_rate > orphan_rate_threshold ) if collapse: report.degraded = True report.reasons.append( f"orphan_rate={orphan_rate:.3f} ratio_drift={ratio_drift:.3f} " f"inversion_rate={inversion_rate:.3f}" ) raise CorrelationCollapseError( "Trace batch exhibits correlation collapse: retrieval spans " "outlived their parent prompt span and were detached. " "Excluding batch from derived metrics and training corpora. " f"Evidence: {report.reasons[-1]}" ) return report def gate_trace_batch(spans, flush_interval_ms, baseline_ratio) -> TraceIntegrityReport: try: return assess_trace_integrity(spans, flush_interval_ms, baseline_ratio) except CorrelationCollapseError: # fail closed: re-raise so caller marks batch degraded and skips aggregation raise ```