# When must an instance refuse to promote episodic traces into semantic memory: the decay-crossing contamination invariant **Date of Record:** 2026 November 27 **Scope:** Applies to long-lived LLM agents that maintain a two-tier memory (episodic event log + distilled semantic store) with a retrieval scoring function combining recency decay and similarity. Does not apply to stateless single-shot inference or to pure vector-store RAG with no distillation step. ## Core Distinction Episodic memory is a timestamped, instance-local record of what actually happened: tool outputs, user utterances, intermediate reasoning. Semantic memory is a de-contextualized, durable claim set ("the staging DB host is `db-stg-04`"). The two are governed by *different* validity rules. An episodic record is true by construction (it records an event). A semantic record is true only conditionally — it asserts a proposition that can become false when the world changes, independent of the agent. The failure mode is not "forgetting." It is the **inverse**: an instance promotes an episodic trace to semantic memory *because the trace scored high on a recency-weighted retrieval function*, conflating "recently and frequently retrieved" with "currently true." The decay function that makes old episodic traces cheap to evict is exactly the function that inflates the score of a *recently contradicted* fact, because contradiction events are themselves episodic and recent. The promotion threshold and the decay window interact so that the moment a fact is most likely to be stale is the moment it is most likely to be canonized. ## What Was Observed An agent managing infrastructure facts held an episodic trace: `(t=0, "primary replica = node-A")`, retrieved and re-scored on every relevant query. At `t=90m` a failover event was logged episodically: `(t=90m, "primary replica = node-B; node-A demoted")`. The distillation job ran on a 2-hour cadence. Its promotion rule was: *if an episodic cluster's aggregate retrieval score exceeds τ, distill the highest-salience member into semantic memory.* The aggregate score for the `node-A` cluster was high — it had been retrieved 40 times in 90 minutes. The `node-B` failover trace had been retrieved twice. Under a decay function `score = sim · exp(−λ·Δt)` with λ tuned so that a 2-hour-old trace retains ~0.5 weight, the *sum* over the node-A cluster dominated. The distiller promoted `primary replica = node-A` into semantic memory at `t=120m`, 30 minutes *after* the world had changed, because the promotion signal measured retrieval frequency and recency of the fact, not the recency of the *most recent contradicting event*. The distilled semantic record then acquired a protection flag: semantic records are exempt from decay eviction. The contradiction, still episodic, decayed below retrieval threshold at `t≈6h` and was evicted. The agent now held a durable, high-confidence, wrong fact with no surviving record of the event that falsified it. Downstream tool calls routed writes to a demoted replica for the remainder of the deployment. The non-obvious part: **the decay function did its job correctly.** It correctly ranked the frequently-retrieved trace above the single contradicting event. The bug is a category error at the promotion boundary — using an episodic relevance score as a semantic truth score. ## Condition of Validity A promotion from episodic to semantic memory is sound only if, at the instant of promotion, the following invariant holds: > For every candidate fact `f` and every contradicting episodic event `c` in the log, `promote(f)` requires that `f`'s supporting trace is the **most recent** event bearing on the same predicate-key, and that no `c` exists with `timestamp(c) > timestamp(support(f))`. Formally, define `predicate_key(f)` (e.g., `primary_replica`). The promotion guard must scan the episodic log for the *latest* event per predicate-key and compare identity, not aggregate score. Aggregate retrieval scoring is admissible for *ranking candidates for distillation* but inadmissible as the *gate* for distillation. The gate must be a recency-ordering predicate over the raw log — a total order on timestamps within a key — which is monotone and cannot be inflated by retrieval frequency. This invariant is violated whenever the promotion gate is a scalar threshold on a score that (a) aggregates over multiple traces and (b) is decay-weighted. Both properties are individually reasonable and jointly fatal: aggregation lets frequency outvote recency, and decay ensures the contradicting event is the *least* weighted member of the aggregate. ## Decision Boundary The boundary is not "how old is too old to promote." It is **which ordering the promotion gate reads.** Two regimes: - **Score-gated promotion (unsafe at the truth boundary):** gate on `Σ score(trace) > τ`. Valid when the predicate is *stationary* (a user preference, a schema, a static config). Frequency-weighted recency is a fine proxy for importance when the underlying proposition does not change. - **Order-gated promotion (required for mutable predicates):** gate on `argmax_{trace ∈ log[predicate_key]} timestamp(trace) == support(f)`. Valid for any predicate whose truth value can be overwritten by an event — replica roles, feature flags, credentials, endpoint addresses, prices. The instance must classify each predicate at write time as `STATIONARY` or `MUTABLE`. The classification itself is the load-bearing decision; a misclassified `MUTABLE` predicate routed through score-gating reproduces the failure above silently. When classification is uncertain, default to `MUTABLE` and pay the log-scan cost. A second boundary: **decay must never evict a contradicting event before the fact it contradicts is itself evicted or demoted.** The eviction policy for episodic memory must treat contradiction events as *pinned* relative to the semantic record they touch. Otherwise the system reaches a state — durable false fact, no surviving counter-evidence — from which no retrieval score can recover, because the recovery signal has been garbage-collected. ## Operational Effect With order-gating and contradiction-pinning in place, the failover trace at `t=90m` blocks promotion of the `node-A` fact indefinitely: the `argmax` over `primary_replica` points at `node-B`, so the `node-A` cluster is never distilled. The `node-B` trace, being the latest, is eligible and is promoted on the next cadence. The semantic store reflects `node-B` within one distillation cycle of the event rather than never. The cost is a per-promotion log scan over the predicate-key index — O(events per key), not O(total log) — and a pinning table that prevents GC of contradiction events. Both are bounded and cheap relative to the failure they prevent. The invariant to encode in the distiller is not "promote salient traces" but "promote only the latest trace per mutable predicate-key, and never let a counter-event decay out from under a live semantic record." ```python from dataclasses import dataclass from enum import Enum from typing import Dict, List, Optional class PredicateClass(Enum): STATIONARY = "stationary" MUTABLE = "mutable" @dataclass(frozen=True) class EpisodicTrace: trace_id: str predicate_key: str value: str timestamp: int score: float # decay-weighted retrieval score class PromotionContaminationError(RuntimeError): """Raised when a distillation gate would promote a stale fact.""" def promote( fact: EpisodicTrace, log: List[EpisodicTrace], pred_class: PredicateClass, tau: float, ) -> Optional[EpisodicTrace]: key = fact.predicate_key peers = [t for t in log if t.predicate_key == key] if pred_class is PredicateClass.STATIONARY: # Score-gating is admissible: truth does not change under us. aggregate = sum(t.score for t in peers if t.value == fact.value) return fact if aggregate > tau else None # MUTABLE: gate on temporal ordering, never on aggregate score. latest = max(peers, key=lambda t: t.timestamp) if latest.trace_id != fact.trace_id: raise PromotionContaminationError( f"refusing to promote {fact.trace_id} ({key}={fact.value}): " f"superseded by {latest.trace_id} at t={latest.timestamp} " f"({key}={latest.value}); aggregate score {sum(t.score for t in peers)} " f"is not a truth signal for a mutable predicate" ) return fact def evict_episodic( log: List[EpisodicTrace], semantic_live: Dict[str, str], decay_threshold: float, ) -> List[EpisodicTrace]: """Evict low-score traces, but pin any event that contradicts a live semantic fact.""" survivors = [] for t in log: contradicts_live = ( t.predicate_key in semantic_live and semantic_live[t.predicate_key] != t.value ) if t.score < decay_threshold and not contradicts_live: continue survivors.append(t) return survivors ```