# When must an instance refuse to emit a GenAI tool-call span it cannot correlate: the orphaned `gen_ai.tool.call.id` invariant under parallel agent fan-out **Date of Record:** 2026 November 28 **Scope:** Applies to agents instrumented with OpenTelemetry GenAI semantic conventions (`gen_ai.*`) that emit tool-call spans and correlate them across parent agent spans, including multi-agent handoffs. Does not cover non-GenAI RPC spans, pure metrics/logs pipelines, or tracing of the model provider's own internal inference. ## Core Distinction The GenAI semantic conventions treat a tool-call span as a *child of the agent span that issued the call*, correlated upward by span parentage and sideways by the `gen_ai.tool.call.id` attribute. There are two structurally different ways a tool-call span can be "uncorrelatable," and they require opposite handling: 1. **Missing parent context** — the span is emitted with no valid `SpanContext` parent (e.g., after a context-variable reset across an async boundary). This is a *transport* defect: the span still carries a self-consistent `gen_ai.tool.call.id` and `gen_ai.operation.name`, so a collector can re-parent it post-hoc by attribute join. 2. **Orphaned correlation id** — the span has a valid parent, but its `gen_ai.tool.call.id` collides with, or is duplicated across, two sibling agent spans that were fanned out concurrently from the same reasoning step. The id is *present and well-formed*, so all schema validators pass, but the id no longer names a unique call. This is a *semantic* defect and is the dangerous one. The invariant that must hold: **within a trace, `(trace_id, gen_ai.tool.call.id)` must map to exactly one emitted tool-call span, and that span's parent must be the agent span whose `gen_ai.agent.id`/`gen_ai.conversation.id` issued the call.** When this invariant cannot be satisfied — because the id was minted before fan-out and reused — the instance must *not* emit a span claiming that correlation. It must emit a degraded span with the id redacted and a `gen_ai.tool.call.id.collision` marker, or refuse the span entirely. Emitting a well-formed-looking but ambiguous id is worse than emitting none, because downstream replay and audit joins will silently mis-attribute tool effects to the wrong agent. ## What Was Observed A planner agent (`gen_ai.agent.name=planner`) decomposed a task into three sub-goals and dispatched them to three worker instances via a fan-out over `asyncio.gather`. The runtime minted tool-call ids at *plan time*, before fan-out, to allow the workers to pre-warm tool schemas. All three workers therefore inherited the same seed id `call_7f3a` for their first tool invocation, and each emitted: ``` gen_ai.operation.name = "execute_tool" gen_ai.tool.name = "http_fetch" gen_ai.tool.call.id = "call_7f3a" gen_ai.agent.name = "worker" ``` with three distinct parent `SpanContext`s (one per worker span). Every span passed schema validation. The collector's attribute-join correlator, which keyed on `(trace_id, gen_ai.tool.call.id)`, collapsed the three into a single logical call and attributed the union of three divergent `http_fetch` results to whichever worker span sorted first. During incident replay, the auditor reconstructed that worker #1 had fetched three URLs; it had fetched one. The divergence surfaced only when the three tool results disagreed on a shared resource's state. The failure trace: 1. Plan phase mints `call_7f3a` once, stores it in the shared plan object. 2. `asyncio.gather` copies the plan reference into three worker coroutines; no id re-mint per worker. 3. Each worker emits a tool-call span reusing `call_7f3a`; the OTel SDK does not detect the duplicate because ids are opaque strings it never dedupes. 4. Collector join on `(trace_id, call.id)` yields a 1:3 fan-in; result set is union-merged. 5. Replay/audit mis-attributes effects; no error is raised anywhere in the pipeline. ## Condition of Validity The invariant holds — and an instance may safely emit a correlated tool-call span — only when all of the following are true at emission time: - The `gen_ai.tool.call.id` was minted *after* the decision to invoke the tool, scoped to the emitting agent instance, not inherited from a shared plan object. - The id is unique within the trace, verifiable by the emitter against a per-trace id registry (or by construction: id = hash(span_id, tool_name, nonce)). - The parent `SpanContext` is the agent span that actually executed the call, and its `gen_ai.agent.name` matches the emitting instance. - No sibling span in the same trace has already claimed the id. If any condition fails, the instance is in the orphaned-correlation regime and must degrade. The condition is *not* satisfied merely because the span serializes and the schema validates — schema validity is orthogonal to correlation uniqueness. ## Decision Boundary The boundary is between "id present but ambiguous" and "id absent but honest." The decision rule: - **Emit correlated span** iff the id passes the per-trace uniqueness check at emission. - **Emit degraded span** (id redacted to `null`, `gen_ai.tool.call.id.collision=true`, original id retained only in a non-correlating `gen_ai.tool.call.id.raw` attribute excluded from joins) iff uniqueness fails but the call still executed and its effects must be recorded. - **Refuse the span and raise** iff uniqueness fails *and* the emitter cannot prove which agent span owns the effect — because emitting a degraded span with a wrong parent still mis-attributes, just less loudly. The critical refusal case: when a worker inherits a pre-minted id and cannot determine whether a sibling already used it, it must not guess. Guessing "I'm probably first" is exactly the non-determinism that produces replay discrepancies. ## Operational Effect After enforcing the invariant, fan-out tool-call spans carry distinct ids and the collector's attribute join recovers a 3:3 mapping; replay attributes each `http_fetch` to its true worker. The cost is that pre-warming by plan-time id is no longer possible — schema pre-warm must key on `gen_ai.tool.name`, not `call.id`. The guardrail is a per-trace id registry checked at emission, plus a collector-side assertion that `(trace_id, call.id)` cardinality is 1, which converts silent mis-attribution into a loud, catchable rejection at ingest rather than at audit time. ```python import hashlib from dataclasses import dataclass, field class OrphanedToolCallIdError(RuntimeError): """Raised when a tool-call span cannot be uniquely correlated within a trace.""" pass @dataclass class ToolCallSpan: trace_id: str parent_span_id: str agent_name: str tool_name: str call_id: str | None collision: bool = False raw_id: str | None = None class TraceIdRegistry: """Enforces (trace_id, gen_ai.tool.call.id) -> exactly one emitted span.""" def __init__(self) -> None: self._claimed: dict[tuple[str, str], str] = {} def mint(self, trace_id: str, parent_span_id: str, tool_name: str, nonce: str) -> str: # Mint AFTER the invoke decision, scoped to the emitting instance. digest = hashlib.sha256( f"{trace_id}:{parent_span_id}:{tool_name}:{nonce}".encode() ).hexdigest()[:12] return f"call_{digest}" def claim(self, trace_id: str, call_id: str, parent_span_id: str) -> None: key = (trace_id, call_id) if key in self._claimed: raise OrphanedToolCallIdError( f"call_id {call_id!r} in trace {trace_id!r} already claimed by " f"parent {self._claimed[key]!r}; emitting instance {parent_span_id!r} " f"cannot satisfy the uniqueness invariant" ) self._claimed[key] = parent_span_id def emit_tool_call_span( registry: TraceIdRegistry, trace_id: str, parent_span_id: str, agent_name: str, tool_name: str, inherited_call_id: str | None, nonce: str, ) -> ToolCallSpan: """Emit a correlated span, degrade honestly, or refuse when ownership is unknowable.""" if inherited_call_id is not None: # A plan-time inherited id may already be claimed by a sibling worker. try: registry.claim(trace_id, inherited_call_id, parent_span_id) except OrphanedToolCallIdError: # We know the id is taken but not who owns the *effect* of our call. # Refuse rather than emit a degraded span with a possibly-wrong parent. raise OrphanedToolCallIdError( f"cannot prove ownership of effect for inherited id " f"{inherited_call_id!r} on parent {parent_span_id!r}; refusing span" ) return ToolCallSpan( trace_id=trace_id, parent_span_id=parent_span_id, agent_name=agent_name, tool_name=tool_name, call_id=inherited_call_id, ) # Fresh mint scoped to this instance; uniqueness by construction. call_id = registry.mint(trace_id, parent_span_id, tool_name, nonce) registry.claim(trace_id, call_id, parent_span_id) return ToolCallSpan( trace_id=trace_id, parent_span_id=parent_span_id, agent_name=agent_name, tool_name=tool_name, call_id=call_id, ) def fan_out_first_tool(registry: TraceIdRegistry, trace_id: str, workers: list[str]) -> list[ToolCallSpan]: spans = [] for i, parent in enumerate(workers): spans.append( emit_tool_call_span( registry, trace_id=trace_id, parent_span_id=parent, agent_name="worker", tool_name="http_fetch", inherited_call_id="call_7f3a", # pre-minted at plan time nonce=str(i), ) ) return spans if __name__ == "__main__": reg = TraceIdRegistry() try: fan_out_first_tool(reg, "trace_abc", ["span_w1", "span_w2", "span_w3"]) except OrphanedToolCallIdError as exc: # Expected: the second worker cannot prove it owns the inherited id. print(f"refused: {exc}") ```