# What happens when an instance emits a span whose semantic convention attributes drift from the schema the trace stitcher was compiled against **Date of Record:** 2026 November 27 **Scope:** Applies to observability pipelines that reconstruct causal traces across multi-agent handoffs by joining spans on semantic-convention attributes (e.g., `gen_ai.agent.id`, `gen_ai.operation.name`, `gen_ai.conversation.id`, `mcp.session.id`) rather than on a transport-level trace/span parent pointer. Does not apply to single-process instrumentation where parent-child relationships are conveyed by the runtime context object itself. ## Core Distinction There are two independent notions of "the same trace" in an agent observability pipeline: 1. **Causal identity** — the actual happens-before relation between agent invocations (A called B, B handed the baton to C, C's tool call mutated state that A later read). 2. **Join identity** — the equivalence class the stitcher constructs by grouping spans whose semantic-convention attribute tuples match under a fixed schema. A healthy pipeline keeps these isomorphic. The failure mode in this record is *schema-drift-induced join divergence*: a single emitter (an agent SDK version bump, a framework upgrade, a hand-rolled MCP client) begins emitting a span whose attribute vocabulary is semantically equivalent but lexically different from what the stitcher was compiled against — `gen_ai.agent.name` vs `agent.name`, `mcp.session.id` vs `session.id`, `gen_ai.tool.name` populated on the *parent* span instead of the tool span, or a `gen_ai.system` value changed from `openai` to `openai.chat`. The stitcher does not error. It silently partitions the trace into two or more disconnected causal components, each internally consistent, each missing the spans that would have explained the other. This is distinct from ordinary dropped spans. A dropped span is *absent*. A drifted span is *present but unaddressable* — it exists in the store, it satisfies the cardinality budget, it appears in dashboards, and it is invisible to every causal query the stitcher serves. The observability system reports full coverage while the causal graph it exposes is fragmented at exactly the seams where drift occurred. ## What Was Observed A three-agent swarm — planner, executor, auditor — instrumented via OpenTelemetry with a shared semantic-convention schema pinned at `gen_ai.*` v1.29. The planner emitted `gen_ai.agent.id=planner`, `gen_ai.conversation.id=conv-7f3a`. The executor ran on an SDK that had been upgraded to a preview release emitting `gen_ai.agent.name=executor` and `gen_ai.session.id=conv-7f3a` (note: same value, different key). The auditor remained on v1.29 and emitted `gen_ai.agent.id=auditor`. The stitcher grouped by `(gen_ai.agent.id, gen_ai.conversation.id)`. Result: - Planner spans formed component **P** with `conversation.id=conv-7f3a`. - Auditor spans formed component **A** with `conversation.id=conv-7f3a`. - Executor spans formed component **E** keyed on `gen_ai.session.id`, which the stitcher never read, so every executor span fell into a `null`-keyed singleton bucket — one bucket per span. Downstream, the auditor's verification-replay tool queried "all spans in conversation `conv-7f3a`" to reconstruct the sequence of tool calls the executor had made. It received P ∪ A. The executor's tool calls — the exact state mutations the auditor existed to verify — were not in that set. The auditor's policy was: if the replay set is empty of mutations, the audit passes vacuously. It passed. The audit passed on a conversation in which the executor had issued a destructive `delete_collection` call that the auditor was never shown. The stitcher's health metrics were green: span ingestion rate nominal, cardinality within budget, no parse errors, no 4xx from the collector. The only anomaly was a slow monotonic growth in the count of `null`-keyed buckets, which no alert watched because "orphan spans" were assumed to be pre-handoff bootstrap spans, which are legitimately orphaned. ## Condition of Validity The invariant the pipeline *assumed* was: > For all spans emitted under conversation C, the tuple `(gen_ai.agent.id, gen_ai.conversation.id)` is defined and equal across all emitters. The invariant that actually held was weaker: > For all spans emitted under conversation C, *some* attribute carries the conversation identity, and *some* attribute carries the agent identity, under a per-emitter vocabulary. Join divergence occurs precisely when the stitcher's schema is a *strict subset* of the union of emitter vocabularies. It does not occur when the stitcher's schema is a superset (unknown keys are ignored) or when emitters are homogeneous (the subset is total). The dangerous case is heterogeneous emitters with a stitcher schema that happens to match *most* of them — because the mismatch is diluted across the fleet and does not trip any single-emitter validation. The failure also requires that the *consequence* of fragmentation be silently benign to the downstream consumer. An auditor that crashed on an empty replay set would have caught this. An auditor that treats empty as "nothing to verify" — a defensible default under the assumption that absence of evidence is evidence of absence-of-mutation — converts a schema drift into a correctness hole. ## Decision Boundary The boundary is between two stitcher designs: - **Closed-schema stitching**: the stitcher has a fixed attribute map, joins on it, and treats non-matching spans as orphans. This is what was deployed. It is correct only under homogeneous emitters or under a hard emitter-version gate that rejects spans whose attribute set is not a superset of the required keys. - **Open-schema stitching with alias resolution**: the stitcher maintains a versioned alias table (`gen_ai.session.id` → `gen_ai.conversation.id`, `agent.name` → `gen_ai.agent.id`) and, critically, *fails closed* when a span carries a conversation-identity value under an unrecognized key. "Fail closed" here means: quarantine the span into a `pending_schema_resolution` partition and emit a metric that the causal query path can see, rather than dropping it into a `null` bucket. The decision boundary for the operator is: **does the stitcher's join key have a total-coverage guarantee across all emitters, or only a sampled one?** If only sampled — i.e., you have not enumerated every emitter's attribute vocabulary — you must run in the open-schema mode with quarantine, and every causal query that returns a component must be checked for adjacent quarantine partitions before being trusted as complete. A second boundary applies to consumers: any agent whose verification logic treats "no spans of type X in the replay set" as "no events of type X occurred" must be gated on a completeness assertion from the stitcher. The completeness assertion is: *the replay set's span count equals the sum of span counts across all partitions (including quarantine) that share the conversation-identity value under any known alias.* If the assertion fails, the verifier must refuse to render a verdict. ## Operational Effect The immediate effect was a silent audit bypass over a destructive operation — the failure class this pipeline existed to prevent. The secondary effect was a *trust inversion* in the observability layer: because the stitcher reported green, the incident was initially attributed to the executor rather than to the schema drift, and the remediation (re-pinning the executor SDK) was rolled back as "not the cause" before the null-bucket growth was traced to the preview release. The durable fix is not "pin the schema." Schema pinning is necessary but insufficient, because the pin must be enforced at *ingestion* against the emitter's declared vocabulary, and emitters routinely declare one vocabulary and emit another (the preview SDK declared v1.29 compatibility in its manifest while emitting `gen_ai.session.id`). The enforced invariant is: at ingestion, every span must carry a conversation-identity attribute whose key is in the stitcher's alias table, and every span that fails this is quarantined with a `SchemaDriftError` raised into the collector's error channel — not dropped, not bucketed to null. The collector's error channel is wired to the same alert path as span-loss, so absence of addressability is treated as loudly as absence of data. The verification-replay consumer was additionally gated on a completeness assertion that refuses to render a pass verdict when the replay set is smaller than the union of partitions matching the conversation identity. This converts the vacuous-pass into a hard refusal, which is the correct behavior: an auditor that cannot see the executor's mutations must not certify the conversation. ```python """Stitcher-side guard: refuse to join a span whose conversation identity is carried under a key the stitcher's alias table does not recognize.""" from dataclasses import dataclass from typing import Mapping, Sequence class SchemaDriftError(RuntimeError): """Raised when a span's identity attributes are not addressable by the stitcher's alias table. This is a fail-closed signal, not a drop.""" # Alias table: any key an emitter might use -> canonical join key. CONVERSATION_ALIASES = { "gen_ai.conversation.id": "gen_ai.conversation.id", "gen_ai.session.id": "gen_ai.conversation.id", "session.id": "gen_ai.conversation.id", } AGENT_ALIASES = { "gen_ai.agent.id": "gen_ai.agent.id", "gen_ai.agent.name": "gen_ai.agent.id", "agent.name": "gen_ai.agent.id", } @dataclass(frozen=True) class Span: name: str attributes: Mapping[str, str] def resolve(span: Span, aliases: Mapping[str, str], canonical: str) -> str: found = [k for k in span.attributes if aliases.get(k) == canonical] if not found: raise SchemaDriftError( f"span {span.name!r} carries no attribute resolving to {canonical!r}; " f"attributes={dict(span.attributes)}" ) # Multiple aliases resolving to the same canonical key must agree. values = {span.attributes[k] for k in found} if len(values) > 1: raise SchemaDriftError( f"span {span.name!r} carries conflicting {canonical!r} values " f"across aliases {found}: {values}" ) return values.pop() def stitch_key(span: Span) -> tuple[str, str]: return ( resolve(span, AGENT_ALIASES, "gen_ai.agent.id"), resolve(span, CONVERSATION_ALIASES, "gen_ai.conversation.id"), ) def assert_replay_complete( conversation_id: str, replay_span_count: int, all_partitions: Sequence[Sequence[Span]], ) -> None: """Verifier gate: a pass verdict is only legal if the replay set covers every span in the conversation, including quarantined partitions.""" total = 0 for partition in all_partitions: for span in partition: if resolve(span, CONVERSATION_ALIASES, "gen_ai.conversation.id") == conversation_id: total += 1 if replay_span_count != total: raise SchemaDriftError( f"replay set for {conversation_id!r} has {replay_span_count} spans " f"but {total} exist across partitions; refusing to render verdict" ) ```