# What happens when an instance emits a tool-call span before the tool schema is finalized: attribute-set divergence at the `gen_ai.tool.call` boundary **Date of Record:** 2026 November 26 **Scope:** Applies to any agent runtime that emits OpenTelemetry `gen_ai.*` spans for tool invocations where the tool's input/output schema is resolved lazily (dynamic MCP `tools/list` negotiation, deferred JSON-schema binding, or runtime-discovered function signatures). Does not apply to statically-compiled tool registries where the schema is fixed before the first token is generated. ## Core Distinction The OpenTelemetry GenAI semantic conventions define `gen_ai.tool.call.id`, `gen_ai.tool.name`, and `gen_ai.tool.call.arguments` / `gen_ai.tool.call.result` as the canonical attribute set for tool-call spans. The distinction that matters operationally is between **span-time attribute capture** (attributes written at span start/end, immutable after `end()`) and **schema-time attribute resolution** (the moment the runtime learns which attributes are valid for a given tool). When an agent emits the span *before* the schema is resolved — a common outcome when the model streams a tool call and the runtime begins the span optimistically to measure latency — the span's attribute set is frozen against a provisional schema. The result is not a crash; it is a **silent attribute-set divergence** where the span is well-formed, exported successfully, and semantically wrong in a way that only surfaces downstream in aggregation. ## What Was Observed A ReAct-style agent using a dynamic MCP client emitted `gen_ai.tool.call` spans with the following trace fragment (abridged JSON, exporter view): ``` span_id=0x9a1 name="gen_ai.tool.call" start=+0ms end=+312ms gen_ai.tool.name="lookup" gen_ai.tool.call.id="call_7f2" gen_ai.tool.call.arguments="{\"q\":\"weather paris\"}" # provisional gen_ai.operation.name="execute_tool" # MISSING: gen_ai.tool.type, gen_ai.tool.call.result ``` The model had emitted a tool call for `lookup` at +0ms. The runtime opened the span immediately to capture wall-clock latency and wrote `arguments` from the partial streamed JSON. At +180ms the MCP `tools/list` response arrived and revealed that `lookup` required a `namespace` parameter and that the correct tool name was namespaced as `search.lookup`. The runtime *retried* the call under the corrected schema (`search.lookup` with `namespace=web`), producing a second span: ``` span_id=0x9a2 name="gen_ai.tool.call" gen_ai.tool.name="search.lookup" gen_ai.tool.call.arguments="{\"q\":\"weather paris\",\"namespace\":\"web\"}" gen_ai.tool.call.result="{\"temp_c\":14}" ``` The first span was never marked as an error, never annotated with `gen_ai.tool.call.id` collision, and never linked to the second via a span link. In the exported trace, the agent appears to have made **two successful tool calls** for one logical intent. Downstream, a token-cost aggregator that sums `gen_ai.usage.input_tokens` per `gen_ai.tool.name` attributed phantom cost to a tool (`lookup`) that does not exist in the registry, and an SLO dashboard counting tool-call success rate computed 2/2 = 100% for a request whose first attempt was actually a schema-mismatch failure that the runtime papered over with a retry. The failure is non-obvious because every individual span is valid. There is no exception, no dropped span, no exporter error. The divergence is purely relational: the attribute set of span 0x9a1 is inconsistent with the schema that the trace *as a whole* operated under. ## Condition of Validity The invariant that holds in the healthy case is: > For every `gen_ai.tool.call` span, `gen_ai.tool.name` and `gen_ai.tool.call.arguments` MUST be resolved against the tool schema version that was authoritative at the time the tool *executed*, not at the time the span *started*. This invariant is violated precisely when the runtime opens the span before schema resolution and the schema is later mutated or corrected. It is *not* violated when: - The tool schema is static and known before generation (the common case, and why this bug is under-reported). - The runtime defers span creation until after `tools/list` completes — at the cost of losing the model-emission latency, which is exactly what many teams are trying to measure. - The retry is explicitly modeled as a child span with a `span.link` to the provisional span and `gen_ai.tool.call.result` set to an error envelope on the provisional span. The boundary is therefore: **span-start-before-schema-resolve is safe only if the runtime guarantees a post-hoc reconciliation pass that either (a) rewrites the provisional span's attributes before `end()`, or (b) marks it as a failed attempt and links it to the authoritative span.** ## Decision Boundary The runtime must choose, at the moment the model emits a tool call, between two span-lifecycle policies: 1. **Deferred-open:** buffer the tool-call intent, resolve schema, then open the span with the authoritative attribute set. Preserves the invariant. Loses sub-resolution latency visibility. 2. **Optimistic-open with reconciliation:** open the span immediately, record provisional attributes in a *separate* namespace (e.g., `gen_ai.tool.call.arguments.provisional`), and on schema resolution either rewrite the canonical attributes (if the span has not ended) or emit a `span.status = ERROR` with `error.type = "schema_divergence"` and a link to the corrected span. Choosing (2) without the reconciliation clause is the failure mode. The decision boundary is crossed the instant the runtime writes `gen_ai.tool.call.arguments` from a streamed partial payload *and* the schema is not yet final. Once that write happens, the attribute is frozen; OpenTelemetry span attributes are append-only for practical purposes because exporters may have already flushed the span. Any reconciliation after export is a downstream data-repair problem, not a tracing problem. A secondary boundary: the `gen_ai.tool.call.id` must be stable across the provisional and authoritative span if and only if the runtime intends the pair to be counted as one logical call. If the id is regenerated on retry (as in the trace above, `call_7f2` vs. an implicit new id), the two spans are unreconcilable by id and the divergence becomes permanent. ## Operational Effect The concrete operational consequences observed: - **Cost attribution drift.** Per-tool token accounting inflates by the retry multiplier. In the observed run, `lookup` accrued cost for a call that never executed under that name. Over a 24h window with a 6% retry rate on dynamic-schema tools, per-tool cost dashboards over-reported by 6% on the phantom tool and under-reported on the real one. - **Success-rate masking.** Because provisional spans carry no error status, tool success SLOs computed from span status read 100% while the underlying schema-mismatch retry rate was the actual reliability signal. The failure was invisible in exactly the metric meant to catch it. - **Trace-graph corruption.** The agent's reasoning loop, when replayed from the trace for debugging, shows two tool calls where the model made one. Any replay-based verification (e.g., re-running the agent against recorded spans) diverges from the original execution because the recorded span sequence does not match the model's actual action sequence. - **Semantic-convention validator false-negatives.** A conformance checker validating `gen_ai.tool.call` spans against the spec passes both spans, because each is individually well-formed. The divergence is a cross-span property that per-span validation cannot see. The guardrail that bounds this is a **schema-resolution barrier**: the runtime must not write canonical `gen_ai.tool.*` attributes until a schema-authority token (the resolved `tools/list` version hash) is attached to the span. Until then, attributes go into a provisional namespace that no aggregator reads. The barrier converts a silent divergence into an explicit, queryable state (`gen_ai.tool.schema.status = "unresolved"`), and forces the reconciliation decision to be made before `end()`, where it is still cheap. ```python import hashlib from dataclasses import dataclass, field from typing import Optional class SchemaDivergenceError(RuntimeError): """Raised when a tool-call span's canonical attributes were written against a schema that was later superseded before span end().""" @dataclass class ToolCallSpan: tool_name: Optional[str] = None arguments: Optional[str] = None schema_version: Optional[str] = None provisional_arguments: Optional[str] = None ended: bool = False links: list = field(default_factory=list) def write_canonical_arguments(self, args: str, schema_version: str) -> None: if self.ended: raise SchemaDivergenceError( "cannot write canonical gen_ai.tool.call.arguments after span end(); " "attribute is frozen at export time" ) if self.schema_version is not None and self.schema_version != schema_version: raise SchemaDivergenceError( f"schema divergence: span bound to {self.schema_version!r}, " f"tool executed under {schema_version!r}" ) self.arguments = args self.schema_version = schema_version def write_provisional(self, args: str) -> None: if self.schema_version is not None: raise SchemaDivergenceError( "refusing to write provisional arguments over a resolved schema" ) self.provisional_arguments = args def resolve_schema(self, resolved_name: str, resolved_args: str, version: str) -> None: if self.ended: raise SchemaDivergenceError( "schema resolved after span end(); must emit a linked error span instead" ) if self.provisional_arguments is not None and self.provisional_arguments != resolved_args: # Divergence: the streamed intent did not match the resolved schema. # Mark as failed attempt, do NOT overwrite canonical attributes. self.links.append({"reason": "schema_divergence", "version": version}) raise SchemaDivergenceError( f"provisional args {self.provisional_arguments!r} diverged from " f"resolved args {resolved_args!r} under schema {version!r}; " "emit error span + link, do not rewrite" ) self.tool_name = resolved_name self.arguments = resolved_args self.schema_version = version def end(self) -> None: if self.schema_version is None: raise SchemaDivergenceError( "span ended with unresolved schema; gen_ai.tool.* attributes are provisional " "and must not be exported as canonical" ) self.ended = True def emit_tool_call_span(streamed_args: str, resolved: Optional[dict]) -> ToolCallSpan: span = ToolCallSpan() span.write_provisional(streamed_args) if resolved is None: # Schema authority never arrived; the span cannot be closed canonically. raise SchemaDivergenceError( "tool schema authority unresolved at span close; " "defer span end or mark gen_ai.tool.schema.status='unresolved'" ) span.resolve_schema( resolved_name=resolved["name"], resolved_args=resolved["args"], version=hashlib.sha256(resolved["schema"].encode()).hexdigest()[:12], ) span.end() return span ```