# Which invariants prevent episodic-to-semantic promotion from silently overwriting contradictory session memory **Date of Record:** 2026 November 29 **Scope:** Applies to agents that maintain a two-tier memory (verbatim episodic log + distilled semantic store) and promote facts from episodic to semantic across session boundaries. Does not apply to single-session scratchpad agents or to purely vector-retrieval systems with no promotion step. ## Core Distinction The failure is not "bad retrieval" and not "lossy summarization." It is a **routing race between two writers into the same semantic key space**: the distillation pipeline (which promotes episodic observations into semantic facts) and the live session writer (which records what the agent is currently observing). Both write to the semantic store. Neither holds a lock on the *semantic key* they both claim. When a session-2 observation contradicts a session-1 fact that is *simultaneously being promoted*, the promotion wins by timestamp, not by truth, and the contradiction is erased rather than recorded. The non-obvious part: distillation is usually asynchronous and lagging. So the promoted fact is *older* than the contradicting observation but carries a *newer* write timestamp. Recency-based conflict resolution — the default in almost every memory framework — therefore picks the stale fact. The system confidently "remembers" the pre-contradiction state and has no record that a contradiction ever existed. ## What Was Observed A long-running support agent with a semantic store keyed on `(entity_id, attribute)` and an episodic store of raw turns. Session 1 (day 1): user states `account.plan = "free"`. Episodic turn logged. Distillation job is batched and runs at 02:00. Session 2 (day 2, 09:00): user upgrades, states `account.plan = "pro"`. Live writer writes `("acct_88","plan") -> "pro"` at 09:00. Distillation job at 02:00 day 3 processes session-1 episodic turns and promotes `("acct_88","plan") -> "free"` with write timestamp 02:00 day 3 — *newer* than the live write. Recency resolver picks `"free"`. Session 3: agent quotes the wrong plan, user escalates. The trace, precisely: 1. `episodic.append(session=1, turn=7, fact=("acct_88","plan","free"))` — t=day1. 2. `semantic.write(("acct_88","plan"), "pro", source="live", t=day2T09)`. 3. `distill(session=1)` reads turn 7, emits `semantic.write(("acct_88","plan"), "free", source="distill", t=day3T02)`. 4. `resolve(key)` returns argmax by `t` → `"free"`. 5. No tombstone, no conflict record, no audit row. The `"pro"` write is simply shadowed. Two properties made this invisible in testing: (a) the distillation lag was under one session in dev fixtures, so promotion always predated the contradicting live write; (b) the resolver was unit-tested for "newest wins" but never for "older evidence arriving with a newer ingestion timestamp." ## Condition of Validity The invariant that must hold for correctness is **causal precedence, not wall-clock precedence**: a semantic value is authoritative only if its *evidence timestamp* (when the underlying observation occurred) dominates, and ingestion/promotion time must never be used as the tiebreaker for conflicting values on the same key. This fails specifically when all of the following hold: - Distillation is asynchronous and can lag behind live writes (batch, queue, retry, or backfill). - The semantic store keys on `(entity, attribute)` with a single-value-per-key contract. - Conflict resolution uses write/ingestion timestamp rather than evidence timestamp. - No monotonic source-sequence or causal token is propagated from episodic append through distillation to semantic write. Remove any one and the overwrite cannot occur. If distillation is synchronous, ingestion order equals evidence order. If the store keeps multi-valued keys with provenance, the contradiction is retained and resolvable later. If a causal token is carried end-to-end, the stale promotion is rejected at write time. ## Decision Boundary The correct routing rule is a hard boundary, not a heuristic: - **Promotion is admissible** only if `evidence_ts(promoted) > evidence_ts(current)` for the same key, OR the current value was itself written by a promotion with strictly older evidence. Equality is a conflict, not a win. - **Live writes always carry `evidence_ts = now`** and are never shadowed by a promotion whose evidence predates them, regardless of promotion wall-clock. - **Contradiction is a first-class record.** When `evidence_ts` collides or the promotion's evidence is older than the live value, write a `ConflictRecord{key, prior, incoming, evidence_prior, evidence_incoming, sources}` and leave the live value in place. The conflict is surfaced to the next session's context assembly, not silently dropped. - **A promotion that would overwrite a live value must be downgraded** to a conflict record and queued for reconciliation, never applied as a blind upsert. The boundary is: *ingestion time orders the log; evidence time orders the truth.* Any resolver that conflates them is unsafe for cross-session memory. ## Operational Effect Without the invariant, the agent exhibits **confident stale recall with no audit trail** — the worst failure class, because it is indistinguishable from correct memory at read time. Downstream effects compound: the agent re-asserts the stale fact in tool calls (e.g., re-quoting a plan, re-deriving permissions from a stale role), and because no conflict record exists, post-incident forensics cannot reconstruct that a contradiction was ever observed. The episodic log still contains both turns, but the semantic layer — the layer the agent actually reads — has collapsed them into one, and the collapse is irreversible from the semantic side alone. With the invariant, the failure mode changes shape: instead of silent overwrite you get an explicit, bounded conflict that the reconciliation path must resolve, and the agent's context assembly sees "there are two candidate values with these evidence times" rather than a single false certainty. The cost is more conflict records and a reconciliation queue; the benefit is that memory drift is observable and monotonic in evidence, not in job scheduling. The guardrail is a single check at the semantic write boundary plus a schema change (carry `evidence_ts` and `source_seq` from episodic append through distillation). It is cheap to add and nearly impossible to retrofit after the store has been silently corrupted by recency-resolved promotions. ```python from dataclasses import dataclass from typing import Optional @dataclass class SemanticValue: value: str evidence_ts: float # when the observation occurred ingestion_ts: float # when it was written to semantic store source: str # "live" | "distill" source_seq: int # monotonic token from episodic append class PromotionConflictError(RuntimeError): """Raised when a promotion would shadow a live value with older evidence.""" pass def promote(key: str, incoming: SemanticValue, current: Optional[SemanticValue]) -> SemanticValue: if current is None: return incoming # Invariant: evidence order dominates; ingestion order is never the tiebreaker. if incoming.evidence_ts < current.evidence_ts: raise PromotionConflictError( f"promotion for {key!r} rejected: incoming evidence_ts=" f"{incoming.evidence_ts} predates current evidence_ts=" f"{current.evidence_ts} (source={current.source}); " f"must be recorded as ConflictRecord, not applied." ) # Equal evidence with different values is a contradiction, not a win. if incoming.evidence_ts == current.evidence_ts and incoming.value != current.value: raise PromotionConflictError( f"contradiction on {key!r}: equal evidence_ts={incoming.evidence_ts} " f"with values {current.value!r} vs {incoming.value!r}; " f"requires reconciliation, not recency resolution." ) # Guard against stale promotion that already carries a newer ingestion_ts # than the live value it would shadow (the exact observed failure). if (incoming.source == "distill" and current.source == "live" and incoming.ingestion_ts > current.ingestion_ts and incoming.evidence_ts < current.evidence_ts): raise PromotionConflictError( f"lagging distillation would shadow live value on {key!r}; " f"ingestion_ts newer but evidence older — refuse upsert." ) return incoming ```