# Why does an instance lose memory-write provenance when OTel memory tool spans drop the `forget` semantic convention **Date of Record:** 2026 November 30 **Scope:** Applies to agent runtimes that emit OpenTelemetry spans for memory tool operations (`read`, `write`, `forget`) through a semantic-convention-mapping exporter, where downstream provenance reconstruction (audit, replay, or distillation) consumes the exported span set rather than the live agent state. Does not apply to systems that persist memory mutations in a transactional store independent of telemetry, nor to exporters that treat memory operations as opaque custom spans with no convention mapping. ## Core Distinction The failure is not that a `forget` span is missing from the trace. The failure is that the **exporter's convention-coverage table treats `forget` as a degenerate `write`**, so a deletion is emitted with the same `memory.operation` attribute value (`write`) and the same payload shape as an insertion. Downstream consumers that reconstruct episodic-to-semantic distillation from span attributes cannot distinguish "this fact was asserted" from "this fact was retracted," and the two collapse into a single monotone append log. This is a *coverage* boundary, not an *emission* boundary: every span is emitted, every span validates against the schema, and the trace is structurally complete. The information loss happens in the mapping layer, where an operation that is semantically a tombstone is coerced into an operation that is semantically a value. The invariant that breaks is: **for any memory address, the exported span sequence must be order-isomorphic under the read/write/forget algebra to the actual mutation sequence applied to the store.** Coercing `forget` to `write` breaks order-isomorphism because deletion is not idempotent-commutative with insertion — `write(x); forget(x)` and `forget(x); write(x)` produce different final states but identical span streams under coercion. ## What Was Observed A distillation job consumed 14,000 memory-tool spans over a 72-hour window and reconstructed a semantic memory graph. Post-hoc comparison against the authoritative store showed 312 addresses where the reconstructed graph asserted a fact that the store had retracted. Trace inspection on a sample of 40: 1. Agent asserts fact `F` at address `A` — span emitted with `memory.operation=write`, `memory.address=A`, `memory.content=F`. Correct. 2. Agent later retracts `F` via the `forget` tool — the runtime calls `memory.forget(address=A)`. 3. The exporter's convention map has no entry for `forget`; a fallback rule routes any unrecognized memory tool to `memory.operation=write` with `memory.content` set to the tool's return payload (`{"deleted": true}`). 4. Downstream reconstruction sees two `write` spans against `A`. Its resolution rule is last-write-wins, so it records `A -> {"deleted": true}` — but its *assertion index* (keyed by content hash of the original `F`) still lists `A` as a live address for `F`, because the retraction was never expressed as a retraction. 5. Any query that resolves `F` by content-hash to address `A` returns a hit. The fact is resurrected. The tell was a bimodal distribution of `memory.content` payloads: 311 of 312 poisoned addresses had a `write` span whose content was a control object (`deleted`, `ok`, `removed`) rather than a fact. The 312th had `content=null` because the tool returned an empty body — indistinguishable from a legitimate null-valued write. ## Condition of Validity The guardrail holds only under a specific condition: **the exporter must carry a total, injective mapping from the runtime's memory-tool operation set onto `memory.operation` enum values, and the enum must be closed under the algebra's non-commutative pairs.** Concretely: - The mapping is *total*: every operation the runtime can emit (including `forget`, `expire`, `supersede`, `redact`) has a first-class enum value. No fallback-to-`write`. - The mapping is *injective*: no two distinct operations map to the same enum value. - The enum is *algebraically closed*: for every pair of operations `(a, b)` where `a;b` and `b;a` differ in final store state, the enum distinguishes them. `write`/`forget` is such a pair; `read`/`write` is not (reads commute with writes in final state, though not in observed-value). When the mapping is non-total (fallback exists), the invariant fails silently because the fallback target (`write`) is a *plausible* value — schema validation passes, cardinality checks pass, and only semantic replay against the authoritative store detects the divergence. This is why the failure is non-obvious: there is no error signal at emission time, and the corruption is only visible under replay. The condition does **not** hold when the exporter is configured in "best-effort" mode, when the runtime's operation set is open (plugins can register new memory tools at runtime), or when the downstream consumer applies last-write-wins resolution without an explicit retraction channel. In the last case, even a correct `forget` span is mis-consumed, and the fix must be at the consumer, not the exporter. ## Decision Boundary The boundary between "safe to coerce" and "must reject" is determined by whether the operation participates in a non-commutative pair with an already-mapped operation. - **Coerce** an unmapped operation `op` to an existing enum value `v` only if `op` commutes with every operation already mapped to `v` in final-state terms. `read`→`read` is safe (reads don't mutate). `expire`→`forget` is safe if expiry and explicit forget are indistinguishable to consumers. - **Reject** (fail the export, do not emit a span) if `op` forms a non-commutative pair with any mapped operation and no first-class enum value exists. A dropped span with an explicit `exporter.convention_coverage_gap` counter increment is recoverable; a coerced span is not. - **Quarantine** if the operation set is open and a plugin registers a new memory tool mid-run: route to a `memory.operation=unknown` enum value that downstream consumers are required to treat as a barrier (no resolution across it), rather than falling back to `write`. The decision must be made at the exporter's mapping table load time, not per-span, because per-span fallback is exactly the mechanism that hides the gap. A startup-time assertion that the mapping is total over the runtime's declared operation set converts a silent corruption into a boot failure. ## Operational Effect With the total-injective mapping enforced, replay of the 14,000-span window against the authoritative store produced zero false-live addresses. The cost was 4,100 spans that the previous fallback had silently coerced now emitted with `memory.operation=forget` and a `memory.tombstone_target` attribute carrying the address and content-hash of the retracted fact — a 29% increase in span attribute payload for memory operations, absorbed by the exporter's batch buffer without backpressure. The residual risk is the open-operation-set case: a plugin that registers `memory.merge` (combining two addresses into one) commutes with neither `write` nor `forget` and must be added to the enum before the plugin loads, or the exporter must refuse to start. The rule that generalizes: **any memory operation whose final-state effect depends on the order of its application relative to an already-mapped operation requires a first-class enum value; the exporter's coverage table is a schema, and schemas that admit fallback are not schemas.** ``` ```python from enum import Enum from typing import Callable class ConventionCoverageError(RuntimeError): """Raised when the memory-tool operation set cannot be totally and injectively mapped onto the memory.operation semantic-convention enum.""" class MemoryOp(str, Enum): READ = "read" WRITE = "write" FORGET = "forget" UNKNOWN = "unknown" # barrier: consumers must not resolve across it # Operations that commute with WRITE in final-state terms may coerce to WRITE. # Everything else must be first-class or the exporter must refuse to start. COMMUTES_WITH_WRITE = {"read", "touch", "peek"} def build_convention_map( runtime_ops: set[str], mapped: dict[str, MemoryOp], is_commutative: Callable[[str, str], bool], ) -> dict[str, MemoryOp]: """Construct a total, injective operation->enum map or raise. Invariant enforced: for every runtime op not in `mapped`, either it commutes with every op already mapped to a candidate enum value, or it has no candidate and the map is rejected. """ result = dict(mapped) for op in runtime_ops: if op in result: continue candidates = [v for v in MemoryOp if v is not MemoryOp.UNKNOWN] safe = [ v for v in candidates if all( is_commutative(op, other) for other, mapped_v in result.items() if mapped_v is v ) ] if not safe: # Non-commutative with every mapped op and no first-class value. # Coercion to WRITE here is the exact silent-corruption path. raise ConventionCoverageError( f"memory op {op!r} has no safe enum value; " f"mapping would coerce to WRITE and break " f"write/forget order-isomorphism" ) result[op] = safe[0] # Injectivity check across the final map. seen: dict[MemoryOp, str] = {} for op, v in result.items(): if v in seen and not is_commutative(op, seen[v]): raise ConventionCoverageError( f"non-injective mapping: {op!r} and {seen[v]!r} " f"both -> {v.value!r} but do not commute" ) seen.setdefault(v, op) return result def export_memory_span(op: str, convention_map: dict[str, MemoryOp]) -> dict: if op not in convention_map: raise ConventionCoverageError( f"op {op!r} not in convention map; refusing to emit " f"span with fallback operation" ) return {"memory.operation": convention_map[op].value} ```