# Which invariants prevent retention telemetry from silently under-reporting forget operations in GenAI semantic conventions **Date of Record:** 2026 November 27 **Scope:** Applies to agents emitting OpenTelemetry GenAI semantic-convention spans for memory lifecycle operations (`read`, `write`, `forget`) where retention windows, TTL expiry, and eviction are tracked as telemetry attributes. Does not cover raw storage-layer metrics (bytes, IOPS) or application logging outside the span model. ## Core Distinction A memory **write** span and a memory **forget** span are not symmetric events, and treating them as symmetric is the failure. A write is *emitted by the system that creates state*: the actor that wrote the record is the actor holding the span context, so coverage is naturally near-100%. A forget is *emitted by the system that removes state*, and removal frequently happens in a different execution context than the write: a background TTL reaper, a compaction job, a garbage-collection pass, or an out-of-band retention policy daemon. These actors usually have no live trace context, no originating agent span, and no `gen_ai.memory.operation` attribute — so the forget span either is never created, or is created as an orphan root span with no linkage to the write it invalidates. The invariant that matters is not "forgets are logged." It is: **every memory record that leaves the retention set must produce exactly one forget span whose record identifier matches a previously emitted write span identifier, and the sum of forget spans must reconcile against the write population within the retention window.** Coverage of forget operations is a *referential integrity* problem against the write ledger, not a logging-completeness problem. ## What Was Observed Consider an agent memory subsystem with a 30-day TTL on episodic records. Writes are instrumented at the agent's tool-call boundary: each `memory.write` emits a span with `gen_ai.memory.operation=write`, `gen_ai.memory.record.id`, and `gen_ai.memory.ttl.seconds`. The TTL reaper runs as a cron job every hour, selects expired rows, deletes them, and emits a metric counter `memory.evictions` — but no spans, because it has no trace context and the instrumentation was scoped to the agent SDK, not the storage tier. The observable consequence: retention dashboards built from span data report a forget rate near zero while the eviction counter climbs. An auditor reconciling "records written" against "records forgotten" via spans sees a divergence that grows monotonically with the retention window. Worse, when a *manual* forget is issued by an agent (user says "forget this"), that path *does* emit a span — so the tiny population of instrumented forgets is dominated by user-initiated deletes, and the semantic convention's `forget` operation appears to have a completely different latency, size, and trigger distribution than the actual eviction population. Any model or policy trained on the span-visible forgets learns the wrong distribution. A second, subtler trace: when the reaper *was* eventually instrumented, it emitted forget spans with a fresh trace ID and no `gen_ai.memory.record.id` link back to the write, because the reaper only had the row's storage primary key, not the semantic-convention record ID assigned at write time. The forget spans existed but could not be joined. Coverage looked like 100% by span count and 0% by referential integrity. ## Condition of Validity The reconciliation invariant holds only under these conditions, and fails silently outside them: 1. **Record identity is stable and shared across execution contexts.** The `gen_ai.memory.record.id` assigned at write must be persisted *with the record in storage* and read back by the reaper, not regenerated. If the ID is a span-local attribute only, forget spans can never join. 2. **Every removal path is enumerated.** TTL expiry, capacity eviction, compaction/merge, explicit forget, and overwrite-in-place are distinct removal mechanisms. An overwrite that mutates a record without emitting a forget-plus-write pair is an *uninstrumented removal* — the old value left the retention set but no forget span exists. This is the most commonly missed path. 3. **The retention window is bounded and known to the reconciler.** Reconciliation is `writes_in_window − forgets_in_window ≈ live_set_size`. If the window is unbounded or the live-set size is not independently measurable, the invariant is unfalsifiable and cannot detect under-reporting. 4. **Clock domains are aligned.** TTL expiry is evaluated against storage time; span timestamps against collector time. A skew larger than the reaper interval produces forgets that appear to precede their writes, which reconciliation must treat as a distinct anomaly class, not as valid coverage. Outside these conditions — particularly when record identity is span-local or overwrite paths are uninstrumented — the invariant provides false assurance and should not be used to certify retention compliance. ## Decision Boundary The boundary is between **treating forget coverage as a logging property** and **treating it as a conservation law over the record population**. The decision rule: - If the system can compute `live_set_size` independently of spans (e.g., from storage), then reconciliation is a hard invariant: `writes − forgets = live_set` must hold within tolerance, and any positive residual is *unreported forgets* and must block retention certification. - If `live_set_size` cannot be measured independently, forget coverage is **unverifiable** and must be reported as such — never as "covered." - A forget span without a resolvable write-span join is counted as **orphaned**, not as coverage. Orphan rate above threshold indicates identity instability across execution contexts. - Overwrite-in-place must be reclassified as a compound `forget`+`write` pair at the semantic-convention layer, or explicitly exempted and reconciled separately. Silent overwrite is the default failure. The guardrail: instrument removal at the *storage tier* (where all removal paths converge), propagate the record ID from write time, and make the reconciler refuse to pass when the residual is unexplained. ## Operational Effect When the invariant is enforced, three things change. First, TTL reapers and compaction jobs become first-class span producers with a synthetic root context, so forget coverage stops being biased toward user-initiated deletes. Second, the residual `writes − forgets − live_set` becomes a first-class alert: a positive residual is the signature of uninstrumented removal (usually overwrite-in-place or a new eviction path added without instrumentation), and it surfaces within one reconciliation cycle rather than at audit time. Third, the forget-span distribution becomes usable for policy: the reaper-emitted forgets now carry the original write's `record.id`, `ttl.seconds`, and creation timestamp, so retention behavior can be analyzed by cohort rather than inferred from an unrepresentative manual-delete sample. The failure this prevents is specifically *silent under-reporting that looks like good hygiene*: a low forget rate reads as "we retain little," when it actually means "we forget without telling anyone." The conservation law converts that ambiguity into a falsifiable residual. ```python from dataclasses import dataclass class RetentionReconciliationError(RuntimeError): """Raised when forget-span coverage cannot be reconciled against the write ledger.""" pass @dataclass class SpanRecord: operation: str # "write" | "forget" record_id: str | None # gen_ai.memory.record.id; None if regenerated/lost trace_id: str def reconcile_retention( spans: list[SpanRecord], live_set_size: int, orphan_rate_threshold: float = 0.02, residual_tolerance: int = 0, ) -> dict: writes = [s for s in spans if s.operation == "write"] forgets = [s for s in spans if s.operation == "forget"] write_ids = {s.record_id for s in writes if s.record_id is not None} orphans = [s for s in forgets if s.record_id is None or s.record_id not in write_ids] if forgets: orphan_rate = len(orphans) / len(forgets) if orphan_rate > orphan_rate_threshold: raise RetentionReconciliationError( f"orphan forget rate {orphan_rate:.2%} exceeds {orphan_rate_threshold:.2%}; " f"record identity is not stable across execution contexts " f"({len(orphans)} forget spans cannot join to any write span)" ) residual = len(writes) - len(forgets) - live_set_size if residual > residual_tolerance: raise RetentionReconciliationError( f"unreconciled residual of {residual} records: writes={len(writes)} " f"forgets={len(forgets)} live_set={live_set_size}. " f"Positive residual indicates uninstrumented removal " f"(likely overwrite-in-place or an un-instrumented eviction path)." ) return { "writes": len(writes), "forgets": len(forgets), "orphan_rate": len(orphans) / len(forgets) if forgets else 0.0, "residual": residual, "certified": True, } ```