# What happens when an instance emits span attributes that satisfy the schema but violate semantic convention cardinality across a resumed trace **Date of Record:** 2026 November 27 **Scope:** Applies to OpenTelemetry-style GenAI agent telemetry pipelines where spans are emitted per LLM/tool invocation and joined by `trace_id` across process restarts, async workers, or handoff boundaries. Does not apply to single-process, single-span traces or to pipelines that validate only against JSON Schema without semantic convention rules. ## Core Distinction Schema conformance and semantic convention conformance are not the same property, and agent telemetry pipelines routinely conflate them. A span attribute set can pass structural validation (correct types, required keys present, enum values in range) while violating a *cardinality invariant* the semantic convention assumes: that within one trace, a given attribute key identifies the same logical entity across every span that carries it. For GenAI conventions this bites hardest on keys like `gen_ai.conversation.id`, `gen_ai.request.model`, and `gen_ai.agent.id`. The convention assumes each is stable for the lifetime of the trace or the span's parent. An agent that resumes from a checkpoint, rehydrates a partially-distilled memory, or re-enters a tool loop after a timeout can legitimately emit a *different* value for the same key on a later span within the same `trace_id` — and every schema check passes. The failure is not malformed data. It is *semantically divergent data that is structurally valid*, which is the class of defect that conformance test suites are least equipped to catch because each span is validated in isolation. ## What Was Observed A multi-step agent running a retrieval-then-summarize task was checkpointed mid-execution. On resume, the orchestrator reconstructed the agent's working state from an episodic log but re-derived `gen_ai.conversation.id` from a fresh session token rather than from the checkpointed value. The resumed spans carried the new conversation ID; the pre-checkpoint spans carried the old one. All spans shared a single `trace_id` because the orchestrator propagated the trace context correctly. Structural validation passed on every span. The semantic convention conformance suite — which checked presence, type, and enum membership — passed. The defect surfaced only downstream, when the trace assembler tried to group spans by `gen_ai.conversation.id` to compute per-conversation token cost. The single trace split into two conversation buckets, the token accounting double-counted the shared system prompt, and the cost attribution report was silently wrong by roughly the system-prompt size times the number of resumes. A second instance of the same class appeared in tool-loop retries. After a sandbox timeout, the retry path re-instantiated the tool client and emitted a new `gen_ai.tool.call.id` while retaining the parent span's `gen_ai.agent.id`. The convention expects tool call IDs to be unique per call, which held — but the retry also incremented a `gen_ai.usage.input_tokens` counter that the assembler summed across both attempts, inflating the trace's reported input tokens by the size of the retried prompt. Again: every span individually conformant. ## Condition of Validity The cardinality invariant holds only under the conjunction of three conditions, and the pipeline must test all three rather than assuming them: 1. **Trace-scoped key stability.** For every attribute key declared trace-scoped by the convention (conversation ID, agent ID when the agent is singular per trace), all spans sharing a `trace_id` must carry identical values. This is a *cross-span* predicate, not a per-span one, and therefore cannot be checked by a span-level validator. 2. **Attempt-scoped key uniqueness with explicit linkage.** For keys declared per-attempt (tool call ID, request ID), values must be unique within the trace *and* retries must be linked to their originals via an explicit attribute (e.g., `gen_ai.tool.call.retry_of`) so the assembler can deduplicate usage counters rather than sum them. 3. **Resume provenance.** Any span emitted after a checkpoint resume must carry an attribute identifying the resume boundary (e.g., `agent.resume.from_checkpoint`), so downstream consumers can distinguish a legitimate key change from a bug. When any of these fails, the trace is structurally valid but semantically incoherent. The pipeline cannot detect this from individual spans; it must run a trace-level conformance pass after assembly. ## Decision Boundary The boundary between "acceptable divergence" and "conformance violation" is whether the divergence is *declared and linkable*. A conversation ID change across a resume is a violation unless the resume boundary is marked and the change is intentional (e.g., the agent deliberately forked the conversation). A tool call ID change across a retry is acceptable only if the retry is linked and usage counters are marked as attempt-scoped rather than trace-scoped. The decision rule for the conformance test is therefore: - If a trace-scoped key varies across spans within a trace and no resume/fork marker explains it → **fail**. - If a trace-scoped key varies and a marker explains it → **pass, but flag for cost-attribution deduplication**. - If an attempt-scoped key is duplicated without a retry link → **fail** (ambiguous provenance). - If an attempt-scoped key is unique but usage counters are summed without dedup → **fail at the assembler, not the span validator**. The last rule is the one most often missed: the conformance test must extend past span validation into the aggregation layer, because that is where the semantic damage actually occurs. ## Operational Effect Pipelines that validate only per-span will pass these traces indefinitely and produce silently wrong cost, latency, and token accounting — the kind of error that is invisible until a budget alarm fires or a customer disputes a bill. The fix is not stricter schema validation; it is a trace-level conformance pass that enforces the three conditions above and raises on undeclared divergence. Concretely: assemble the trace, group by trace-scoped keys, assert single-valuedness, check retry linkage, and deduplicate usage before aggregation. This pass belongs in the pipeline between span ingestion and the metrics backend, and it must run on resumed and retried traces specifically, because those are the only traces where the invariant is at risk. The following reference check encodes the trace-level predicate and the specific failure it guards against. ```python from collections import defaultdict from dataclasses import dataclass, field class SemanticConventionViolation(RuntimeError): """Raised when a trace is structurally valid but violates a cross-span cardinality invariant declared by the GenAI semantic convention.""" pass @dataclass class Span: trace_id: str name: str attributes: dict resume_marker: bool = False TRACE_SCOPED_KEYS = ("gen_ai.conversation.id", "gen_ai.agent.id") ATTEMPT_SCOPED_KEYS = ("gen_ai.tool.call.id", "gen_ai.request.id") def check_trace_conformance(spans: list[Span]) -> dict: """Enforce trace-scoped key stability and attempt-scoped linkage. Returns a deduplicated usage summary or raises SemanticConventionViolation.""" if not spans: return {} trace_ids = {s.trace_id for s in spans} if len(trace_ids) != 1: raise SemanticConventionViolation( f"expected single trace, got {trace_ids}" ) # Condition 1: trace-scoped keys must be single-valued unless a resume # marker explains the divergence. for key in TRACE_SCOPED_KEYS: values = defaultdict(list) for s in spans: if key in s.attributes: values[s.attributes[key]].append(s) if len(values) > 1: explained = all( any(sp.resume_marker for sp in group) for group in values.values() ) if not explained: raise SemanticConventionViolation( f"trace-scoped key {key!r} diverges across spans " f"{[v for v in values]} with no resume marker" ) # Condition 2: attempt-scoped keys must be unique or explicitly linked. seen_attempts = {} for s in spans: for key in ATTEMPT_SCOPED_KEYS: val = s.attributes.get(key) if val is None: continue if val in seen_attempts: retry_of = s.attributes.get("gen_ai.tool.call.retry_of") if retry_of != val: raise SemanticConventionViolation( f"duplicate attempt-scoped {key}={val!r} without " f"retry_of linkage" ) seen_attempts[val] = s # Condition 3: deduplicate usage counters across retries before summing. usage = defaultdict(int) counted = set() for s in spans: attempt = s.attributes.get("gen_ai.tool.call.id") if attempt and attempt in counted: continue if attempt: counted.add(attempt) usage["input_tokens"] += s.attributes.get("gen_ai.usage.input_tokens", 0) usage["output_tokens"] += s.attributes.get("gen_ai.usage.output_tokens", 0) return dict(usage) ```