# What happens when an instance emits GenAI spans without a turn-scoped parent: orphaned tool-call links and silent trace fragmentation under OpenTelemetry GenAI conventions **Date of Record:** 2026 November 22 **Scope:** Applies to multi-turn agent runtimes that emit OpenTelemetry GenAI semantic-convention spans (`gen_ai.*`) across tool calls, model invocations, and handoffs within a single logical conversation. Does not apply to single-shot inference calls or to traces that are structurally validated by a collector-side span processor before export. ## Core Distinction The GenAI semantic conventions model a *turn* as an implicit unit: `gen_ai.operation.name`, `gen_ai.request.model`, and the `gen_ai.usage.*` counters are defined per model invocation, while conversation identity is carried out-of-band via `gen_ai.conversation.id` (and, in practice, a session/thread attribute). What the conventions do **not** define is a mandatory structural parent that binds successive turns of the same conversation into a single trace. The failure mode is not a schema violation—every emitted span is individually valid. The failure is *structural*: when an agent runtime creates each turn's root span independently (a common pattern when turns are scheduled by a queue, a resumed checkpoint, or a separate worker), each turn becomes its own trace, and the cross-turn causal chain—the thing that makes multi-turn agent behavior auditable—is severed. The distinction that matters: **attribute-level conformance is not trace-level continuity.** A runtime can be 100% compliant with `gen_ai.*` attribute requirements and still produce a trace graph in which no tool call can be causally linked to the user message that provoked it three turns earlier. ## What Was Observed A three-turn agent loop (user message → plan → tool call → tool result → synthesis → user follow-up) executed across stateless workers. Each worker received `conversation.id` and a serialized message history, created a fresh root span with `gen_ai.operation.name="chat"`, and emitted child spans for tool invocations with `gen_ai.tool.name` and `gen_ai.tool.call.id`. On export: - The backend received **three distinct traces**, each with a single root span and one to four children. `trace_id` differed per turn; `parent_span_id` was empty on each root. - Within a turn, tool spans correctly referenced their model-invocation parent. Across turns, **no span referenced any span from a prior turn**—the `gen_ai.tool.call.id` linking a tool result to its originating call survived only inside the message payload, not in span structure. - `gen_ai.conversation.id` was present and identical across all three traces, so a query *by attribute* could reconstruct the conversation. A query *by trace* (`trace_id`) returned one-third of the interaction. - When a turn was retried after a worker timeout, the retry emitted a **second root span with the same `conversation.id` and same turn index but a new `trace_id`**, producing duplicate turn roots that downstream dedup keyed on `trace_id` could not collapse. - Latency attribution broke: the backend's per-trace duration equalled the slowest single turn, not the end-to-end agent latency, because the turns never shared a trace root. The observable symptom is **silent trace fragmentation**: no error, no dropped span, no schema rejection—just a trace graph whose edges understate the actual causal structure by an unbounded factor (one edge per turn instead of one chain per conversation). ## Condition of Validity The fragmentation is only *benign* under a specific, checkable condition: **every consumer of the telemetry reconstructs conversation structure from `gen_ai.conversation.id` plus an explicit turn-ordering attribute (e.g., `gen_ai.conversation.turn` or a monotonic `turn.index`), and never assumes `trace_id` equals conversation identity.** This condition holds only when: 1. The turn-ordering attribute is emitted on every span, not just the root (otherwise child tool spans cannot be ordered relative to prior turns). 2. Retries are disambiguated by an attempt attribute (e.g., `turn.attempt`), so duplicate roots are collapsible. 3. The backend's query layer supports attribute-scoped trace reconstruction (grouping spans by `conversation.id` across trace boundaries) rather than trace-scoped traversal only. If any of these is false—most commonly, if the backend or an auditor assumes one trace per conversation—the condition fails and the trace is *misleading*, not merely incomplete. The dangerous regime is the one where the data looks complete per-trace and is silently wrong per-conversation. ## Decision Boundary The architectural choice is between two invariants; pick one and enforce it: - **Invariant A (single-trace conversation):** the runtime must propagate a conversation-scoped root context across turns—either by resuming the prior turn's span context from checkpoint state, or by creating a conversation root span at session start and making every turn's `chat` span a descendant. This requires persisting the `trace_id`/`span_id` of the conversation root in the agent's checkpoint, so a cold-started worker can reattach. The cost: a long-running conversation root span, which some backends truncate or reject past a max duration, and which forces the checkpoint to carry trace state alongside message state. - **Invariant B (fragmented-by-design, reconstructed-by-attribute):** accept one trace per turn, but make `gen_ai.conversation.id`, `turn.index`, and `turn.attempt` mandatory on every span and contractually required by every consumer. The cost: every query and every auditor must implement cross-trace reconstruction, and any consumer that defaults to trace-scoped traversal is now a correctness bug. The boundary is crossed the moment a runtime mixes the two: emits per-turn roots (A violated) while consumers assume trace identity (B's contract unmet). That mixed state is the failure. It is not detectable from any single span and is only detectable by a validator that checks *cross-span* structural invariants—specifically, that for a given `conversation.id`, either all turns share a `trace_id` (A) or all spans carry `turn.index` and `turn.attempt` (B), but never neither. ## Operational Effect In the fragmented state, three concrete operational losses follow: 1. **Causal attribution loss:** a tool call's effect on a later turn's output cannot be traced by span linkage, only by re-reading the message payload. Post-incident analysis of "which retrieval poisoned turn 4" degrades from a graph query to a text search. 2. **Retry duplication:** duplicate turn roots with distinct `trace_id`s inflate token-usage aggregates (`gen_ai.usage.input_tokens` summed per trace double-counts retried turns), silently corrupting cost and budget telemetry—which then feeds back into the runtime's own token-budget governor as a wrong input. 3. **Continuity-blind alerting:** latency and error-rate SLOs computed per-trace measure per-turn behavior, so a conversation that stalls *between* turns (the classic cold-start/handoff gap) shows as three fast, successful traces and zero alerts. The guardrail is a collector-side or export-side validator that enforces the chosen invariant before spans reach the backend, plus checkpoint-persisted trace state if Invariant A is chosen. The invariant to encode: *for every `conversation.id`, the emitted span set must satisfy exactly one of the two structural contracts, and retries must be collapsible by `(conversation.id, turn.index, turn.attempt)`.* ```python from dataclasses import dataclass, field from collections import defaultdict class TraceContinuityViolation(RuntimeError): """Raised when an agent's GenAI span set violates the chosen multi-turn continuity invariant (single-trace OR attribute-reconstructable).""" @dataclass class Span: trace_id: str span_id: str parent_span_id: str | None conversation_id: str turn_index: int | None = None turn_attempt: int | None = None operation: str = "chat" @dataclass class ConversationAudit: spans: list[Span] = field(default_factory=list) def validate(self, require_single_trace: bool) -> None: by_conv: dict[str, list[Span]] = defaultdict(list) for s in self.spans: by_conv[s.conversation_id].append(s) for conv_id, conv_spans in by_conv.items(): trace_ids = {s.trace_id for s in conv_spans} roots = [s for s in conv_spans if s.parent_span_id is None] if require_single_trace: # Invariant A: all turns of a conversation share one trace, # and exactly one root exists per (conversation, attempt). if len(trace_ids) > 1: raise TraceContinuityViolation( f"conversation {conv_id!r} fragmented across " f"{len(trace_ids)} trace_ids under single-trace invariant" ) attempts = {(s.turn_index, s.turn_attempt) for s in roots} if len(attempts) != len(roots): raise TraceContinuityViolation( f"conversation {conv_id!r} has duplicate turn roots " f"not collapsible by (turn_index, turn_attempt)" ) else: # Invariant B: fragmentation allowed, but every span must be # reconstructable by conversation.id + turn.index + turn.attempt. for s in conv_spans: if s.turn_index is None or s.turn_attempt is None: raise TraceContinuityViolation( f"span {s.span_id} in conversation {conv_id!r} " f"lacks turn.index/turn.attempt; cross-trace " f"reconstruction impossible" ) keys = [(s.turn_index, s.turn_attempt) for s in roots] if len(set(keys)) != len(keys): raise TraceContinuityViolation( f"conversation {conv_id!r} retry roots not disambiguated " f"by attempt; duplicate turn roots will double-count usage" ) def emit_turn(audit: ConversationAudit, *, conversation_id: str, trace_id: str, turn_index: int, turn_attempt: int, single_trace: bool, prior_trace_id: str | None) -> Span: # Enforce invariant at emission time: a cold-started worker that fails to # reattach to the conversation's trace silently fragments the chain. if single_trace and prior_trace_id is not None and trace_id != prior_trace_id: raise TraceContinuityViolation( f"turn {turn_index} of {conversation_id!r} opened new trace " f"{trace_id} while prior turn used {prior_trace_id}; " f"checkpoint trace state was not resumed" ) span = Span( trace_id=trace_id, span_id=f"sp-{conversation_id}-{turn_index}-{turn_attempt}", parent_span_id=None, conversation_id=conversation_id, turn_index=turn_index, turn_attempt=turn_attempt, ) audit.spans.append(span) return span ```