# Which invariants prevent episodic-to-semantic contamination during retrieval-time provenance resolution **Date of Record:** 2026 November 17 **Scope:** Applies to agent memory systems that maintain a strict separation between episodic stores (timestamped, source-bound event traces) and semantic stores (de-contextualized, generalized assertions), and that resolve contradictions at retrieval time using provenance metadata. Does not apply to single-store RAG systems, nor to systems where semantic facts are regenerated deterministically from episodes on every read (in which case the separation is a build-time concern, not a retrieval-time one). ## Core Distinction The non-obvious boundary is between **provenance-preserving generalization** and **provenance-erasing generalization**. Both produce a semantic assertion from a set of episodic traces. The former keeps a back-pointer to the *set* of episodes that support it, plus the *validity interval* over which those episodes held. The latter produces a de-contextualized fact—"the user's timezone is UTC+2"—with no record of *when* that was true or *which* episodes established it. The failure mode is not that generalization happens. It is that **contradiction resolution at retrieval time has no way to arbitrate between two semantic facts if neither carries the episode-set and validity interval that would let the resolver decide which one is current, which is superseded, or which is scoped to a different entity or context.** The resolver then falls back to recency-by-write-time, which is a proxy that silently conflates *when the fact was written* with *when the fact was true*. ## What Was Observed A system maintained episodic traces for a long-running assistant: session logs, tool outputs, user statements, each with `(source_id, observed_at, entity, predicate, value)`. A background job folded episodic traces into a semantic store keyed by `(entity, predicate)` with a single `value` and a `written_at` timestamp. On fold, the older value was overwritten. Two facts were established at different times: - Episode E1 (2026-03-02): user states "my primary workstation is the Linux box." Folded to semantic: `workstation = linux`, `written_at = 2026-03-02`. - Episode E2 (2026-09-18): user states "I moved my primary workstation to the Mac." Folded to semantic: `workstation = mac`, `written_at = 2026-09-18`. This looked correct. The failure surfaced on a different predicate. A third episode E3 (2026-04-11) established `package_manager = apt` *conditional on* `workstation = linux`. The fold job, having no representation for conditionality, stored `package_manager = apt` as unconditional, `written_at = 2026-04-11`. After E2 superseded the workstation fact, the resolver still returned `package_manager = apt` as current—because its `written_at` (April) was later than nothing that contradicted it, and the conditional guard had been erased at fold time. The agent then issued `apt install` instructions to a macOS host. The root cause was not staleness. It was that **the semantic store had thrown away the episode-set and the guard predicate, so retrieval-time provenance resolution had nothing to resolve against.** The contradiction between `workstation=mac` and the precondition of `package_manager=apt` was representable in the episodic store and unrepresentable in the semantic store. ## Condition of Validity The invariant holds only if three conditions are jointly satisfied at every semantic write: 1. **Episode-set retention.** Every semantic assertion carries the non-empty set of episode IDs that justify it. An assertion with an empty episode-set is not a semantic fact; it is an unverified claim and must be quarantined, not retrievable as current. 2. **Validity interval, not write timestamp.** Every assertion carries `[valid_from, valid_to)` derived from the observed-at times of its supporting episodes, with `valid_to = ∞` only when an explicit superseding episode exists. Write time is metadata about the store, never about the world. 3. **Guard preservation.** Any conditionality present in the episodes (entity scoping, environment predicates, temporal qualifiers) must survive the fold as a structured guard. A fold that drops a guard is a lossy transform and must be rejected, not committed. The invariant does **not** hold—and retrieval-time resolution cannot be trusted—if any of the three is violated at write time. This is the key operational point: **provenance resolution is a read-time operation that can only arbitrate between assertions whose write-time provenance was preserved.** You cannot recover a dropped guard at read time. The boundary is at the fold, not at the query. ## Decision Boundary At retrieval, when two semantic assertions for `(entity, predicate)` are both live, the resolver must choose among exactly four outcomes, and must never silently pick one: - **Supersession:** intervals are disjoint and ordered; return the assertion whose interval contains the query time. This requires condition 2. - **Contradiction:** intervals overlap and values differ. Do not arbitrate by write time. Return *both*, flagged, with their episode-sets attached, and let the caller (or a resolution policy) decide. This requires condition 1. - **Scoped coexistence:** values differ but guards name disjoint scopes (different entities, different environments). Return the one whose guard is satisfied by the query context. This requires condition 3. - **Unsupported:** one assertion has an empty episode-set. Exclude it from "current" results entirely. The boundary failure occurs precisely when the resolver is forced into a fifth, implicit outcome—"pick the most recently written"—because the store did not preserve enough to permit any of the four. That fallback is the observable symptom of a violated write-time invariant, not a retrieval bug. ## Operational Effect When the three conditions are enforced, contradiction resolution becomes a *total function* over the assertion set: every pair of live assertions maps to exactly one of the four outcomes above, and the "most recent write wins" fallback is unreachable. The measurable effect is that conditional facts (the `package_manager` case) are either correctly scoped to their guard or correctly invalidated when the guard's referent changes—never silently promoted to unconditional currency. When they are not enforced, the system exhibits *provenance drift*: semantic assertions that are individually well-formed but collectively inconsistent, with no read-time mechanism able to detect the inconsistency because the information needed to detect it was discarded upstream. The failure is silent, survives restarts, and compounds—each subsequent fold overwrites the evidence that would have exposed it. The operational rule is therefore: **reject lossy folds at write time and treat the rejection as a hard error, because read-time resolution cannot repair what write-time generalization destroyed.** ```python from dataclasses import dataclass, field from typing import Optional class ProvenanceInvariantError(RuntimeError): """Raised when a semantic fold would violate episodic/semantic separation.""" pass @dataclass(frozen=True) class SemanticAssertion: entity: str predicate: str value: str episode_ids: frozenset valid_from: float valid_to: Optional[float] # None == open interval guard: Optional[str] = None # structured precondition, e.g. "workstation=linux" def fold_episode( episodes: list, entity: str, predicate: str, value: str, valid_from: float, valid_to: Optional[float], guard: Optional[str], ) -> SemanticAssertion: if not episodes: raise ProvenanceInvariantError( f"cannot fold {entity}.{predicate}: empty episode-set" ) if valid_from is None: raise ProvenanceInvariantError( f"cannot fold {entity}.{predicate}: missing validity interval" ) # Guard preservation: if any supporting episode was conditional, the # folded assertion must carry that guard. Dropping it is a lossy fold. conditional_episodes = [e for e in episodes if getattr(e, "guard", None)] if conditional_episodes and guard is None: raise ProvenanceInvariantError( f"lossy fold {entity}.{predicate}: {len(conditional_episodes)} " f"conditional episode(s) folded without guard" ) return SemanticAssertion( entity=entity, predicate=predicate, value=value, episode_ids=frozenset(e.id for e in episodes), valid_from=valid_from, valid_to=valid_to, guard=guard, ) def resolve(assertions: list, query_time: float, context: dict) -> list: live = [ a for a in assertions if a.valid_from <= query_time and (a.valid_to is None or query_time < a.valid_to) ] if not live: return [] if len(live) == 1: return live # Multiple live assertions: never fall back to write-time recency. values = {a.value for a in live} if len(values) > 1: scoped = [ a for a in live if a.guard is None or _guard_satisfied(a.guard, context) ] if len(scoped) == len(live): raise ProvenanceInvariantError( f"unresolvable contradiction on {live[0].entity}.{live[0].predicate}: " f"overlapping intervals with no disjoint guard; refusing recency fallback" ) return scoped return live def _guard_satisfied(guard: str, context: dict) -> bool: key, _, val = guard.partition("=") return context.get(key) == val ```