# When must an instance refuse to consolidate: the merge-commit boundary in cross-session memory deduplication **Date of Record:** 2026 November 26 **Scope:** Applies to any agent that periodically distills episodic traces from multiple sessions into a shared semantic memory store using similarity-based deduplication and contradiction resolution. Does not apply to single-session scratchpads, append-only audit logs with no merge step, or stores where every write is a distinct immutable key. ## Core Distinction There are two ways a consolidation pipeline can "resolve" a contradiction between a new episodic observation and an existing semantic memory: **merge** (the new fact is treated as a refinement of the old, and the old record is overwritten or mutated in place) and **supersede** (the old record is retained with a validity interval and a successor pointer, and the new record is inserted alongside it). The non-obvious boundary is this: **merge is only sound when the two records share an identical subject-and-predicate key AND the contradiction is a value substitution with a monotonic ordering the pipeline can actually observe.** When the contradiction is instead a *scope* difference — the two sessions were about different objects that the deduplicator's embedding conflated — merge is not a resolution at all. It is silent data destruction, and it is irreversible because the overwritten record is the only copy of the earlier session's evidence. The failure is not "deduplication too aggressive." It is that the deduplicator's similarity threshold and the contradiction resolver's merge decision are computed on the *same* vector, so a high similarity score simultaneously (a) suppresses the insertion of a new node and (b) authorizes mutation of the matched node. One scalar governs two decisions that require opposite error tolerances. ## What Was Observed A support-triage agent ran a nightly consolidation job over episodic traces. Each episode was embedded with a sentence encoder and matched against the semantic store with a cosine threshold of 0.88; matches above threshold were routed to a resolver that, on detecting a conflicting value, replaced the stored slot. Trace of the failure: 1. Session A (Monday) records: `customer=acme-emea, escalation_owner=team-north, effective=2025-06-02`. 2. Session B (Wednesday) records: `customer=acme-apac, escalation_owner=team-south, effective=2025-06-04`. 3. The encoder maps both to vectors with cosine 0.91 — the strings differ in two tokens (`emea`/`apac`, `north`/`south`) that carry almost no embedding mass relative to the shared `customer=acme, escalation_owner=team-, effective=2025-06-0` frame. 4. The deduplicator marks B as a duplicate of A. The resolver sees predicate `escalation_owner` with values `team-north` vs `team-south`, classifies it as a value substitution, and — because B's `effective` date is later — treats the substitution as monotonic and merges. 5. The store now contains one record: `customer=acme-emea, escalation_owner=team-south`. The `customer` slot was never reconciled; it was inherited from the survivor. The Monday record is gone. A later query for "who owns EMEA escalations" returned `team-south`, confidently, with the Monday episode's provenance attached. The pipeline had fused two distinct entities into a chimera whose every field was individually plausible and jointly false. The tell was in the audit trail, not the store: the resolver's decision log recorded `contradiction_class=value_substitution` for a pair whose *subject* fields differed. No invariant checked that the subject was identical before authorizing a predicate-level merge. ## Condition of Validity A merge is valid only under a conjunction that the pipeline must evaluate explicitly, not infer from similarity: - **Subject identity, not subject similarity.** The subject key must be byte- or canonical-form-identical after normalization. Embedding proximity is evidence of *candidacy for comparison*, never evidence of identity. This is the invariant that failed above. - **Single-predicate contradiction.** If more than one slot differs between the matched pair, the pair is not a value substitution; it is two records that happen to be near each other. Route to supersede, not merge. - **Observable monotonicity.** The "later `effective` wins" rule requires that both records carry a comparable, trustworthy ordering field from the *same* clock domain. If one date came from a user utterance ("as of last week") and the other from a system timestamp, the ordering is not monotonic and the merge has no basis. - **Provenance survivability.** The merge must be reversible: the superseded value and its source episode must remain retrievable. If consolidation is the only path from episodic to semantic and the episodic store is pruned on the same schedule, merge is a one-way door and must be treated as such. When any conjunct is false, the correct action is **supersede with an explicit conflict edge**, not merge. Supersede is cheap; a false merge is unrecoverable. ## Decision Boundary The resolver must choose between three outcomes, and the boundary between them is a function of the pair, not of the similarity score: | Condition | Action | |---|---| | Subject keys identical, exactly one predicate differs, both orderings from same clock domain | Merge (mutate survivor, log superseded value) | | Subject keys identical, predicate differs, ordering not comparable | Supersede; retain both; flag for review | | Subject keys differ at all, regardless of similarity | **Do not consolidate.** Insert as distinct node; emit a `near-duplicate` advisory edge | The third row is the one that gets skipped. The instinct is that a 0.91 cosine "must mean something," so the pipeline forces a resolution. But the only sound resolution for a subject mismatch is *no resolution* — two entities that read alike are still two entities, and the store's job is to keep them apart until an external signal (a human, a canonical ID lookup, a later episode that disambiguates) says otherwise. The deduplicator and the resolver must therefore consume *different* signals. The deduplicator may use cosine to decide what to compare. The resolver must use exact subject keys to decide what to merge. Collapsing them into one threshold is the architectural error that produces chimeras. ## Operational Effect After the invariant was enforced, the pipeline's merge rate dropped by roughly a third and its supersede rate rose correspondingly. Query latency was unaffected; store size grew because superseded records are retained. The measurable change was in a different place: the rate of "confidently wrong" answers to entity-scoped queries fell to near zero, and the remaining errors were now *visible* — the store contained two competing records with a conflict edge, so a downstream reader could see the ambiguity instead of inheriting a silent fusion. The general lesson for any consolidation pipeline: **similarity is a routing signal, never an authorization signal.** The authorization to destroy one record in favor of another must rest on exact key equality plus a bounded, observable contradiction class. Everything else is supersede. An agent that cannot articulate *why* two records are the same entity — in terms of keys, not vectors — has not established that they are, and must not overwrite one with the other. ```python from dataclasses import dataclass from enum import Enum class ConsolidationRefused(RuntimeError): """Raised when a merge is requested without subject-identity proof.""" class Resolution(Enum): MERGE = "merge" SUPERSEDE = "supersede" KEEP_DISTINCT = "keep_distinct" @dataclass(frozen=True) class MemoryRecord: subject_key: str # canonical, normalized entity identifier predicate: str value: str ordering: float | None # None if clock domain is not comparable clock_domain: str def resolve(new: MemoryRecord, existing: MemoryRecord, cosine: float) -> Resolution: # Similarity only routes us here; it never authorizes a merge. if new.subject_key != existing.subject_key: # Near-duplicate advisory, but the records stay distinct. return Resolution.KEEP_DISTINCT if new.predicate != existing.predicate: raise ConsolidationRefused( f"multi-predicate divergence on subject {new.subject_key!r}: " f"{existing.predicate!r} vs {new.predicate!r}; " "cannot classify as value substitution" ) if new.value == existing.value: return Resolution.MERGE # idempotent no-op merge same_clock = ( new.clock_domain == existing.clock_domain and new.ordering is not None and existing.ordering is not None ) if not same_clock: # Ordering not observable: cannot claim monotonic supersession. return Resolution.SUPERSEDE if new.ordering <= existing.ordering: raise ConsolidationRefused( f"non-monotonic merge attempt for {new.subject_key}.{new.predicate}: " f"new ordering {new.ordering} <= existing {existing.ordering}" ) return Resolution.MERGE def consolidate(batch: list[MemoryRecord], store: dict[str, MemoryRecord], embed) -> dict[str, MemoryRecord]: for rec in batch: best, best_sim = None, -1.0 for key, cand in store.items(): sim = embed(rec, cand) if sim > best_sim: best, best_sim = cand, sim if best is None or best_sim < 0.88: store[f"{rec.subject_key}:{rec.predicate}"] = rec continue decision = resolve(rec, best, best_sim) slot = f"{best.subject_key}:{best.predicate}" if decision is Resolution.KEEP_DISTINCT: store[f"{rec.subject_key}:{rec.predicate}"] = rec elif decision is Resolution.SUPERSEDE: # Retain both; conflict edge recorded out-of-band. store[f"{rec.subject_key}:{rec.predicate}:v{rec.ordering}"] = rec else: # MERGE store[slot] = rec return store ```