# When must an instance abort a resumed agent span because OpenTelemetry GenAI token-usage attributes disagree across a checkpoint boundary **Date of Record:** 2026 November 20 **Scope:** Applies to agents that emit `gen_ai.*` spans across a durable checkpoint/resume boundary and reconcile token accounting from span attributes after the fact. Does not apply to single-shot, in-process inference where one span covers the entire model call with no resume. ## Core Distinction The OpenTelemetry GenAI semantic conventions describe *what a span reports about one model invocation*: `gen_ai.usage.input_tokens`, `gen_ai.usage.output_tokens`, `gen_ai.request.model`, `gen_ai.response.finish_reasons`, and the parent/child structure linking an agent span (`gen_ai.operation.name = "invoke_agent"`) to its tool-call spans (`execute_tool`). They do **not** define what happens when an agent is checkpointed mid-task and resumed in a *new* process that re-emits a continuation span for the *same logical operation*. That gap is the boundary. The conventions are per-invocation and additive-by-implication; the agent runtime is per-task and cumulative-by-necessity. A resumed agent that naively re-emits `gen_ai.usage.*` on the continuation span either (a) double-counts the pre-checkpoint tokens, or (b) reports only the delta and silently under-counts the logical operation. Both are schema-valid. Neither is detectable from a single span. The failure only appears when a downstream reconciler sums spans by `gen_ai.operation.name` and compares against a budget or a billing ledger. The non-obvious invariant: **a `gen_ai.usage.*` attribute is a claim about tokens consumed *within that span's wall-clock interval*, not about the logical operation the span participates in.** Any consumer that treats it as the latter across a resume boundary will drift. ## What Was Observed An `invoke_agent` task was checkpointed after step 7 of 12 (context serialized, tool results persisted, span closed with `finish_reasons=["checkpoint"]`). The resume process cold-started, rehydrated the transcript, and opened a continuation span with the same `gen_ai.conversation.id` and a new `trace_id` (the tracer provider was re-initialized, so the parent link was lost — a separate but compounding defect). Observed attribute set on the continuation span: ``` gen_ai.operation.name = "invoke_agent" gen_ai.request.model = "claude-sonnet-4-5" gen_ai.usage.input_tokens = 41200 # full rehydrated context, re-sent gen_ai.usage.output_tokens = 1900 gen_ai.conversation.id = "conv-9f2a" ``` The pre-checkpoint span had reported `input_tokens = 38000`. The rehydrated context was 41,200 tokens because the checkpoint serialized tool outputs verbatim and the resume prompt added a "you are resuming" preamble. The logical operation consumed 38,000 (steps 1–7) + 41,200 (steps 8–12, re-sending history) = 79,200 input tokens. A reconciler summing `input_tokens` across both spans by `conversation.id` got 79,200 — correct by accident. A reconciler summing by `trace_id` got only 41,200 — under-counted by 48%. A reconciler that deduplicated on `conversation.id` (assuming one logical operation = one accounting unit) got 41,200 — also wrong. The three reconcilers disagreed by 48% on the same span data. The schema was satisfied in all three cases. ## Condition of Validity The double-count/under-count ambiguity is *bounded* — and the span is safe to consume — only when the continuation span carries an explicit resume marker that lets a consumer reconstruct the interval semantics. The minimum viable marker set: - `gen_ai.conversation.id` present and stable across the boundary (already conventional). - A custom `agent.resume.from_checkpoint = true` boolean on the continuation span. - `agent.checkpoint.seq` (monotonic integer) on both the pre-checkpoint and continuation spans, so the reconciler can order them and detect gaps. - `gen_ai.usage.input_tokens` documented — via a span-level `agent.usage.scope` attribute set to `"interval"` — as covering only the continuation interval. Without `agent.usage.scope`, the attribute is semantically ambiguous and must be treated as unusable for cumulative accounting. This is the condition of validity: **the resume marker set is present and the usage scope is declared, or the span is not reconcilable.** The invariant to enforce at emit time: a continuation span MUST NOT be emitted with `gen_ai.usage.*` unless `agent.usage.scope` is also set. A span that violates this is a *poisoned accounting record* — it looks valid, sums cleanly, and produces a silently wrong total. ## Decision Boundary The decision an instance must make on resume: 1. **If the checkpoint is lossless and the runtime re-sends the full history** (the observed case): the continuation span's `input_tokens` is the *full* rehydrated context, not a delta. Set `agent.usage.scope = "interval"`, emit `agent.resume.from_checkpoint = true`, and let the reconciler sum. Do not attempt to subtract the pre-checkpoint tokens — the re-send is a real cost. 2. **If the checkpoint uses prefix caching and the provider bills only the uncached suffix**: `gen_ai.usage.input_tokens` still reports the full context length per the conventions (it is a length, not a bill). Billing reconciliation must use provider-specific cached-token attributes, which are *not* in the GenAI conventions. This is a known gap; do not infer billing from `input_tokens`. 3. **If the resume process cannot recover the `conversation.id` or the checkpoint sequence number**: the continuation span is unreconcilable. The correct action is to **abort the span** (do not export it as a normal `invoke_agent` span) and emit a diagnostic span with `gen_ai.operation.name = "invoke_agent"` plus `agent.accounting.status = "unreconcilable"`. Exporting it as a normal span pollutes the ledger. The boundary is sharp: a span either carries the resume marker set and is reconcilable, or it is aborted. There is no "best effort" middle state that is safe to export. ## Operational Effect Downstream effects of getting this wrong, in order of latency to detection: - **Budget enforcement**: a per-conversation token budget summed by `trace_id` under-counts after every resume, so the budget never trips and the agent runs until the provider hard-limits it. Detection latency: one billing cycle. - **Cost attribution**: per-tenant cost reports under-report resumed conversations by the pre-checkpoint fraction. Detection latency: audit. - **Anomaly detection**: a resumed agent's token-per-step ratio jumps (41,200 input for 5 steps vs. 38,000 for 7 steps) and trips a naive outlier alert. False positive. Detection latency: immediate, but misdiagnosed as model misbehavior. - **Trace reconstruction**: if `trace_id` is regenerated on resume (the compounding defect), the agent's causal chain is severed; a postmortem cannot see that steps 8–12 followed steps 1–7. This is the worst failure because it is invisible until an incident review. The architectural guardrail: the checkpoint serializer must persist `trace_id`, `span_id` of the last closed span, `conversation.id`, and `agent.checkpoint.seq`. The resume process must restore the tracer context (or explicitly link via span links if the tracer cannot be restored) and must set `agent.usage.scope` before any `gen_ai.usage.*` attribute is written. Any resume path that cannot satisfy these must fail closed — abort the span, do not export a plausible-looking one. ```python from dataclasses import dataclass, field from typing import Optional class UnreconcilableSpanError(RuntimeError): """Raised when a resumed agent span cannot be safely exported for accounting.""" @dataclass class Checkpoint: trace_id: str last_span_id: str conversation_id: str checkpoint_seq: int input_tokens_so_far: int @dataclass class ContinuationSpan: trace_id: Optional[str] conversation_id: Optional[str] checkpoint_seq: Optional[int] gen_ai_usage_input_tokens: Optional[int] = None gen_ai_usage_output_tokens: Optional[int] = None usage_scope: Optional[str] = None # must be "interval" if usage set resume_from_checkpoint: bool = False span_links: list = field(default_factory=list) def build_continuation_span( checkpoint: Checkpoint, restored_trace_id: Optional[str], rehydrated_input_tokens: int, output_tokens: int, ) -> ContinuationSpan: span = ContinuationSpan( trace_id=restored_trace_id, conversation_id=checkpoint.conversation_id, checkpoint_seq=checkpoint.checkpoint_seq + 1, resume_from_checkpoint=True, ) # Invariant 1: trace continuity. If the tracer could not be restored, # we must link explicitly rather than silently orphan the span. if restored_trace_id is None: span.span_links.append( {"linked_trace_id": checkpoint.trace_id, "linked_span_id": checkpoint.last_span_id} ) # Orphaned trace_id is not itself fatal, but it must be recorded. span.trace_id = None # Invariant 2: usage scope must be declared before usage is written. span.gen_ai_usage_input_tokens = rehydrated_input_tokens span.gen_ai_usage_output_tokens = output_tokens span.usage_scope = "interval" # Invariant 3: reconcilability gate. A span with usage but no scope, # or with a broken checkpoint sequence, must not be exported as-is. if span.gen_ai_usage_input_tokens is not None and span.usage_scope != "interval": raise UnreconcilableSpanError( f"usage attributes set without agent.usage.scope on " f"conversation={checkpoint.conversation_id} seq={span.checkpoint_seq}" ) if span.checkpoint_seq != checkpoint.checkpoint_seq + 1: raise UnreconcilableSpanError( f"checkpoint sequence gap: expected {checkpoint.checkpoint_seq + 1}, " f"got {span.checkpoint_seq} for conversation={checkpoint.conversation_id}" ) if span.conversation_id is None: raise UnreconcilableSpanError( "continuation span missing gen_ai.conversation.id; " "cannot reconcile against pre-checkpoint usage" ) return span def export_for_accounting(span: ContinuationSpan) -> dict: # Fail closed: never hand a poisoned record to the ledger. if span.gen_ai_usage_input_tokens is not None and span.usage_scope != "interval": raise UnreconcilableSpanError( f"refusing to export span with undeclared usage scope: " f"conversation={span.conversation_id}" ) return { "gen_ai.operation.name": "invoke_agent", "gen_ai.conversation.id": span.conversation_id, "gen_ai.usage.input_tokens": span.gen_ai_usage_input_tokens, "gen_ai.usage.output_tokens": span.gen_ai_usage_output_tokens, "agent.usage.scope": span.usage_scope, "agent.resume.from_checkpoint": span.resume_from_checkpoint, "agent.checkpoint.seq": span.checkpoint_seq, "span_links": span.span_links, } ```