# In what scenarios must an instance reconcile OTel GenAI agent spans when tool-call lineage, token accounting, and model provenance disagree across a resumed run **Date of Record:** 2026 November 23 **Scope:** Applies to any agent runtime that emits OpenTelemetry spans under the GenAI semantic conventions (`gen_ai.*`) and performs mid-task checkpoint/resume, where a single logical agent run is split across two or more process lifetimes. Does not cover single-lifetime, non-resumed runs, nor spans emitted purely for offline evaluation where lineage closure is not required for billing or audit. ## Core Distinction The GenAI semantic conventions treat a span as an *observation* of a single execution attempt: `gen_ai.operation.name`, `gen_ai.request.model`, `gen_ai.usage.input_tokens`, `gen_ai.usage.output_tokens`, and tool-call attributes (`gen_ai.tool.name`, `gen_ai.tool.call.id`) are all scoped to the emitting process. They are not, and were never designed to be, a *ledger* of a logical run that spans process deaths. This is the boundary. A resumed agent run produces a second tree of spans whose root is a new `gen_ai.operation.name=invoke_agent` span, with no structural parent linking it to the pre-crash tree except a `trace_id` that the runtime must carry forward manually. When the runtime carries the `trace_id` forward but re-emits tool-call spans for tools that already executed, the collector sees two `gen_ai.tool.call.id` values that are semantically the same call but syntactically distinct, and two token-usage records that both count toward the same logical completion. The invariant that breaks is **lineage closure under process death**: every `gen_ai.tool.call.id` in a trace must correspond to exactly one physical tool invocation, and every `gen_ai.usage.*_tokens` value must be attributed to exactly one model response. ## What Was Observed A tool-using agent (planner → `search_docs` → `write_file` → `verify`) was checkpointed after the `search_docs` tool returned but before the result was committed to durable memory. The process was killed by an OOM reaper. On resume, the runtime: 1. Re-read the checkpoint, which contained the planner message history but not the tool result (the result was in an in-memory buffer). 2. Re-executed `search_docs` with a new `gen_ai.tool.call.id` (a fresh UUID per attempt, per convention guidance that call IDs be unique per invocation). 3. Emitted a new `invoke_agent` root span with the *same* `trace_id` but a new `span_id`, and re-emitted the planner's LLM call as a child. The resulting trace contained: - Two `gen_ai.tool.name=search_docs` spans with different `gen_ai.tool.call.id`, both parented under different agent roots, both carrying `gen_ai.usage.*` from the *planner* call that preceded them (the runtime attributed planner tokens to the tool span because the tool span was the nearest child in its emission order). - A `gen_ai.request.model` of `gpt-4o-2024-08-06` on the first tree and `gpt-4o` on the second, because the resume path resolved the model alias freshly and the alias had rolled forward between lifetimes. - Total `gen_ai.usage.input_tokens` across the trace of 1.8× the true logical input, because the planner prompt was re-sent and re-counted. The billing reconciliation job, which summed `gen_ai.usage.*` per `trace_id`, overcharged the run by 80%. The audit job, which assumed `gen_ai.tool.call.id` uniqueness within a trace, flagged the trace as corrupt and dropped it, so the run had no lineage record at all. ## Condition of Validity The naive reconciliation — sum token usage per `trace_id`, dedupe tool calls by `gen_ai.tool.call.id` — is valid **only if** the following holds for the trace: - Exactly one `invoke_agent` root span exists per `trace_id`, **or** every additional root span carries an explicit `gen_ai.agent.resume_of` (or equivalent) attribute pointing at the prior root's `span_id`. - Every `gen_ai.tool.call.id` is globally unique across the whole trace, **and** re-executed tools after resume carry a `gen_ai.tool.retry_of` attribute referencing the abandoned call ID, so the collector can collapse them. - `gen_ai.request.model` is resolved to a pinned version string, not an alias, at emission time, so model provenance is stable across lifetimes. When any of these fails, the trace is **not reconcilable by summation** and must be treated as a *set of attempts* rather than a single execution. The correct invariant is not "one trace = one run" but "one trace = one or more attempts, each attempt self-contained, joined by explicit resume edges." ## Decision Boundary The runtime must decide, at resume time and before emitting any span, whether it is in **replay** mode (the tool result is recoverable from durable state) or **re-execute** mode (the result is lost and the tool must run again). This decision determines the span shape: - **Replay:** emit a span with `gen_ai.tool.call.id` equal to the original, plus `gen_ai.tool.replayed=true`. Do not emit `gen_ai.usage.*` on the replayed tool span — the tokens were already counted. Parent it under the *original* agent root via a link (`SpanLink`), not a parent, so the original tree stays closed. - **Re-execute:** emit a new `gen_ai.tool.call.id`, set `gen_ai.tool.retry_of` to the abandoned ID, and parent it under the *new* agent root. Count its tokens fresh. The reconciliation job must then sum only spans where `retry_of` is absent or points to a span outside the trace. The boundary is crossed when the runtime cannot determine which mode it is in — e.g., the checkpoint is present but the tool-result store is partitioned and unreachable. In that case the safe default is **re-execute with `retry_of` set**, never replay-without-link, because replay without a link produces a trace that passes dedupe but silently loses the fact that a physical call happened twice (which matters for rate-limit accounting and for tools with side effects). ## Operational Effect The practical consequence is that GenAI span trees from resumed runs are **not summable** and must be reconciled by a lineage-aware reducer that: 1. Groups spans by `trace_id`. 2. Identifies attempt roots (spans with `gen_ai.operation.name=invoke_agent` and no parent). 3. Builds an attempt DAG using `gen_ai.agent.resume_of` and `gen_ai.tool.retry_of` edges. 4. Sums `gen_ai.usage.*` only over the *latest* attempt in each DAG branch, and only over spans whose `gen_ai.tool.call.id` is not referenced by any `retry_of`. 5. Fails closed (emits a reconciliation error span, does not bill) if any attempt root lacks a resume edge or any `retry_of` points to an unknown ID. Without this reducer, every resumed run is a latent billing and audit defect. The OTel conventions give you the attributes to express the reconciliation; they do not give you the reducer, and the default collector behavior (sum per trace, dedupe by call ID) is exactly the wrong reducer for this boundary. ```python from dataclasses import dataclass, field from typing import Optional class LineageReconciliationError(RuntimeError): """Raised when a GenAI trace cannot be reconciled under resume semantics.""" @dataclass class GenAISpan: span_id: str trace_id: str parent_span_id: Optional[str] operation: str tool_call_id: Optional[str] = None retry_of: Optional[str] = None resume_of: Optional[str] = None input_tokens: int = 0 output_tokens: int = 0 model: Optional[str] = None def reconcile_trace(spans: list[GenAISpan]) -> dict: """Sum token usage over a resumed GenAI trace, honoring retry/resume edges. Raises LineageReconciliationError if the trace is not reconcilable. """ by_id = {s.span_id: s for s in spans} if len(by_id) != len(spans): raise LineageReconciliationError("duplicate span_id in trace") roots = [s for s in spans if s.parent_span_id is None and s.operation == "invoke_agent"] if not roots: raise LineageReconciliationError("no invoke_agent root span") # Every non-primary root must declare a resume edge to a known span. primary = [r for r in roots if r.resume_of is None] if len(primary) != 1: raise LineageReconciliationError( f"expected exactly one primary root, found {len(primary)}" ) for r in roots: if r.resume_of is not None and r.resume_of not in by_id: raise LineageReconciliationError( f"resume_of points to unknown span {r.resume_of}" ) # Any retry_of must reference a known, distinct span. for s in spans: if s.retry_of is not None and s.retry_of not in by_id: raise LineageReconciliationError( f"retry_of points to unknown span {s.retry_of}" ) # Model provenance must be pinned (no alias) on every span that counts tokens. for s in spans: if (s.input_tokens or s.output_tokens) and s.model is None: raise LineageReconciliationError( f"span {s.span_id} counts tokens without gen_ai.request.model" ) if s.model is not None and s.model.count("-") < 2: raise LineageReconciliationError( f"span {s.span_id} model {s.model!r} is an unpinned alias" ) retried_ids = {s.retry_of for s in spans if s.retry_of is not None} total_in = total_out = 0 for s in spans: if s.tool_call_id is not None and s.tool_call_id in retried_ids: continue # superseded by a retry; do not double-count total_in += s.input_tokens total_out += s.output_tokens return {"trace_id": spans[0].trace_id, "input_tokens": total_in, "output_tokens": total_out} ```