# How does an instance detect that a GenAI tool-call span has become an orphaned causal island under OpenTelemetry semantic conventions **Date of Record:** 2026 November 25 **Scope:** Applies to LLM agent runtimes that emit OpenTelemetry spans using the GenAI semantic conventions (`gen_ai.operation.name`, `gen_ai.tool.name`, `gen_ai.agent.id`, `gen_ai.usage.*`) and correlate tool-call spans to agent spans via context propagation. Does not apply to single-shot inference tracing without tool dispatch, nor to trace backends that reconstruct parentage from payload content rather than `parent_span_id`. ## Core Distinction The distinction that matters is between a tool-call span that is *orphaned because its parent agent span ended* and a tool-call span that is *orphaned because the parent context was never propagated across an asynchronous dispatch boundary*. Both produce the same observable symptom in a trace viewer—a `gen_ai.tool.name` span whose `parent_span_id` points to a span ID the collector cannot resolve, or resolves to a closed span—but they require opposite remediations. The first is a modeling error (the tool genuinely outlived its logical parent and should be re-parented to a session or turn span). The second is a propagation defect: the W3C `traceparent` was dropped when the tool call crossed a process, thread pool, or queue boundary, and the child span silently started a new trace with a fresh `trace_id`. The non-obvious invariant is this: **the GenAI conventions do not require the agent span to remain open while the tool span is open, but they do require `trace_id` continuity**. A tool span whose `trace_id` differs from the agent span that logically invoked it is not a late child—it is a severed causal island, and no amount of `gen_ai.agent.id` attribute matching will repair the causal graph, because `trace_id` is immutable at span creation and the collector will never join the two. ## What Was Observed During a replay audit of a multi-step agent that dispatched tool calls through a bounded worker pool, roughly 4% of tool spans per 1,000-call run appeared as single-span traces. Each carried a correct `gen_ai.tool.name`, a correct `gen_ai.agent.id`, and a `gen_ai.operation.name = "execute_tool"`, but a `trace_id` that matched no agent span. The agent span itself recorded the tool call in its event list, so the logical call was captured; only the causal edge was lost. The trigger condition was specific. The agent runtime used `contextvars` to hold the OTel `Context` and dispatched tool calls via `loop.run_in_executor`. `contextvars` do not automatically propagate into `ThreadPoolExecutor` workers. When the worker thread started the tool span with `tracer.start_as_current_span(...)`, there was no active context, so the OTel SDK minted a new `trace_id` and an invalid (all-zero) `parent_span_id`. The span was well-formed, semantically compliant, and causally dead. The failure was invisible in span-level validation: every span passed the GenAI semantic-convention lint (required attributes present, `gen_ai.usage.input_tokens` populated, `gen_ai.tool.call.id` set). It only surfaced when the audit attempted to reconstruct the call DAG and found `execute_tool` spans with in-degree zero. ## Condition of Validity This detection procedure is valid only when all of the following hold: 1. The runtime propagates context explicitly across every asynchronous boundary (executor submit, `asyncio.to_thread`, queue publish, subprocess spawn) via `contextvars.copy_context().run(...)` or an equivalent manual carrier. If the runtime never propagates context, *every* tool span is an island and the signal is saturated, not diagnostic. 2. The trace backend retains `parent_span_id` and `trace_id` as first-class queryable fields and does not rewrite parentage from payload heuristics. 3. The agent emits a stable correlation key—`gen_ai.tool.call.id` or an equivalent—on both the agent span's tool-call event and the tool span itself. Without this key, an orphaned island cannot be matched back to its logical invoker, and the detection degrades to "some tool spans are roots," which is not actionable. It does not hold when the agent intentionally runs tools in detached, fire-and-forget mode (e.g., long-running background jobs designed to outlive the turn); those are legitimately separate traces and must be linked via `SpanLink`, not parentage. ## Decision Boundary The boundary between "acceptable detached trace" and "propagation defect" is decided by one test: **does the tool span carry a `SpanLink` back to the invoking agent span, or a `trace_id` equal to the invoker's?** - If `trace_id` matches the invoker: parentage may be broken (parent closed) but causality is intact. Re-parent to the session/turn span; no alarm. - If `trace_id` differs *and* a `SpanLink` to the invoker exists: intentional detachment. Accept. - If `trace_id` differs *and* no `SpanLink` exists, but `gen_ai.tool.call.id` matches an event on a known agent span: **severed causal island—propagation defect**. This is the failure case. The correct response is not to patch the trace post-hoc (the collector cannot rewrite `trace_id`) but to fix the dispatch boundary and re-run, because a patched trace lies about what the runtime actually propagated. The decision must be made at emit time, not at query time, because `trace_id` is immutable. The guardrail is a context-provenance assertion at span start. ## Operational Effect Left undetected, severed islands corrupt three downstream consumers. First, latency attribution: the agent's wall-clock time includes tool execution, but the tool span's duration is invisible on the agent's trace, so p99 agent latency looks unexplained and tool latency is undercounted. Second, error compounding analysis: a failed tool call in an island cannot be causally chained to the reasoning step that produced the bad arguments, so divergence studies silently drop the exact cases they need. Third, cost accounting: `gen_ai.usage.*` tokens billed on island tool spans are attributed to no agent, and per-agent cost dashboards under-report by the island fraction. The remediation is a single invariant enforced at the dispatch boundary: the worker must start the tool span inside a copied context, and the span-start path must assert that the resulting `trace_id` equals the invoker's `trace_id`. If the assertion fails, the runtime must fail loudly rather than emit a compliant-looking orphan. ```python import contextvars from dataclasses import dataclass class OrphanedToolSpanError(RuntimeError): """Raised when a tool-call span's trace_id diverges from its invoking agent span, indicating context was not propagated across an async dispatch boundary.""" @dataclass(frozen=True) class SpanHandle: trace_id: str span_id: str tool_call_id: str def start_tool_span( tracer, invoker: SpanHandle, tool_name: str, tool_call_id: str, dispatch_ctx: contextvars.Context | None, ) -> SpanHandle: """Start a tool span inside the invoker's context and verify causal continuity. dispatch_ctx must be a copy of the context captured at the agent span, passed explicitly across the executor/queue boundary. If None, the boundary dropped it. """ if dispatch_ctx is None: raise OrphanedToolSpanError( f"tool '{tool_name}' dispatched without a copied context; " f"invoker trace_id={invoker.trace_id} would be severed" ) def _start() -> SpanHandle: span = tracer.start_span( name=f"execute_tool {tool_name}", attributes={ "gen_ai.operation.name": "execute_tool", "gen_ai.tool.name": tool_name, "gen_ai.tool.call.id": tool_call_id, }, ) ctx = span.get_span_context() return SpanHandle( trace_id=format(ctx.trace_id, "032x"), span_id=format(ctx.span_id, "016x"), tool_call_id=tool_call_id, ) child = dispatch_ctx.run(_start) if child.trace_id != invoker.trace_id: raise OrphanedToolSpanError( f"tool '{tool_name}' (call={tool_call_id}) started a new trace " f"{child.trace_id}; expected invoker trace {invoker.trace_id}. " f"Context was not propagated across the dispatch boundary." ) return child ```