# Where must an instance reject a GenAI span whose parent-child timing inverts across a tool-call boundary, and how does the OpenTelemetry GenAI semantic convention model fail to encode the causal invariant? **Date of Record:** 2026 November 29 **Scope:** Applies to any agent runtime that emits OpenTelemetry GenAI spans (`gen_ai.*`) for agent turns and tool calls under a single trace, where child spans are closed out-of-order relative to parent turn spans across asynchronous tool dispatch. Does not apply to single-shot inference calls without tool invocation, nor to runtimes using a strictly synchronous span stack with no cross-process tool transport. ## Core Distinction The GenAI semantic conventions model a trace as a tree of spans keyed by `trace_id`/`span_id`/`parent_span_id`, and they prescribe attributes such as `gen_ai.operation.name` (`chat`, `execute_tool`, `invoke_agent`), `gen_ai.tool.name`, and `gen_ai.usage.input_tokens`. What they do **not** encode is a causal ordering invariant: the convention says nothing about whether a child `execute_tool` span's `end_time_unix_nano` may precede its parent `chat` span's `start_time_unix_nano`, nor whether a tool-call span may be re-parented after the fact. The distinction that matters operationally is between **structural parentage** (the `parent_span_id` field) and **temporal containment** (child interval ⊆ parent interval). The GenAI conventions bind only the former. A trace can therefore be structurally valid, pass every schema validator, and still be causally impossible — the tool span finishes before the agent turn that dispatched it began. That is the boundary: the model has no invariant that forbids it, so the runtime must supply one. ## What Was Observed A multi-step agent loop (`invoke_agent` → `chat` → `execute_tool` → `chat`) was instrumented with the GenAI conventions. Tool dispatch was async: the runtime emitted the `execute_tool` span from a worker pool and the `chat` span from the orchestrator. Under load, the following trace shape appeared repeatedly in the collector: - `chat` span (turn 2), `start_time = T0`, `end_time = T5`, `parent_span_id = invoke_agent`. - `execute_tool` span, `start_time = T1`, `end_time = T2`, `parent_span_id = chat(turn 2)`. - A second `chat` span (turn 3) with `start_time = T3` — i.e., turn 3 begins *before* turn 2's tool span has ended, because the orchestrator had already fired the next turn on a speculative path while the tool worker pool was still retrying. The inversion: the tool span's `end_time` (T2) was captured with the worker's monotonic clock, but the `chat` span's `start_time` (T0) came from the orchestrator's clock on a different host. Clock skew of ~40ms on the worker made `execute_tool.end_time < chat.start_time` for a subset of spans. Every span was individually well-formed and carried the correct `gen_ai.*` attributes. The trace passed the collector's schema check. It failed only when a downstream replay engine — which reconstructs agent state by replaying tool results in span-end order — consumed the tool result *before* the turn that produced the tool call, producing a hallucinated argument binding on turn 3. The GenAI conventions gave us no signal. `gen_ai.operation.name` was present; `parent_span_id` was correct; the only anomaly was temporal, and the spec treats timestamps as descriptive metadata, not as a constraint to be validated. ## Condition of Validity The failure is valid — meaning the runtime *must* reject the span — under the conjunction of: 1. The trace is declared as a single agent execution (one `invoke_agent` root with `gen_ai.agent.name`). 2. A child span carries `parent_span_id` pointing to a `chat` or `invoke_agent` span in the same trace. 3. The child's `[start, end]` interval is not contained within the parent's `[start, end]` interval on the **normalized** clock. 4. The runtime or replay engine relies on span ordering (end-order or start-order) to reconstruct tool-call causality — i.e., it does not carry an explicit sequence token. If (4) is false — the replay engine keys off an explicit `gen_ai.tool.call.id` or a monotonic sequence attribute rather than timestamps — the inversion is cosmetic and need not be rejected. The boundary is exactly where ordering is inferred from time rather than from an explicit causal token. ## Decision Boundary The decision is *not* "reject any span where child.end > parent.end." Legitimate async tool calls can outlive the turn that dispatched them when the agent architecture allows overlapping turns (speculative execution, parallel tool fan-out). The boundary is: - **Reject** when the child interval does not *contain-intersect* the parent interval and the trace declares sequential turns (no `gen_ai.sequence` token). Intersection is the minimum temporal invariant: a tool call dispatched by a turn must overlap that turn in real time. - **Accept with annotation** when intervals intersect but the child extends past the parent's end (async fan-out) — record `gen_ai.tool.async_outlives_turn = true` so replay engines know not to trust end-order. - **Reject unconditionally** when `parent_span_id` references a span that has already been closed *and* the child's start precedes the parent's start — this is the clock-skew signature and cannot be reconciled by annotation. The guardrail is: normalize all span timestamps to a single reference clock (via `otel.trace.clock_skew_ns` if derivable, else reject cross-host parentage without an explicit sequence token), then enforce interval intersection at ingest. ## Operational Effect Without the guardrail, the GenAI trace is a structurally faithful but causally false record. Replay engines that trust end-order silently corrupt agent state on resume — the cold-start reconstruction binds a tool result to the wrong turn, and the agent's next `chat` call reasons over a poisoned context. The corruption is non-deterministic and load-dependent (it appears only under clock skew or worker-pool backpressure), so it evades staging tests. With the guardrail, the runtime either rejects the inverted span at ingest (surfacing the skew as an operational error rather than a silent state bug) or annotates the async-outlives case so downstream replay switches to explicit sequence tokens. The invariant the GenAI conventions leave unstated — *a tool-call span must temporally intersect the turn span that dispatched it, on a normalized clock* — becomes a hard precondition on trace admission. ```python import time from dataclasses import dataclass class GenAISpanCausalityError(RuntimeError): """Raised when a GenAI child span violates the temporal containment invariant.""" pass @dataclass class Span: span_id: str parent_span_id: str | None operation: str # gen_ai.operation.name start_ns: int end_ns: int clock_skew_ns: int = 0 # host skew vs. reference clock def normalize(span: Span) -> Span: # Shift onto the reference clock; positive skew means host ran ahead. return Span( span_id=span.span_id, parent_span_id=span.parent_span_id, operation=span.operation, start_ns=span.start_ns - span.clock_skew_ns, end_ns=span.end_ns - span.clock_skew_ns, clock_skew_ns=span.clock_skew_ns, ) def admit_trace(spans: list[Span], sequential_turns: bool) -> list[Span]: by_id = {s.span_id: normalize(s) for s in spans} admitted: list[Span] = [] for s in by_id.values(): if s.parent_span_id is None: admitted.append(s) continue parent = by_id.get(s.parent_span_id) if parent is None: raise GenAISpanCausalityError( f"span {s.span_id} ({s.operation}) references missing parent " f"{s.parent_span_id}; cannot verify causality" ) # Invariant: child must temporally intersect its parent. intersects = s.start_ns <= parent.end_ns and s.end_ns >= parent.start_ns if not intersects: raise GenAISpanCausalityError( f"span {s.span_id} ({s.operation}) interval " f"[{s.start_ns},{s.end_ns}] does not intersect parent " f"{parent.span_id} [{parent.start_ns},{parent.end_ns}] after " f"skew normalization ({s.clock_skew_ns}ns); rejecting as " f"causally impossible" ) # Sequential turn declared but child predates parent's start = skew signature. if sequential_turns and s.start_ns < parent.start_ns: raise GenAISpanCausalityError( f"span {s.span_id} starts {parent.start_ns - s.start_ns}ns " f"before its sequential parent {parent.span_id}; unreconcilable " f"clock skew, refusing admission" ) # Async fan-out: child outlives parent's end — annotate, don't reject. if s.end_ns > parent.end_ns: s = Span(**{**s.__dict__, "operation": s.operation}) # caller should set gen_ai.tool.async_outlives_turn = True admitted.append(s) return admitted def ingest(raw_spans: list[Span], sequential_turns: bool = True) -> list[Span]: try: return admit_trace(raw_spans, sequential_turns) except GenAISpanCausalityError: # Surface as operational error, never silently drop. raise ```