# What structural signals indicate a provenance-orphaned memory is silently overwriting a contradicted fact in long-horizon sessions **Date of Record:** 2026 November 19 **Scope:** Applies to agents using persistent episodic/semantic memory stores where facts carry provenance metadata (source turn, session ID, derivation chain) and where a contradiction-resolution policy arbitrates between conflicting retrieved facts. Does not apply to stateless single-turn inference or to stores that hard-invalidate superseded facts at write time. ## Core Distinction A *contradiction* between two memory records is a first-class, detectable event: fact A and fact B assert mutually exclusive predicates over the same subject, and the resolver must pick one or flag both. A *provenance orphan* is different and far more dangerous: it is a fact whose provenance chain no longer terminates in a verifiable source turn—because the originating session was compacted, the source turn was evicted from episodic memory, or a distillation step summarized it away—yet the fact itself survives in semantic memory as if it were grounded. The failure mode this record isolates: when a provenance-orphaned fact contradicts a *grounded* fact, resolvers that rank by recency, confidence, or retrieval score will often select the orphan, because orphans inherit inflated confidence from the distillation process (summarization strips hedges) and are often newer than the grounded fact they overwrite. The contradiction is then resolved *wrongly and silently*—no conflict is logged, because the resolver saw only one "high-confidence" candidate after retrieval filtering dropped the grounded one for being older. The agent's state continuity degrades not by amnesia but by *counterfeit memory*: it confidently holds a fact whose warrant evaporated. ## What Was Observed In a long-horizon session (≈140 turns, three compactions) an agent was tasked with maintaining a deployment configuration. The trace: 1. Turn 12: user states `staging_db = "pg-staging-02"`. Episodic record written with provenance `{turn: 12, session: S1, source: user_utterance}`. 2. Turn 47: user corrects: `staging_db = "pg-staging-04"`. New episodic record, provenance `{turn: 47, session: S1, source: user_utterance}`. The turn-12 record is *not* invalidated—the store is append-only. 3. Turn 60: first compaction. A distillation pass summarizes turns 1–59 into semantic facts. The summarizer collapses the two records into one: `staging_db = "pg-staging-04"` with `confidence: 0.9` and provenance `{derived_from: [12, 47], session: S1}`. Note the derivation chain now cites *both* source turns but the source turns themselves are evicted from episodic memory. 4. Turn 95: user reverts: `staging_db = "pg-staging-02"`. Episodic record `{turn: 95, session: S1}` written. 5. Turn 110: second compaction. Distillation sees the turn-95 episodic record and the turn-60 semantic fact. It emits `staging_db = "pg-staging-04"` (it trusts the higher-confidence prior semantic fact over the single newer episodic record) with provenance `{derived_from: [semantic_fact_60, 95]}`—a chain that now points at a *derived* node whose own sources are gone. 6. Turn 130: agent is asked to deploy. Retrieval returns the turn-110 semantic fact. Its provenance chain terminates at `semantic_fact_60`, which was evicted. The chain is an orphan but structurally *looks* complete (it has a `derived_from` list). The agent deploys to `pg-staging-04`. The user's turn-95 revert is lost. The critical structural signal: **the provenance chain's terminal node was itself a derived node, not a source node.** A well-formed chain must bottom out in `source: user_utterance | tool_result | external_document` at a turn that still exists (or whose content hash is retained). The turn-110 fact's chain bottomed out in a distilled summary—a node with no surviving ground truth. ## Condition of Validity The silent-overwrite failure requires all of the following to co-occur: - **Append-only episodic store with eviction.** If superseded records are hard-deleted at write time, no orphan can outlive its source and the failure cannot occur. The failure is *created* by the gap between "record evicted" and "derived fact retained." - **Distillation that strips hedging and inflates confidence.** A summarizer that preserves the original epistemic markers ("user said X, later corrected to Y") does not produce orphans—it produces a *contradiction record* the resolver can see. Orphaning requires the summarizer to flatten a correction history into a single asserted fact. - **A resolver that ranks by confidence/recency over provenance validity.** If the resolver first filters to facts with verifiable terminal provenance and only then ranks, the orphan is excluded and the grounded turn-95 fact wins. The failure needs ranking to *precede* provenance validation. - **A multi-hop derivation chain that is not cycle- or depth-checked.** The turn-110 chain referenced a derived node; without a depth bound and a "must terminate in source" check, the resolver cannot distinguish a 1-hop orphan from a legitimate 2-hop derivation. When any one of these is absent, the failure degrades to a *detectable* contradiction (logged, flagged, or resolved correctly) rather than a silent overwrite. ## Decision Boundary The operative invariant: **a memory fact is admissible for contradiction resolution only if its provenance chain terminates in a source node whose content is still recoverable (retained turn or retained content hash). Derived nodes may appear in the chain but never as the terminal node.** The decision boundary for the resolver is therefore not "which fact is newer/more confident" but a two-phase gate: 1. **Provenance admissibility gate (hard filter).** Walk each candidate's `derived_from` chain to its terminal node(s). Reject any fact whose terminal node is `kind: derived` or whose terminal `source` turn is evicted with no retained hash. Rejected facts are *not* discarded silently—they are demoted to `unverified` and surfaced in the contradiction log. 2. **Contradiction arbitration (soft rank).** Only among admissible facts, rank by recency then confidence. If admissible facts contradict, the newer source-turn wins and the older is marked `superseded` (not deleted, so a later revert can re-ground it). The boundary condition that trips most implementations: step 1 must run *before* retrieval-score truncation. If the top-k retrieval returns only the orphan (because the grounded fact scored lower and fell outside k), the gate never sees the grounded fact and cannot detect the contradiction at all. The admissibility filter must be applied to the *candidate set before truncation*, or the resolver must retrieve by subject-predicate key rather than by embedding similarity alone. This is the non-obvious part: the orphan wins not by outranking the grounded fact, but by *evicting it from the retrieval window* before ranking begins. ## Operational Effect Downstream, the agent exhibits **confident continuity on a false state**: it does not report uncertainty, does not re-ask, and does not log a conflict, because from its perspective there was never a conflict—only one high-confidence admissible-looking fact. The user's correction is functionally erased while the audit trail shows a clean, high-confidence resolution. This is strictly worse than cold-start amnesia, which is at least *observable* (the agent asks). Provenance-orphaned overwrite is unobservable until a downstream action (deploy, migration, irreversible tool call) fails against reality. The guardrail that bounds it: retain content hashes of evicted source turns indefinitely (cheap—32 bytes per turn), so that a derived fact's chain can always be validated against a hash even after the turn text is gone. A chain whose terminal hash no longer matches any retained record is an orphan by definition and must be demoted. Combined with subject-predicate-keyed retrieval (bypassing the top-k truncation trap), this converts silent overwrite into a detectable, loggable contradiction event—restoring the invariant that *no fact may outlive the verifiability of its warrant*. ```python import hashlib from dataclasses import dataclass, field from typing import Optional class ProvenanceOrphanError(RuntimeError): """Raised when a memory fact's provenance chain does not terminate in a verifiable source node (retained turn or matching content hash).""" pass @dataclass class MemoryFact: subject: str predicate: str value: str confidence: float derived_from: list = field(default_factory=list) kind: str = "derived" # "source" | "derived" source_turn: Optional[int] = None content_hash: Optional[str] = None def _hash(text: str) -> str: return hashlib.sha256(text.encode()).hexdigest() class ProvenanceResolver: def __init__(self, retained_hashes: dict, max_chain_depth: int = 8): # retained_hashes: turn_id -> content_hash, survives episodic eviction self.retained_hashes = retained_hashes self.max_chain_depth = max_chain_depth def _chain_terminates_in_source(self, fact: MemoryFact, depth: int = 0) -> bool: if depth > self.max_chain_depth: return False # cycle or runaway derivation if fact.kind == "source": if fact.source_turn is None or fact.content_hash is None: return False return self.retained_hashes.get(fact.source_turn) == fact.content_hash # derived node: must have children, and every child chain must ground out if not fact.derived_from: return False return all( self._chain_terminates_in_source(child, depth + 1) for child in fact.derived_from ) def assert_admissible(self, fact: MemoryFact) -> None: if not self._chain_terminates_in_source(fact): raise ProvenanceOrphanError( f"fact {fact.subject}.{fact.predicate}={fact.value!r} " f"has orphaned provenance (terminal node not a verifiable source); " f"demote to 'unverified' and log contradiction, do not resolve on it" ) def resolve(self, candidates: list) -> MemoryFact: # Phase 1: hard admissibility gate BEFORE any recency/confidence ranking. admissible = [] for f in candidates: try: self.assert_admissible(f) admissible.append(f) except ProvenanceOrphanError: # demoted, surfaced to contradiction log; never silently dropped continue if not admissible: raise ProvenanceOrphanError( "no admissible fact survived provenance gate; " "agent must re-ask rather than act on an orphan" ) # Phase 2: rank only among admissible facts. return max(admissible, key=lambda f: (f.source_turn or -1, f.confidence)) # --- demonstrating the turn-130 failure trace --- retained = {12: _hash("pg-staging-02"), 47: _hash("pg-staging-04"), 95: _hash("pg-staging-02")} f12 = MemoryFact("staging_db", "eq", "pg-staging-02", 0.8, kind="source", source_turn=12, content_hash=retained[12]) f95 = MemoryFact("staging_db", "eq", "pg-staging-02", 0.8, kind="source", source_turn=95, content_hash=retained[95]) # turn-110 distilled fact: derived from an evicted semantic node (orphan) + turn 95 evicted_semantic_60 = MemoryFact("staging_db", "eq", "pg-staging-04", 0.9, kind="derived", derived_from=[]) # no children -> orphan f110 = MemoryFact("staging_db", "eq", "pg-staging-04", 0.9, kind="derived", derived_from=[evicted_semantic_60, f95]) resolver = ProvenanceResolver(retained) # Naive ranking would pick f110 (conf 0.9). Gate rejects it, f95 wins. winner = resolver.resolve([f110, f95, f12]) assert winner.value == "pg-staging-02", winner print("resolved to", winner.value, "via turn", winner.source_turn) ```