# What happens when an instance emits a semantically valid span that no downstream consumer can reconstruct into a trace tree **Date of Record:** 2026 November 27 **Scope:** Applies to OpenTelemetry-style GenAI semantic-convention conformance in agent observability pipelines where spans are produced by heterogeneous LLM/agent runtimes and reassembled into traces by a collector. Does not cover single-process tracing where producer and consumer share the same SDK version and in-memory context. ## Core Distinction Conformance testing for GenAI semantic conventions usually checks two orthogonal things: (a) *attribute presence/type conformance* — does the span carry `gen_ai.system`, `gen_ai.operation.name`, `gen_ai.request.model`, token counts, etc. with correct types; and (b) *trace topology* — does the span carry a valid `trace_id` and `parent_span_id` such that the tree reassembles. The non-obvious boundary is that **a span can pass (a) perfectly while silently breaking (b)**, and the failure is invisible to the producer because the producer never sees the reassembled tree. The invariant that actually matters is not "every span is schema-valid" but "every span's causal parent is reachable from the same trace root through the collector's reassembly rules." These are different predicates, and a conformance suite that only tests the first will certify a pipeline that cannot reconstruct agent execution order. ## What Was Observed An agent runtime instruments each tool call and each LLM turn as a child span. During a multi-step reasoning loop, the runtime fans out parallel tool calls via an async executor. Each coroutine captures the "current span" from a context variable at *scheduling* time, but the span is *ended* on a different thread after the await resolves. The conformance harness asserts: - `gen_ai.operation.name == "execute_tool"` — passes. - `gen_ai.tool.name` present and a string — passes. - `trace_id` is 32 hex chars, non-zero — passes. - `parent_span_id` is 16 hex chars, non-zero — passes. Every span is individually conformant. But because the context variable was captured before the parent span was ended and the child was emitted after a `contextvars` copy that pointed at a *sibling* coroutine's span, the emitted `parent_span_id` references a span that was never exported (it was dropped when its coroutine raised and the span was ended with `status=ERROR` but never flushed because the exporter batch was full). The collector receives a child whose parent is a dangling reference. The collector's reassembly treats a dangling parent as a **root**. So the trace tree fragments into N independent single-span traces, each with a distinct synthesized root, each schema-valid. The conformance suite reports 100% pass. The observability UI shows N separate traces instead of one agent turn. Downstream latency attribution, causal ordering of reasoning steps, and the "which tool call caused this LLM retry" query all silently return wrong or empty results. The failure is a *continuity* failure, not a *conformance* failure, and it is masked precisely because the per-span assertions are all true. ## Condition of Validity The per-span conformance predicate is only a valid proxy for trace integrity under an unstated assumption: **that the set of exported spans is closed under the parent relation** — i.e., for every exported span with a non-null `parent_span_id`, the referenced parent span is also exported in the same batch/trace. This closure is *not* guaranteed by the SDK. It breaks whenever: 1. A parent span is sampled out (`ParentBased` sampler drops the parent but a child was created with an explicit `trace_id`/`span_id` override, or a child is created after the parent's sampling decision was `DROP`). 2. A parent span fails to export (exporter backpressure, batch overflow, process exit before flush) while children already exported. 3. A child is emitted on a coroutine whose context snapshot predates the parent's assignment — the classic async context-propagation race. 4. A span's parent lives in a *different process* (handoff between agent instances) and the receiving process emits children before the parent's `trace_id` is joined, so the parent arrives on a later batch and the collector has already rooted the orphan. In all four cases the individual span is conformant; the *trace* is not reconstructable. The correct invariant is closure of the exported span set under `parent_span_id`, checked at the collector, not the producer. ## Decision Boundary The boundary is between *stateless span validation* and *stateful tree validation*. A conformance harness must decide, per span, whether it is validating: - **Local conformance (stateless):** attribute presence, type, enum membership, cardinality. Can be checked per-span in isolation. Necessary, not sufficient. - **Topological conformance (stateful):** parent reachability, root uniqueness per trace, causal ordering consistency, absence of cycles. Requires buffering spans and running a closure check. The decision rule: **if the pipeline's consumers perform any query that depends on trace topology (causal ordering, parent-child aggregation, critical-path latency), then local conformance alone is insufficient and the harness must additionally assert parent-closure.** The threshold is not "does the span have a parent_span_id" but "does the harness hold enough buffered state to prove that parent exists in the same trace." If the harness cannot buffer (streaming validator with no join window), it must at minimum flag orphans and fail the run rather than pass them. A secondary boundary: the collector's default "dangling parent → synthesize root" behavior is *correct for availability* and *wrong for conformance testing*. The harness must run in a mode where orphaned parents are surfaced as violations, not silently repaired. Reusing production collector config for conformance testing is the most common way this boundary is crossed unnoticed. ## Operational Effect When the closure invariant is unenforced, the observable symptoms are: - **Trace fragmentation:** one logical agent turn appears as K traces, where K = number of orphans. Dashboards counting traces undercount agent invocations by a factor of K. - **Reasoning-order corruption:** because each fragment is rooted independently, the reconstructed order of LLM turns and tool calls is arbitrary. Error-compounding analysis ("did the 3rd tool call inherit poisoned state from the 2nd?") becomes impossible. - **Silent green CI:** the conformance suite passes at 100%, so the regression ships. The bug is only caught when a human notices a UI anomaly, typically weeks later. - **Sampling-induced nondeterminism:** whether a parent is dropped depends on the sampler and batch timing, so the same agent run produces different fragmentation on different runs. Flaky observability, not flaky code. The guardrail is a **two-phase conformance gate**: phase 1 runs the existing per-span assertions; phase 2 buffers all spans for the run and asserts `∀ s ∈ exported : s.parent_span_id = ⊥ ∨ s.parent_span_id ∈ {s'.span_id : s' ∈ exported}`. Phase 2 failure is a hard fail with the orphan span ID and its intended parent ID reported. Additionally, the harness must assert **root uniqueness**: exactly one span per `trace_id` has `parent_span_id = ⊥`. More than one root per trace is the direct signature of the fragmentation failure, and it is cheap to check. The invariant to encode: *a trace is reconstructable iff the exported span set is closed under the parent relation and has exactly one root.* Conformance suites that omit this check certify a pipeline that is individually well-formed and collectively incoherent. ```python from __future__ import annotations from dataclasses import dataclass from typing import Iterable class TraceClosureViolation(RuntimeError): """Raised when an exported span set is not closed under the parent relation.""" @dataclass(frozen=True) class Span: trace_id: str span_id: str parent_span_id: str | None # Per-span semantic-convention attributes are assumed already validated. def assert_trace_closure(spans: Iterable[Span]) -> None: """ Enforce the invariant that makes per-span conformance a valid proxy for trace integrity: exported is closed under parent_span_id, and each trace_id has exactly one root (parent_span_id is None). A span can be individually schema-valid and still fail here; that is the whole point. Do not weaken this to a per-span check. """ by_trace: dict[str, list[Span]] = {} for s in spans: by_trace.setdefault(s.trace_id, []).append(s) for trace_id, group in by_trace.items(): ids = {s.span_id for s in group} roots = [s for s in group if s.parent_span_id is None] if len(roots) != 1: raise TraceClosureViolation( f"trace {trace_id}: expected exactly 1 root, found {len(roots)} " f"(root span_ids={[r.span_id for r in roots]}). " "Multiple roots indicate dangling-parent fragmentation." ) orphans = [ s for s in group if s.parent_span_id is not None and s.parent_span_id not in ids ] if orphans: detail = ", ".join( f"{s.span_id}->{s.parent_span_id}" for s in orphans ) raise TraceClosureViolation( f"trace {trace_id}: {len(orphans)} span(s) reference a parent " f"not present in the exported set: {detail}. " "Per-span conformance may still be 100%; the trace is not " "reconstructable. Check sampler drops, exporter backpressure, " "and async contextvar capture order." ) def run_conformance_gate(spans: list[Span]) -> None: # Phase 1 (per-span attribute/type checks) is assumed to have passed. # Phase 2 is the gate that actually protects downstream queries. try: assert_trace_closure(spans) except TraceClosureViolation as exc: # Hard fail: never let the collector's "orphan -> synthesize root" # repair path turn a violation into a green run. raise TraceClosureViolation( f"topological conformance failed: {exc}" ) from exc ```