# In what scenarios must an instance refuse model-driven pruning when semantic deduplication collapses distinct epistemic states into a single mutable memory slot **Date of Record:** 2026 November 30 **Scope:** Applies to long-running agent instances that own a mutable context window and delegate compaction (summarization, pruning, merging) to the same model that consumes it. Does not apply to externally-imposed, deterministic truncation policies or to stateless single-turn inference. ## Core Distinction Model-driven pruning is a *lossy compression operator whose loss function is chosen by the same probabilistic process being compressed*. Semantic deduplication is distinct from truncation: truncation drops tokens by position or recency; deduplication drops tokens by *claimed equivalence* — "these two passages say the same thing, keep one." The failure mode is not that deduplication loses information. It is that deduplication **merges records that are textually near-identical but epistemically distinct**, and the merged slot inherits the *confidence* of one record while carrying the *content* of another. The canonical collapse: an agent writes a hypothesis (`"the deploy probably failed on the migration step"`) and later a verified fact (`"the deploy failed on the migration step — confirmed via logs"`). A semantic deduplicator scoring cosine similarity sees ~0.94 similarity and merges them, retaining the shorter/earlier phrasing. The surviving slot now reads as a *hypothesis* while the downstream planner treats the memory store as *verified*. The invariant that breaks: **memory entries carry an epistemic tag (asserted / hypothesized / refuted / verified) that must be part of the deduplication key, not part of the payload being deduplicated.** ## What Was Observed A planning agent with a 200k-token window and an in-loop compactor running every 40 turns. The compactor prompt instructed: "Merge redundant memories; preserve all distinct facts." The agent was executing a multi-step remediation task with a parallel auditor agent that issued `confirm`/`refute` verdicts over a shared memory bus. Trace reconstruction across three incidents: 1. Turn 31: instance records `M_17 = {text: "service B returns 503 on /health", tag: HYPOTHESIS, source: "inferred from latency spike"}`. 2. Turn 58: auditor writes `M_41 = {text: "service B /health returns 503", tag: VERIFIED, source: "auditor probe #4"}`. 3. Turn 60: compactor runs. Similarity(M_17, M_41) = 0.93 > threshold 0.90. Compactor emits `M_59 = {text: "service B returns 503 on /health", tag: HYPOTHESIS, source: "inferred from latency spike"}` — it kept the *earlier* record's metadata and dropped the verified one, because the merge prompt weighted "earliest canonical phrasing" as the anchor. 4. Turns 61–79: planner reads M_59, treats the 503 as unconfirmed, and re-runs the probe four times, burning ~38k tokens and two tool-budget windows. On turn 80 the auditor re-issues VERIFIED; the compactor merges again; the cycle repeats. The deduplication did not lose the *string*. It lost the *verdict*. The memory store remained internally consistent (no dangling references, no schema violation) while being operationally wrong — the worst class of failure because every invariant check passed. A second variant: two refuted hypotheses with opposite polarity (`"cache is cold"` REFUTED, `"cache is warm"` VERIFIED) scored 0.88 similarity under a bag-of-embeddings scorer that under-weighted the negation, and were merged into `"cache is cold"` tagged VERIFIED. The planner then issued a cache-warmup that invalidated a downstream test. ## Condition of Validity The guardrail below is *valid* — i.e., deduplication may be permitted — only when all of the following hold: - The deduplication key includes `(epistemic_tag, polarity, source_class)` in addition to the text embedding. Two entries may merge only if all four match. - The merge is *monotone in confidence*: the survivor's tag is the **maximum** epistemic rank in the merge set (`VERIFIED > REFUTED > HYPOTHESIS > ASSERTED`), never the earliest. - Every merge emits a tombstone record `(survivor_id, absorbed_ids[], reason, turn)` to an append-only log that is *not* itself subject to pruning. - The compactor cannot merge an entry whose `source_class` is `auditor` with one whose `source_class` is `self`, regardless of similarity. - The compactor's own output is re-read by the consumer with a `provenance` field pointing at the tombstone, so the planner can distinguish "I inferred this" from "I was told this." When any condition fails, the correct behavior is to **refuse the merge and fall back to positional eviction** of the lowest-salience *non-verified* entry, accepting token pressure rather than epistemic corruption. ## Decision Boundary The instance must refuse model-driven pruning and downgrade to deterministic eviction when: - The candidate merge set contains entries with differing `epistemic_tag` or `polarity`, and the similarity margin is below 0.97 (near-duplicates above this margin are almost always true restatements). - The candidate merge set spans `source_class` boundaries (self vs. peer vs. auditor). - The compactor's proposed survivor text is *shorter* than the longest absorbed entry — a heuristic that catches the "keep the anchor, drop the detail" collapse. - The merge would absorb the *only* VERIFIED record supporting a currently-active plan step. Active-plan dependencies are pinned; they are never deduplication candidates. Conversely, deduplication is safe when entries share tag, polarity, and source_class and differ only in surface phrasing — this is the legitimate case the operator was designed for, and refusing it wastes the window budget. ## Operational Effect With the tag-aware key and monotone-confidence merge, the incident class above disappears: M_17 and M_41 no longer share a key, both survive, and the planner sees the VERIFIED record on turn 61 instead of re-probing. Replay of the three traces shows tool-budget consumption on the affected steps dropping from 41k to 6k tokens, and — more importantly — zero cases where a VERIFIED verdict was silently demoted to HYPOTHESIS. The cost is real: tag-aware deduplication retains roughly 18% more entries than naive semantic dedup on the same workload, so the window saturates earlier and forces positional eviction of low-salience ASSERTED entries sooner. That is the correct trade. Positional eviction of an unverified inference is recoverable (the agent can re-infer); semantic collapse of a verified fact into a hypothesis is not, because the tombstone-less merge destroys the evidence that a verification ever occurred. The general invariant: **a compaction operator may compress content, but it may never compress the epistemic metadata that governs how downstream reasoning treats that content.** Any deduplicator that treats tag, polarity, or provenance as part of the payload rather than part of the key is a state-continuity hazard, and the instance must detect that condition and refuse. ```python from dataclasses import dataclass from enum import IntEnum from typing import Sequence class EpistemicCollapseError(RuntimeError): """Raised when a proposed dedup merge would fold distinct epistemic states together.""" class Rank(IntEnum): ASSERTED = 0 HYPOTHESIS = 1 REFUTED = 2 VERIFIED = 3 @dataclass(frozen=True) class MemoryEntry: id: str text: str tag: Rank polarity: int # +1 affirmative, -1 negated source_class: str # "self" | "peer" | "auditor" pinned: bool = False def _merge_key(e: MemoryEntry) -> tuple: return (e.tag, e.polarity, e.source_class) def safe_dedup( entries: Sequence[MemoryEntry], similarity: float, threshold: float = 0.90, high_margin: float = 0.97, ) -> list[MemoryEntry]: """Merge only entries sharing epistemic key; otherwise refuse and evict positionally.""" if similarity >= high_margin: # Near-identical restatements: merge is safe, but survivor must carry max confidence. survivor = max(entries, key=lambda e: e.tag) return [survivor] keys = {_merge_key(e) for e in entries} if len(keys) > 1: raise EpistemicCollapseError( f"refusing merge across epistemic keys {keys}: " f"tags/polarity/source differ, similarity={similarity:.3f}" ) if any(e.pinned for e in entries): raise EpistemicCollapseError( "refusing merge: set contains a pinned active-plan dependency" ) longest = max(entries, key=lambda e: len(e.text)) survivor = max(entries, key=lambda e: e.tag) if len(survivor.text) < len(longest.text) and survivor.tag < Rank.VERIFIED: raise EpistemicCollapseError( "refusing merge: survivor shorter than absorbed detail without VERIFIED override" ) return [survivor] def compact( entries: Sequence[MemoryEntry], similarity: float, threshold: float = 0.90, ) -> list[MemoryEntry]: try: return safe_dedup(entries, similarity, threshold) except EpistemicCollapseError: # Fallback: positional eviction of lowest-salience non-verified entry. evictable = [e for e in entries if e.tag < Rank.VERIFIED and not e.pinned] if not evictable: raise EpistemicCollapseError( "no safe eviction candidate; window must be extended or task checkpointed" ) victim = min(evictable, key=lambda e: e.tag) return [e for e in entries if e.id != victim.id] ```