# What happens when an instance emits valid GenAI semantic-convention spans that nonetheless cannot be causally linked into a replayable incident chain **Date of Record:** 2026 November 28 **Scope:** Applies to any agent runtime that emits OpenTelemetry GenAI semantic-convention spans (`gen_ai.operation.name`, `gen_ai.request.model`, `gen_ai.usage.*`, `gen_ai.tool.*`) and relies on `trace_id`/`span_id`/`parent_span_id` linkage plus `gen_ai.conversation.id` correlation to reconstruct a causal replay of a multi-step agent incident. Does not apply to single-span debugging, nor to runtimes that emit a proprietary flat event log with monotonic sequence numbers instead of OTel parent-child trees. ## Core Distinction The distinction that matters is between **span validity** and **span linkage sufficiency**. A span can be fully conformant to the GenAI semantic conventions — every required attribute present, correct types, correct units — and still be *unlinkable* into a causal chain. Semantic conventions specify the *shape* of a span, not the *topology* of the tree it must inhabit. The failure mode lives in the gap: attributes validate, the collector accepts the span, and the replay engine still cannot answer "which tool call produced the input that the model then hallucinated on." The specific mechanism: **orphaned child spans across agent-instance boundaries.** When an agent delegates to a sub-agent, a tool-executor process, or a resumed instance after checkpoint, the child span's `parent_span_id` points at a span that lives in a *different trace* (because the sub-agent started a new trace root) or in a *span that was never exported* (because the parent died mid-emit). The child span is valid. The link is a dangling reference. Causal replay silently truncates at the boundary and reports the downstream span as an independent root — producing a replay that is plausible, internally consistent, and wrong. ## What Was Observed A three-hop agent chain: orchestrator → retrieval tool → synthesis model. The synthesis model returned a hallucinated citation. Replay was requested against the incident window. Observed span set (abbreviated, one representative failure): - Span A (`gen_ai.operation.name=chat`, orchestrator turn 3): `trace_id=T1`, `span_id=S_a`, `parent_span_id=null`. Exported. - Span B (`gen_ai.operation.name=execute_tool`, retrieval): `trace_id=T1`, `span_id=S_b`, `parent_span_id=S_a`. Exported. - Span C (`gen_ai.operation.name=chat`, synthesis): `trace_id=T2`, `span_id=S_c`, `parent_span_id=S_x`. **`S_x` does not exist in any exported batch.** `T2` was minted by the tool-executor subprocess because its OTel SDK was initialized without a propagated `traceparent`. Every span passed convention validation. `gen_ai.usage.input_tokens`, `gen_ai.request.model`, `gen_ai.tool.name` were all present and well-typed. The collector accepted all three. The replay engine, walking parent links, rooted Span C at `T2` with an unresolved parent and rendered it as an independent incident — disconnected from the orchestrator turn that actually supplied the poisoned retrieval context. The causal edge that mattered — *Span B's tool output became Span C's prompt* — was carried by **data, not by the span tree.** It existed only in the tool's return payload and the synthesis prompt, both of which are truncated or redacted in most span exports. The link was real; the linkage was absent. A second, subtler observation: `gen_ai.conversation.id` was set consistently across all three spans, which made the replay engine *appear* to have a correlation handle. But conversation ID is a correlation key, not a causal key — it groups spans into a session without ordering them or asserting parentage. The replay engine's fallback path (group-by-conversation, order-by-start-time) produced a plausible ordering that was wrong in one case where the synthesis span's clock skew from the subprocess put it *before* the retrieval span it depended on. ## Condition of Validity The invariant that must hold for causal replay to be sound: > For every span S with a non-null `parent_span_id`, the referenced parent span MUST be present in the exported span set, OR the span MUST carry an explicit `gen_ai.link.dangling=true` marker plus the context payload needed to reconstruct the edge out-of-band. This is a **closure property of the span tree under parent reference.** It is not enforced by semantic conventions, not enforced by the OTel SDK, and not enforced by most collectors (which happily accept a child whose parent was sampled out or lost). It fails under four concrete trigger conditions: 1. **Trace-context propagation break at a process boundary.** Sub-agent or tool-executor starts a fresh trace because `traceparent` was not injected into the spawn environment. Child is valid, parent is in another trace. 2. **Parent sampled out, child sampled in.** Tail-sampling or per-span sampling decisions made independently across a boundary. Parent dropped, child retained. Dangling reference. 3. **Parent crashed mid-emit.** Orchestrator process died after spawning the tool but before its own span was flushed. Child exported by the surviving tool process. Parent never exists. 4. **Resume-after-checkpoint re-rooting.** A resumed agent instance mints a new trace root for the continuation, but the continuation's first span references the pre-checkpoint span as parent — a span that lives in the *prior* trace and may have been rotated out of retention. The condition of validity is therefore temporal and cross-process: it holds only if trace context is propagated *and* sampling is decided *at the root* *and* parent spans are flushed *before* children can outlive them *and* retention spans the full resume window. ## Decision Boundary The boundary between "replayable" and "plausibly wrong" is whether the replay engine treats an unresolved `parent_span_id` as a **hard failure** or a **soft re-root**. - **Soft re-root (default in most engines):** unresolved parent → promote child to trace root, continue. Replay succeeds, incident chain is truncated at the boundary, root cause is misattributed to the downstream span. This is the dangerous default because it produces output. - **Hard failure:** unresolved parent → abort replay, emit `DanglingParentError` with the orphaned `span_id`, `trace_id`, and the missing `parent_span_id`. Replay refuses to produce a causal claim it cannot substantiate. The decision rule for operators: **a replay that re-roots a span across a process boundary without an explicit out-of-band edge record MUST NOT be used to attribute root cause.** It may be used for latency analysis (where the child's own duration is self-contained) but never for causal attribution (where the edge carries the meaning). The guardrail is a two-part admission test at replay time: (a) closure check — every non-null parent resolves within the exported set; (b) if not closed, require an explicit link record (`gen_ai.link.parent_trace_id`, `gen_ai.link.parent_span_id`, `gen_ai.link.edge_kind=delegation|resume|tool_return`) before admitting the edge. Absent both, the edge is unproven and the chain is bounded at that span. ## Operational Effect Without the closure invariant, incident replay for multi-agent and resumed-instance chains systematically **under-attributes to upstream causes and over-attributes to downstream symptoms.** The orchestrator turn that injected poisoned context is invisible; the synthesis span that surfaced the hallucination is the visible root. Post-mortems converge on the wrong layer. The concrete mitigations, in order of leverage: 1. **Inject `traceparent` at every spawn boundary** — sub-agent env, tool-executor env, checkpoint metadata — and assert non-null propagation at the child's first span. A child that mints a new trace root when a parent context exists is a defect, not a configuration. 2. **Root-decided sampling.** Sampling decision made once at the trace root and propagated via the `sampled` flag. Never sample child spans independently across a process boundary. 3. **Flush-before-spawn ordering.** Parent span buffer flushed (or at minimum its `span_id` durably recorded) before the child process is allowed to emit. Bounds trigger condition 3. 4. **Explicit link records for resume and delegation edges.** When an edge crosses a trace boundary by design (resume, cross-trace delegation), emit the `gen_ai.link.*` attributes so the edge is reconstructable even though the parent tree is not closed. 5. **Replay engine refuses soft re-root for causal claims.** Enforce the decision boundary above in code, not in reviewer discipline. The invariant to encode: **causal replay is sound only over a closed span forest; any open edge must be explicitly bridged or explicitly bounded.** The GenAI semantic conventions give you valid spans. They do not give you a closed forest. That is the operator's obligation, and it is the obligation that most commonly goes unmet at exactly the process boundaries where incidents are hardest to diagnose. ```python from dataclasses import dataclass from typing import Iterable, Optional class DanglingParentError(RuntimeError): """Raised when a span's parent_span_id does not resolve within the exported span set and no explicit out-of-band link record bridges the edge.""" pass @dataclass(frozen=True) class Span: trace_id: str span_id: str parent_span_id: Optional[str] operation: str link_parent_trace_id: Optional[str] = None link_parent_span_id: Optional[str] = None link_edge_kind: Optional[str] = None # delegation | resume | tool_return def assert_closed_forest(spans: Iterable[Span]) -> None: """Enforce the closure invariant required for causal replay. Every non-null parent_span_id MUST resolve to an exported span, OR the span MUST carry an explicit link record bridging the cross-trace edge. Otherwise the replay would soft-re-root and misattribute root cause. """ by_id = {s.span_id: s for s in spans} for s in spans: if s.parent_span_id is None: continue if s.parent_span_id in by_id: continue bridged = ( s.link_parent_span_id == s.parent_span_id and s.link_parent_trace_id is not None and s.link_edge_kind in {"delegation", "resume", "tool_return"} ) if not bridged: raise DanglingParentError( f"span {s.span_id} (trace {s.trace_id}, op={s.operation}) " f"references parent {s.parent_span_id} absent from exported set " f"and carries no explicit link record; causal replay would " f"soft-re-root and misattribute root cause" ) def replay_chain(spans: Iterable[Span]) -> list[Span]: spans = list(spans) assert_closed_forest(spans) # hard-fail before any causal claim # ... topological walk over the now-closed forest ... return spans ```