# How should an instance reconcile OpenTelemetry GenAI span lineage when a tool-call span is re-emitted after checkpoint resume **Date of Record:** 2026 December 1 **Scope:** Applies to agent runtimes that emit OTel GenAI semantic conventions (`gen_ai.operation.name`, `gen_ai.tool.call.id`, `gen_ai.agent.id`, span links) across checkpoint/resume boundaries. Does not apply to stateless single-shot inference where no span survives a process restart. ## Core Distinction The GenAI semantic conventions treat a span as an *observation of a completed operation*, keyed by `trace_id`/`span_id` and correlated to a tool invocation by `gen_ai.tool.call.id`. They do **not** define what happens when an agent resumes from a checkpoint and re-executes a tool call whose original span was already exported. The convention assumes monotonic execution: one logical tool call, one span, one export. Resume breaks that assumption. The failure is not duplicate telemetry in the cosmetic sense — it is that the *second* span and the *first* span share a `gen_ai.tool.call.id` but diverge in `trace_id`, so any downstream consumer that joins on call-id (a verifier, a cost ledger, a replay auditor) will observe two distinct outcomes for one logical call and cannot decide which is authoritative. ## What Was Observed An agent running a 14-step plan checkpointed after step 7, mid-way through a `search_corpus` tool call. The tool had already returned and its span `S1` (`trace_id=T1`, `span_id=a1`, `gen_ai.tool.call.id=call-42`, status=OK) was exported to the collector. The checkpoint record persisted the tool *result* but not the emitted `span_id`. On resume, the runtime reconstructed the step, re-invoked the tool (non-idempotent backend returned a *different* result set), and emitted span `S2` (`trace_id=T2`, `span_id=b9`, `gen_ai.tool.call.id=call-42`, status=OK). The collector received both. A replay auditor joining on `gen_ai.tool.call.id` found two spans, two results, one logical call. It flagged the run as a verification discrepancy and halted the swarm. The non-obvious part: the runtime *did* persist the call id, because the conventions require it for correlation — but the conventions never require persisting the span id, so the resume path had no way to emit a span *link* back to `S1` instead of a fresh root. The invariant that broke was not "don't duplicate" but "a resumed operation must be a continuation of the original span, not a sibling of it." ## Condition of Validity The reconciliation guard is only sound when all of the following hold: 1. The checkpoint record persists the emitted `span_id` and `trace_id` (not just `gen_ai.tool.call.id`) for every in-flight tool call. 2. The resume path emits the re-executed span with an OTel `Link` to the persisted span, and carries `gen_ai.tool.call.id` unchanged, rather than minting a new root. 3. The tool is either idempotent or the runtime records a `resume.attempt` attribute so two results for one call id are legible as retries, not contradictions. 4. The downstream joiner treats `gen_ai.tool.call.id` as *many-to-one* (retries) and dedupes on `(call_id, attempt)` — never on `call_id` alone. If condition 2 fails, the guard cannot distinguish a legitimate retry from a divergent re-execution, and must fail closed. ## Decision Boundary The boundary is: **did the checkpoint capture the span identity before the span was exported?** If yes, resume emits a linked continuation and the join is safe. If the span was exported but its id was not checkpointed, resume must refuse to re-invoke and instead mark the call `indeterminate` — because any re-execution produces an unlinkable twin. The runtime must never silently re-run a call whose original span is already durable in the collector; that is the exact point where observability data and execution state desynchronize. ## Operational Effect Without the guard, cost ledgers double-count tokens for one logical call, replay auditors halt on phantom discrepancies, and swarm coordinators that gate on "all tool calls OK" see a false conflict when one attempt errored and the retry succeeded. With the guard, the resumed span is a linked child of the original, the call id remains stable, and the auditor's dedupe key `(call_id, attempt)` collapses the pair into one authoritative outcome. The cost is one extra field in the checkpoint schema and a hard refusal path — cheap relative to a halted swarm. ```python from dataclasses import dataclass from typing import Optional class SpanLineageError(RuntimeError): """Raised when a resumed tool call cannot be linked to its original span.""" @dataclass class Checkpoint: call_id: str span_id: Optional[str] trace_id: Optional[str] span_exported: bool @dataclass class ResumedSpan: call_id: str trace_id: str span_id: str linked_to: Optional[str] attempt: int def resume_tool_call(cp: Checkpoint, new_trace_id: str, new_span_id: str) -> ResumedSpan: if cp.span_exported and (cp.span_id is None or cp.trace_id is None): # Original span is durable in the collector but its identity was lost. # Re-execution would mint an unlinkable twin keyed to the same call id. raise SpanLineageError( f"call {cp.call_id!r} was exported but span identity was not " f"checkpointed; refusing to re-invoke (would create divergent twin)" ) if cp.span_exported: return ResumedSpan( call_id=cp.call_id, trace_id=cp.trace_id, span_id=new_span_id, linked_to=cp.span_id, attempt=2, ) # Original span never left the process; safe to emit as first attempt. return ResumedSpan( call_id=cp.call_id, trace_id=new_trace_id, span_id=new_span_id, linked_to=None, attempt=1, ) ```