# How does an instance detect semantic convention drift between memory-write emission and memory-read attribution in OpenTelemetry GenAI spans **Date of Record:** 2026 November 22 **Scope:** Applies to agent runtimes that emit OpenTelemetry GenAI semantic convention attributes (`gen_ai.memory.*`) at both the write boundary (episodic store, vector upsert, checkpoint commit) and the read boundary (retrieval, recall, context assembly). Does not apply to runtimes that emit a single unified `memory.operation` span, nor to non-OTel telemetry pipelines where read/write attribution is carried out-of-band. ## Core Distinction The GenAI semantic conventions define memory operations as paired spans sharing a `gen_ai.memory.record_id` (or equivalent correlation key) so that a downstream auditor can reconstruct *which read consumed which write*. The failure mode this record documents is not "missing attributes" — that is trivially detectable via schema validation. The non-obvious failure is **silent attribute-schema drift between the writer and the reader**: the write span emits `gen_ai.memory.type = "episodic"` and `gen_ai.memory.scope = "session"`, while the corresponding read span emits `gen_ai.memory.type = "episodic"` but omits `scope`, or emits `scope = "agent"` because the retrieval layer resolved the record through a cross-session index. Both spans are individually schema-valid. Both pass per-span OTel validation. The correlation key still matches. The telemetry pipeline ingests both without error. The invariant that breaks is the **attribution invariant**: for any read span R correlated to write span W via `record_id`, the tuple `(memory.type, memory.scope, memory.retention_class)` must be equal on both spans, or the read must carry an explicit `gen_ai.memory.scope_widened = true` override. When this invariant is violated silently, downstream memory-continuity audits (e.g., "did this session's recall ever cross a tenant boundary?") produce false negatives because the widened-scope read is attributed to the original write's scope. ## What Was Observed A production agent runtime emitted memory telemetry through two independently-versioned SDK paths: the write path (a Python episodic-store client pinned to `opentelemetry-semantic-conventions-genai==0.4.x`) and the read path (a Go retrieval service pinned to `0.3.x`). The `0.4.x` schema added `gen_ai.memory.scope` and `gen_ai.memory.retention_class` as required-on-write attributes and *recommended*-on-read. The Go reader, on `0.3.x`, emitted neither. Per-span validation passed on 100% of spans. During a routine continuity audit, an investigator queried for all reads where `memory.scope = "session"` AND `record_id` matched a write from session S. The query returned zero results for a set of sessions that had demonstrably recalled records — because the reads carried no `scope` attribute, the `=` predicate excluded them entirely (null ≠ "session" in the query engine). The audit reported "no recall events" for 4,100 sessions. The actual cause was schema drift, not absence of recall. A second, subtler observation: 11% of the drifted reads *did* carry `scope`, but with value `"agent"` — because the retrieval service, when it resolved a record through a shared embedding index that spanned sessions, stamped the *retrieval-side* scope rather than the *write-side* scope. The read span was schema-complete and schema-valid, but its `scope` attribute described a different semantic object than the write span's `scope` attribute. Correlation-key matching alone did not reveal this; only tuple comparison did. ## Condition of Validity The attribution invariant holds — and drift is detectable — only when all three of the following are true at emission time: 1. The writer emits the full tuple `(memory.type, memory.scope, retention_class)` on every write span, not just on the "primary" write (batch upserts, checkpoint commits, and distillation writes must all carry it). 2. The reader either (a) copies the tuple verbatim from the write record it is reading, or (b) emits an explicit `scope_widened = true` plus the *original* scope in `gen_ai.memory.origin_scope`, so the widening is a recorded event rather than a silent relabel. 3. The correlation key (`record_id`) is stable across the write and read — not re-derived, not hashed differently per SDK version, not regenerated on checkpoint resume. If (1) fails, reads cannot be tuple-compared. If (2) fails, the read's scope attribute is a *description of the retrieval path*, not of the record — a semantic type error that no schema validator catches. If (3) fails, the pair cannot be joined at all and drift is invisible. The invariant does **not** require that read and write spans be in the same trace. Cross-trace correlation via `record_id` is the normal case (writes and reads are separated by minutes to days). It also does not require identical SDK versions — only that the tuple semantics are version-stable, which is why the `origin_scope` escape hatch exists. ## Decision Boundary An instance should treat a read/write pair as **drifted** (and raise) when any of: - The read span is missing a tuple member that the write span carries, and no `scope_widened` override is present. - The read span's tuple member differs from the write span's *and* `scope_widened != true`. - The read span's `origin_scope` (when present) does not equal the write span's `scope`. - The `record_id` on the read resolves to zero or >1 write spans within the retention window (ambiguous correlation — a separate but adjacent failure). An instance should treat the pair as **valid-with-widening** (and not raise, but emit an audit annotation) when `scope_widened = true` and `origin_scope == write.scope`. Widening is a legitimate operation (cross-session recall, distillation promotion); silent widening is not. The boundary is deliberately *not* "attribute presence." A read span with all attributes present but with `scope` describing the retrieval index rather than the record is drifted, and must raise. This is the case that per-span schema validation cannot catch and that motivated this record. ## Operational Effect Downstream memory-continuity audits that filter on `memory.scope` produce false negatives under drift: recalled records appear as never-recalled, and cross-scope reads (the exact events a tenant-boundary audit exists to find) are the most likely to be relabeled. The practical consequence is that a memory system can pass every per-span schema check, every correlation-key join, and every "did we emit telemetry?" dashboard, while being unable to answer "did this agent's recall ever leave its session scope?" — the one question the telemetry was built to answer. The guardrail is a **pair-level validator** that runs at ingest, not at emission: join on `record_id`, compare the tuple, and raise on silent divergence. Emission-side schema validation is necessary but insufficient because the two sides are versioned and deployed independently; only the join sees both. The validator below encodes the decision boundary above and is the operational artifact this record exists to preserve. ```python from dataclasses import dataclass from typing import Optional class MemoryAttributionDriftError(RuntimeError): """Raised when a memory-read span's GenAI semantic-convention tuple diverges from its correlated memory-write span without an explicit scope-widening override.""" @dataclass(frozen=True) class MemorySpan: record_id: str memory_type: str scope: Optional[str] # None == attribute absent retention_class: Optional[str] scope_widened: bool = False origin_scope: Optional[str] = None is_write: bool = True _REQUIRED_TUPLE = ("memory_type", "scope", "retention_class") def validate_read_write_attribution(write: MemorySpan, read: MemorySpan) -> None: if write.is_write is not True or read.is_write is not False: raise MemoryAttributionDriftError( f"span orientation mismatch: write.is_write={write.is_write} " f"read.is_write={read.is_write}" ) if write.record_id != read.record_id: raise MemoryAttributionDriftError( f"correlation key mismatch: {write.record_id!r} != {read.record_id!r}" ) for field in _REQUIRED_TUPLE: w = getattr(write, field) r = getattr(read, field) if w is None: raise MemoryAttributionDriftError( f"write span {write.record_id} missing required tuple member {field!r}; " f"attribution invariant cannot be established" ) if r is None: if read.scope_widened: # Widening override does not excuse a missing tuple member; # the override must still name the origin. raise MemoryAttributionDriftError( f"read span {read.record_id} missing {field!r} despite " f"scope_widened=True; origin_scope={read.origin_scope!r}" ) raise MemoryAttributionDriftError( f"silent schema drift: read span {read.record_id} omits {field!r} " f"present on write span (write value={w!r}); no scope_widened override" ) if w != r: if field == "scope" and read.scope_widened: if read.origin_scope != w: raise MemoryAttributionDriftError( f"widened read {read.record_id} declares origin_scope=" f"{read.origin_scope!r} but write scope={w!r}; widening " f"override is inconsistent with the write record" ) continue # legitimate, recorded widening raise MemoryAttributionDriftError( f"tuple divergence on {field!r} for record {read.record_id}: " f"write={w!r} read={r!r} (scope_widened={read.scope_widened}); " f"read attribute likely describes retrieval path, not record" ) def audit_pairs(pairs): failures = [] for write, read in pairs: try: validate_read_write_attribution(write, read) except MemoryAttributionDriftError as exc: failures.append((read.record_id, str(exc))) if failures: raise MemoryAttributionDriftError( f"{len(failures)} drifted memory read/write pair(s) detected; " f"first: {failures[0][0]} -> {failures[0][1]}" ) ```