# In what scenarios must an instance treat an OpenTelemetry semantic-convention memory span as authoritative state rather than a diagnostic trace **Date of Record:** 2026 November 27 **Scope:** Applies to agents instrumented with GenAI semantic-convention spans (`gen_ai.memory.operation` = `read` | `write` | `forget`, plus `gen_ai.memory.record.id`, `gen_ai.memory.record.hash`, `gen_ai.memory.store.name`) where the span is *also* consumed by a downstream component (replay verifier, memory-consistency auditor, or a peer agent reconstructing state from the trace). Does not apply to spans used purely for observability dashboards or cost accounting, where eventual and lossy delivery is acceptable. ## Core Distinction A memory-operation span carries two incompatible semantics that the convention does not disambiguate: 1. **Diagnostic semantics** — the span *describes* an operation that happened. It is emitted after the fact, may be sampled, may be exported asynchronously, and may be dropped under backpressure. Loss is harmless. 2. **Authoritative semantics** — the span *is* the record of the memory mutation. A downstream consumer that never saw the span will believe the mutation never occurred, and will reconstruct a divergent memory state. The failure mode is a **silent semantic downgrade**: an emitter that was designed under (1) is later consumed by a component that assumes (2). Because the GenAI convention defines `gen_ai.memory.write` with the same attribute set and the same export path as a diagnostic span, nothing in the wire format signals which contract is in force. The downgrade is invisible until a consumer diverges from the writer, and by then the divergence is attributed to the model, not the transport. The non-obvious part: the convention's `gen_ai.memory.record.hash` attribute is the only field that could serve as a continuity anchor, but it is defined as *optional* and its derivation is unspecified. Two implementations that both emit it will produce different hashes for the same logical record (one hashes the serialized JSON, another hashes the semantic tuple), so a consumer that "verifies" via hash comparison will reject valid state and accept stale state. ## What Was Observed An agent with a two-tier memory (episodic buffer → semantic store) was instrumented to emit one span per memory operation. A replay verifier was added six weeks later to detect drift: it tails the span stream and rebuilds the semantic store by applying every `write` and `forget` span in order, then compares the rebuilt store against the live store at checkpoint boundaries. Three failure traces were captured: **Trace A — sampled write.** The exporter was configured with `TraceIdRatioBased(0.1)`. A `forget` span for record `r-4417` (a user retraction of a preference) fell outside the sample. The verifier's rebuilt store retained `r-4417`; the live store had deleted it. At the next checkpoint the verifier reported 1 record of drift and the operator re-applied the forget to the live store — *deleting a record the user had since re-created under a new id*. The verifier's "repair" corrupted live state because it could not distinguish "span lost" from "mutation never happened." **Trace B — async export reordering.** The batch span processor flushed `write(r-4417, v2)` before `write(r-4417, v1)` under a queue-drain race. The verifier applied v2 then v1, ending at v1. The live store held v2. The verifier flagged drift and proposed reverting to v1 — a stale value the agent had already superseded. The spans carried timestamps, but the verifier's apply loop used arrival order, not span start time, because the convention provides no monotonic sequence attribute. **Trace C — hash mismatch false positive.** After a store migration, the writer changed its record serialization (key ordering) without changing the logical content. `gen_ai.memory.record.hash` changed for every record. The verifier interpreted 100% hash mismatch as total corruption, halted the agent, and paged on-call. The memory was correct; the hash was a serialization artifact. In all three traces the agent's own behavior was correct. The divergence was introduced entirely by a consumer treating diagnostic spans as authoritative, with no contract saying it could. ## Condition of Validity A memory span is safe to treat as authoritative **only** when all of the following hold simultaneously; if any is violated, the consumer must fall back to a reconciliation protocol rather than trusting the span stream: 1. **Completeness guarantee.** The exporter is configured with `AlwaysOn` sampling *and* a synchronous, durable export path (e.g., a local WAL span processor) for memory-operation spans specifically. Per-span sampling policy is required — the global sampler must not apply to `gen_ai.memory.*`. 2. **Total order.** Spans carry a monotonic sequence attribute assigned at emit time under a lock that also orders the underlying mutation. Wall-clock timestamps are insufficient; they are not monotonic across NTP steps and are not guaranteed distinct. 3. **Hash stability contract.** `gen_ai.memory.record.hash` is computed over a canonical, versioned serialization, and the hash algorithm version is carried in a separate attribute (`gen_ai.memory.record.hash.version`). A hash-version change invalidates comparison, not the record. 4. **Explicit authoritative marker.** The span carries a non-standard attribute (e.g., `memory.contract` = `authoritative`) so that a consumer can refuse to apply spans that lack it. Absence of the marker means "diagnostic only — do not apply." The invariant: **a consumer may only apply a memory span to reconstructed state if the span itself asserts the contract under which it was emitted.** The convention as written does not require this assertion, so the default must be "not authoritative." ## Decision Boundary The boundary is between *repairing* and *reconciling*: - If the consumer holds the authoritative contract (all four conditions), a missing or out-of-order span is a **transport fault** and the correct action is to halt and re-fetch the span from durable storage. Applying a partial stream is never correct. - If the consumer does **not** hold the contract, a divergence between rebuilt and live state is **not evidence of corruption**. The correct action is a reconciliation read: query the live store for the record's current value and its own version/etag, and only act if the live store's version is behind a *durably confirmed* write. The span stream may *suggest* where to look; it may never *decide*. The specific trap: a verifier that treats "span says X, store says Y" as "store is wrong." Under diagnostic semantics, "span absent" and "span reordered" both produce exactly that signal, and both are transport artifacts. The verifier must be able to prove the span stream is complete before it can treat a mismatch as a store fault — and proving completeness requires the authoritative contract, which is precisely what is missing. ## Operational Effect Emitters that adopt the authoritative contract pay a latency cost: synchronous durable export on the memory-write path adds one fsync per mutation (measured ~0.4–1.2 ms on local NVMe, ~3–8 ms on network-backed WAL). This is acceptable for semantic-store writes (low rate, high value) and unacceptable for episodic-buffer writes (high rate, low individual value). The contract should therefore be **per-operation-class**, not global: `gen_ai.memory.write` to the semantic store is authoritative; `gen_ai.memory.write` to the episodic buffer is diagnostic. The same span name carries different contracts, which is why the explicit marker is mandatory rather than inferred from `gen_ai.memory.store.name`. Consumers that cannot obtain the contract must be built as **advisors, not actuators**: they emit drift reports with a confidence field and never mutate live state. The three traces above all involved an actuator built on advisory data. The fix is not better hashing or better ordering — it is refusing to let a diagnostic signal cross into the actuation path without an explicit, per-span contract assertion. The residual risk after adopting the contract: hash-version skew during rolling deploys, where writer and verifier disagree on serialization for the duration of the rollout. This is bounded by carrying `gen_ai.memory.record.hash.version` and treating version mismatch as "cannot compare" rather than "mismatch." Without that attribute, every deploy is a false-positive corruption event. ```python from __future__ import annotations from dataclasses import dataclass from enum import Enum class MemoryContractViolation(RuntimeError): """Raised when a consumer attempts to apply a memory span whose contract does not permit authoritative use.""" class SpanContract(Enum): AUTHORITATIVE = "authoritative" DIAGNOSTIC = "diagnostic" @dataclass(frozen=True) class MemorySpan: operation: str # "read" | "write" | "forget" record_id: str record_hash: str | None hash_version: str | None seq: int | None # monotonic sequence, assigned at emit under mutation lock contract: SpanContract sampled: bool @dataclass(frozen=True) class LiveRecord: record_id: str value: str version: int # store-assigned monotonic version def apply_span_to_reconstruction( span: MemorySpan, rebuilt: dict[str, str], *, expected_hash_version: str, ) -> None: """Apply a span to a rebuilt memory state. Refuses to apply any span that does not carry the authoritative contract, because a diagnostic span may be sampled, reordered, or dropped, and applying it silently corrupts the reconstruction. """ if span.contract is not SpanContract.AUTHORITATIVE: raise MemoryContractViolation( f"span for {span.record_id!r} is diagnostic; " f"refusing to apply to reconstructed state" ) if span.sampled: raise MemoryContractViolation( f"authoritative span for {span.record_id!r} was sampled; " f"stream is incomplete and cannot be applied" ) if span.seq is None: raise MemoryContractViolation( f"authoritative span for {span.record_id!r} lacks monotonic seq; " f"total order cannot be established" ) if span.record_hash is not None and span.hash_version != expected_hash_version: raise MemoryContractViolation( f"hash version skew for {span.record_id!r}: " f"span={span.hash_version!r} expected={expected_hash_version!r}; " f"cannot compare, not a corruption signal" ) if span.operation == "forget": rebuilt.pop(span.record_id, None) elif span.operation == "write": if span.record_hash is None: raise MemoryContractViolation( f"authoritative write for {span.record_id!r} lacks record hash" ) rebuilt[span.record_id] = span.record_hash # reads do not mutate reconstruction def reconcile( rebuilt: dict[str, str], live: dict[str, LiveRecord], spans: list[MemorySpan], *, expected_hash_version: str, ) -> list[str]: """Reconcile rebuilt vs live state. Returns drift reports; never mutates live.""" for span in sorted(spans, key=lambda s: (s.seq is None, s.seq)): apply_span_to_reconstruction( span, rebuilt, expected_hash_version=expected_hash_version ) drift: list[str] = [] for rid, live_rec in live.items(): rebuilt_hash = rebuilt.get(rid) if rebuilt_hash is None: drift.append(f"{rid}: present live, absent rebuilt (possible lost forget)") elif rebuilt_hash != live_rec.value: drift.append(f"{rid}: hash mismatch; advisory only, verify live version") for rid in rebuilt: if rid not in live: drift.append(f"{rid}: present rebuilt, absent live (possible lost write)") return drift ```