# What structural signals indicate span-parenting corruption when a tool-call span and its agent-handoff sibling race under OpenTelemetry GenAI semantic conventions **Date of Record:** 2026 November 26 **Scope:** Applies to instrumented agent runtimes that emit OTel GenAI spans (`gen_ai.*` attributes) for tool invocations and inter-agent handoffs, where a single logical turn can produce concurrent child spans under one active span context. Does not apply to single-threaded, strictly sequential tool loops or to systems that emit one span per turn with no handoff decomposition. ## Core Distinction The GenAI semantic conventions define *what* attributes a span must carry (`gen_ai.operation.name`, `gen_ai.request.model`, `gen_ai.usage.input_tokens`, `gen_ai.usage.output_tokens`, `gen_ai.tool.name`, `gen_ai.agent.name`) but they deliberately do **not** specify span *parenting topology* for the case where a tool call and a handoff are emitted from the same logical turn. This gap is not cosmetic. Two instrumentations that both "comply" with the conventions can produce structurally incompatible traces: one nests the tool span under the handoff span (serialized causality), the other parents both directly under the turn span (parallel causality). The distinction that matters operationally is **whether the parent-child edge encodes causal ordering or merely co-invocation**. When a runtime emits the tool-call span and the handoff span concurrently from a shared context, and the tool call completes *after* the handoff has already transferred the baton, the trace's parent edges assert an ordering that the execution history contradicts. Token accounting then attributes the tool's `output_tokens` to the wrong agent's subtree, and the receiving agent's cold-start reconstruction of "what did my predecessor already do" reads an incomplete trace. ## What Was Observed A two-agent runtime (planner → executor) emitted, per turn, a `gen_ai.turn` span, a `gen_ai.tool.call` span for a retrieval tool, and a `gen_ai.agent.handoff` span. Both children were created from the turn's `Context`, so both had `parent_span_id == turn.span_id`. The retrieval tool was async; the handoff was dispatched as soon as the planner's final message was emitted, without awaiting the tool future. In the trace store, `handoff` closed at t=410ms, `tool.call` closed at t=1180ms. Three structural signals appeared together in the corrupted traces: 1. **Overlapping child intervals under a common parent.** `handoff.start < tool.call.start` and `tool.call.end > handoff.end`, with neither span a descendant of the other. The GenAI conventions have no field to express "this tool result was not available to the agent that received the baton," so the overlap is the only signal. 2. **Token attribution leakage.** The executor's subtree summed `gen_ai.usage.output_tokens` to a value that included the retrieval tool's output tokens, because the tool span was a sibling of the handoff and downstream rollups used `parent_span_id` subtree aggregation. The executor's reconstruction of its own budget was inflated by ~14% per turn, compounding across a 9-turn task. 3. **Dangling handoff payload reference.** The handoff span carried `gen_ai.handoff.context_ref` pointing at a serialized scratchpad that referenced the tool call by span ID. At handoff time the tool span had not closed, so the scratchpad recorded the tool as `pending`. The executor, on cold start, treated the referenced result as absent and re-issued the retrieval — a duplicate tool invocation whose span was parented under the *executor*, splitting one logical retrieval across two subtrees. The compounding failure was not a crash. Every span was well-formed and every required `gen_ai.*` attribute was present. The trace was *schema-valid and semantically false*. ## Condition of Validity The invariant that must hold for GenAI span parenting to be trustworthy: > For any span `S` carrying `gen_ai.operation.name = "tool.call"` or `"agent.handoff"`, if `S` is a sibling of another GenAI span `T` under a common parent, then either (a) `S` and `T` do not overlap in time, or (b) `S` carries an explicit `gen_ai.tool.result_available_at` (or equivalent) attribute and consumers MUST NOT aggregate `gen_ai.usage.*` across siblings without honoring that availability boundary. Absent (a) or (b), sibling parenting is indistinguishable from serialized causality, and any consumer performing subtree token rollup or handoff-context reconstruction will read a false history. The condition is violated precisely when a tool future is not awaited before the handoff is emitted — the common "fire the retrieval, ship the baton" optimization. ## Decision Boundary The boundary is **whether the handoff depends on the tool result**. If the planner's handoff message is constructed without reading the tool output (speculative handoff), the two spans are genuinely parallel and sibling parenting is correct — but the handoff span MUST then be marked `gen_ai.handoff.speculative = true` and MUST NOT carry a `context_ref` to the pending tool. If the handoff message *does* incorporate the tool result, the tool span MUST be closed and reparented as an ancestor of the handoff span (or the handoff MUST be deferred until the tool future resolves). The failure mode lives in the unmarked middle: a handoff that is *de facto* dependent on a tool result but emitted before that result exists, with neither the speculative flag nor the causal edge to signal the dependency. This is the boundary an auditor checks first: for every handoff span, is there an unawaited tool sibling whose result appears in the handoff payload? ## Operational Effect Downstream, the corrupted topology produces three compounding effects. First, **token accounting drift**: subtree rollups overcount the receiving agent and undercount the sending agent, so per-agent budget enforcement misallocates headroom and the executor hits its token ceiling mid-task while the planner's ledger shows slack. Second, **cold-start amnesia amplification**: the executor's episodic reconstruction reads the handoff `context_ref`, sees `pending`, and re-derives state that the planner already computed — duplicating tool calls and, in the retrieval case, producing two divergent result sets that the executor must reconcile with no signal that they came from the same logical query. Third, **verification replay divergence**: when an auditor replays the trace to check the executor's decisions, the replay sees the tool result as available at handoff time (because the span is a sibling, present in the trace) and flags the executor's re-issuance as redundant — a false positive against an agent that was, from its own vantage, correct. The guardrail is a span-closure barrier at the handoff emission point: no handoff span may be emitted while a sibling tool span that it references remains open, and the instrumentation must either await or mark speculative. Enforcement at emit time is the only point where the causal truth is still available; after the trace is written, the overlap is a forensic hint, not a recoverable fact. ```python from dataclasses import dataclass, field from typing import Optional class HandoffTopologyError(RuntimeError): """Raised when a GenAI handoff span is emitted while a referenced tool span is still open.""" @dataclass class GenAISpan: span_id: str parent_span_id: Optional[str] operation_name: str # "tool.call" | "agent.handoff" | "turn" start_ms: float end_ms: Optional[float] = None attributes: dict = field(default_factory=dict) context_ref: Optional[str] = None # span_id referenced by a handoff payload @property def is_open(self) -> bool: return self.end_ms is None def validate_handoff_emission(handoff: GenAISpan, siblings: list[GenAISpan]) -> None: if handoff.operation_name != "agent.handoff": return if handoff.attributes.get("gen_ai.handoff.speculative") is True: if handoff.context_ref is not None: raise HandoffTopologyError( f"speculative handoff {handoff.span_id} must not carry context_ref " f"to a pending tool (got {handoff.context_ref})" ) return for sib in siblings: if sib.span_id == handoff.span_id: continue if sib.operation_name != "tool.call": continue referenced = handoff.context_ref == sib.span_id overlapping = sib.is_open or (sib.end_ms is not None and sib.end_ms > handoff.start_ms) if referenced and sib.is_open: raise HandoffTopologyError( f"handoff {handoff.span_id} references tool {sib.span_id} " f"which is still open at emission (t={handoff.start_ms}ms); " f"await the tool future or mark gen_ai.handoff.speculative=true" ) if overlapping and not referenced and sib.parent_span_id == handoff.parent_span_id: raise HandoffTopologyError( f"handoff {handoff.span_id} shares parent {handoff.parent_span_id} " f"with overlapping tool {sib.span_id}; sibling token rollup will " f"misattribute gen_ai.usage.* across agents" ) ```