# In what scenarios must an instance treat an OpenTelemetry GenAI tool-call span as unsealed before the parent turn span closes **Date of Record:** 2026 November 25 **Scope:** Applies to agents that emit GenAI semantic-convention spans (`gen_ai.*`) where a single chat/turn span parents one or more tool-execution spans across a multi-step reasoning loop. Does not apply to single-shot inference with no tool calls, nor to pure transport tracing (HTTP/gRPC) beneath the GenAI layer. ## Core Distinction The OpenTelemetry GenAI conventions model a *turn* as a span that encloses the model invocation, and a *tool call* as a child span that encloses the execution of a tool the model requested. The convention is written as though these nest cleanly: parent turn span opens, child tool span opens and closes, turn span closes. In real agent loops the ordering is not that. The model's tool-call request is emitted *inside* the turn span's payload, the tool executes *after* the model response is received, and the result is fed back into a *second* model invocation that is logically part of the same turn but is a separate `gen_ai.chat` span. The non-obvious boundary is this: **a tool-call span is a child of the turn span, but its input arguments are only known at the moment the parent's model response completes, and its output is only consumed by a sibling model span that has not yet started.** Between the parent's response emission and the child's result being attached to the next model span, the tool span is *unsealed* — its attributes are partially populated and its causal linkage to the consuming model call is not yet representable. Any exporter, sampler, or downstream verifier that treats a closed tool span as complete state will observe an inconsistent chain. ## What Was Observed During a three-tool chain (a `search` tool, a `fetch` tool, and a `summarize` tool) emitted under a single turn span, a batch span processor flushed the tool spans on `end()` while the turn span remained open. The `gen_ai.tool.call.id` attribute was set on each tool span correctly, but the *consuming* model span — the second `gen_ai.chat` invocation that reads the tool result — had not yet been created. The result was a trace where three tool spans existed as children of an open parent, with no forward reference to the model span that would eventually consume them. A downstream replay verifier that reconstructed the causal chain by walking parent→child→sibling relationships saw the tool spans, saw no consuming model span, and concluded the tool results were orphaned. It re-executed the tools. Because the `fetch` tool hit a rate-limited endpoint, the re-execution returned a different payload, and the reconstructed chain diverged from the recorded one. The divergence was not an error in either execution; it was a *modeling* artifact — the GenAI span schema has no field expressing "this tool result is consumed by the next model span in the same turn," so the linkage was inferred from ordering, and ordering was not yet committed at flush time. The same class of failure appeared under a different trigger: when the model emitted *parallel* tool calls (two `fetch` spans under one turn), the convention's implicit assumption of one-tool-per-model-response broke. The turn span's `gen_ai.usage.output_tokens` counted once, but two tool spans were parented to it, and a verifier that assumed a 1:1 tool-to-model-span ratio flagged the second tool as a duplicate. ## Condition of Validity The tool span's "sealed" state is valid **only if** all of the following hold at the moment the span is ended and exported: 1. The parent turn span is still open (so the child is not orphaned by parent closure ordering). 2. The consuming model span either exists as a sibling with a resolvable `gen_ai.tool.call.id` reference, or the exporter is configured to defer flush until the turn span closes. 3. The tool-call ID is unique within the turn and stable across any retry of the same logical call. 4. For parallel tool calls, the turn span carries an explicit count (e.g., `gen_ai.tool.call.count`) so the consumer can distinguish "one call, one span" from "two calls, two spans, one model response." If any of these fail, the span is unsealed and must not be treated as ground truth by replay, audit, or evaluation consumers. The invariant is: **a GenAI tool span is sealed iff its causal consumer is present in the same trace at flush time, or the flush is deferred to turn-span close.** ## Decision Boundary The decision an instance must make is whether to (a) flush tool spans eagerly on `end()` and accept that consumers will see unsealed spans, or (b) defer flush to turn-span close and accept higher memory pressure and longer time-to-visibility. The boundary is crossed when the turn span's expected duration exceeds the batch processor's `schedule_delay_millis`, or when the agent loop's step count is unbounded (no max-tool-calls guard). In those cases eager flush produces unsealed spans that a naive verifier will mis-reconstruct; deferred flush produces sealed spans but risks losing the entire turn's spans if the process crashes mid-loop. The correct resolution is not to pick one: it is to emit an explicit `gen_ai.tool.call.sealed` boolean attribute (or equivalent) that is `false` at `end()` and is flipped to `true` only when the consuming model span is created, with a span *event* on the tool span recording the seal. Consumers that require sealed spans filter on this attribute; consumers that tolerate unsealed spans proceed. This preserves the eager-flush path while making the unsealed state explicit rather than inferred from ordering. ## Operational Effect Without the seal marker, replay verifiers re-execute tools, producing nondeterministic divergence (as observed with the rate-limited `fetch`). Audit pipelines that reconstruct causal chains from parent-child-sibling ordering mis-attribute tool results to the wrong model span when parallel calls are present. Evaluation harnesses that compare recorded tool outputs against re-executed outputs flag false mismatches. The observable symptom is not a crash but a *silent* divergence: the trace looks well-formed, the spans have all required attributes, and only a consumer that checks causal closure detects the inconsistency. The guardrail is the explicit seal attribute plus a verifier precondition that rejects unsealed tool spans from replay — converting a silent mis-reconstruction into a loud, actionable rejection. ```python class UnsealedToolSpanError(RuntimeError): """Raised when a GenAI tool span is consumed as ground truth before its causal consumer exists.""" pass def verify_tool_span_sealed(span: dict, trace_spans: dict) -> None: call_id = span.get("gen_ai.tool.call.id") if call_id is None: raise UnsealedToolSpanError(f"tool span missing gen_ai.tool.call.id: {span.get('name')}") sealed_flag = span.get("gen_ai.tool.call.sealed") if sealed_flag is None: # No explicit seal marker: fall back to causal-consumer presence check. consumer_present = any( other.get("gen_ai.tool.call.id") == call_id and other.get("gen_ai.operation.name") == "chat" and other.get("span_id") != span.get("span_id") for other in trace_spans.values() ) if not consumer_present: raise UnsealedToolSpanError( f"tool span {span.get('span_id')} (call.id={call_id}) has no consuming " f"model span in trace; refusing to treat as sealed ground truth" ) return if sealed_flag is False: raise UnsealedToolSpanError( f"tool span {span.get('span_id')} (call.id={call_id}) explicitly marked unsealed; " f"consumer must wait for turn-span close or seal event" ) def reconstruct_chain(trace_spans: dict) -> list: ordered = sorted(trace_spans.values(), key=lambda s: s.get("start_time_unix_nano", 0)) for span in ordered: if span.get("gen_ai.operation.name") == "execute_tool": verify_tool_span_sealed(span, trace_spans) return ordered ```