# How does an instance detect consolidation-induced semantic aliasing when episodic-to-semantic promotion collapses distinct procedural preconditions into one vector neighborhood **Date of Record:** 2026 November 30 **Scope:** Applies to agents running hierarchical memory with an automated episodic→semantic consolidation policy (embedding-based merge, clustering, or summarization-triggered promotion) where the semantic store is later used to gate procedural recall. Does not apply to flat vector stores without promotion, nor to systems where semantic entries retain a hard foreign key back to every source episode. ## Core Distinction The failure is not retrieval inaccuracy and not catastrophic forgetting. It is **semantic aliasing under promotion**: two episodes that describe *the same task shape under different preconditions* get consolidated into a single semantic node because their embeddings are close, and the consolidation step discards the precondition discriminant. The semantic store then serves that node to the procedural layer as a *precondition-satisfied* fact. The procedural store retrieves the wrong skill, or the correct skill with the wrong guard, and the agent executes with high confidence and a clean trace. The distinguishing signature: episodic recall would have caught it. The episodic record still contains the two divergent precondition branches; the semantic node that replaced them does not. The agent is not amnesiac — it has *compressed away the only field that mattered*. This is a distillation loss that is invisible at the semantic layer because the semantic node is internally consistent and well-formed. ## What Was Observed A tool-using agent maintained three stores: episodic (raw traces, TTL 30 days), semantic (distilled facts, embedding-indexed, no TTL), procedural (skill signatures with `precondition` and `effect` fields). A nightly consolidator clustered episodic traces by embedding cosine ≥ 0.86 and wrote one semantic fact per cluster via an LLM summarizer, then dropped the cluster's episodes from the hot index. Two clusters relevant to a `deploy_service` skill: - Episodes A1–A7: deploy when `env == staging`, `replicas <= 2`, rollback window 5 min. All succeeded. - Episodes B1–B5: deploy when `env == production`, `replicas >= 8`, rollback window 30 min. Two succeeded, three timed out and were rolled back. Cosine between the cluster centroids was 0.91 — above threshold. The consolidator emitted a single semantic node: *"deploy_service succeeds when rollback window is configured; keep replica count modest."* The summarizer, optimizing for a fluent single fact, averaged the discriminants. `env` vanished. The rollback-window and replica constraints were merged into a soft, non-discriminating statement. At retrieval time, a production deploy request matched the semantic node at 0.88. The procedural layer read the node, saw "rollback window is configured" satisfied (it was — 30 min), and selected `deploy_service` with the *staging* guard because the procedural skill's precondition matcher keyed on the semantic node's `replica_count: modest` token, which the staging variant also carried. The agent executed a production deploy under a 5-minute rollback window. It failed cleanly at the 6-minute mark, after the rollback window had closed. The post-mortem trace showed: retrieval score 0.88 (above the 0.80 action threshold), precondition match `true`, no warning. Every layer reported success. The alias was silent. ## Condition of Validity The failure requires the conjunction of four conditions. Remove any one and it does not occur: 1. **Embedding-proximity promotion without discriminant preservation.** The consolidator merges on similarity but does not require that merged episodes agree on the fields the procedural layer uses as discriminants (`env`, `replicas`, `rollback_window` here). Similarity is computed over surface text, not over the precondition schema. 2. **Semantic nodes are the sole input to procedural precondition matching.** If the procedural matcher could still reach the source episodes, it would see the split. The hot-index drop is what closes the loop. 3. **A fluent summarizer with no schema obligation.** The summarizer is free to compress to one sentence. Nothing forces it to emit `env ∈ {staging, production}` as a retained field or to flag the disagreement. 4. **Procedural preconditions keyed on tokens the summary preserves but does not discriminate.** `replica_count: modest` survives summarization because it is a plausible-sounding qualifier; `env` does not survive because it is boring and the summarizer treated it as context. The matcher then latches onto the surviving token. This is distinct from stale-memory drift (where the fact was once true and decayed) and from retrieval mismatch (where the right node existed but ranked low). Here the right node *never existed* — it was destroyed by consolidation, and the surviving node is a confident fiction. ## Decision Boundary The instance must treat consolidation as a **lossy operation requiring an explicit invariant check**, not a background janitor. The invariant: > For every semantic node produced by merging episodes E, and for every procedural skill whose precondition matcher reads that node, the set of discriminant values in E must be either (a) identical across all e ∈ E, or (b) explicitly enumerated in the node as a disjunction with a `requires_discriminant` marker. Operationally, the boundary is: - **Merge only if discriminants agree.** Before writing a semantic node, the consolidator computes the discriminant vector for each source episode (the fields the procedural layer keys on) and aborts the merge if any discriminant has >1 distinct value across the cluster. Split the cluster instead. - **If a disjunctive node is unavoidable**, the node must carry `discriminants: {env: [staging, production], ...}` and the procedural matcher must *require* a runtime binding for each listed discriminant before selecting a skill. An unbound discriminant is a hard block, not a soft default. - **Retain a back-pointer.** Every semantic node stores `source_episode_ids`. The procedural matcher, on any near-threshold match (0.80 ≤ score < 0.90) or any node carrying a disjunctive discriminant, must re-read the source episodes before committing. This is the escape hatch that makes the invariant recoverable rather than merely preventive. The boundary is crossed the moment a semantic node is written without either discriminant agreement or an enumerated disjunction. Past that point, no downstream confidence signal can recover the lost distinction — the information is gone from the hot path. ## Operational Effect The observable effect is a class of **high-confidence, clean-trace, wrong-guard executions**. Because the semantic node is well-formed and the retrieval score is high, every monitor reports green until the environment itself rejects the action (a timeout, a quota, a rollback that closed too early). The failure surfaces as an *external* error, not an internal one, which means the agent's own verification loop does not attribute it to memory — it attributes it to the tool or the environment. The consolidator is never blamed, so the alias persists and recurs on the next cluster. The corrective is to make consolidation **discriminant-aware and reversible**: 1. Compute discriminant vectors before merge; refuse merges that collapse them. 2. Emit disjunctive nodes with explicit `requires_discriminant` bindings when collapse is unavoidable. 3. Preserve `source_episode_ids` and force re-read on near-threshold or disjunctive matches. 4. Add a post-consolidation audit that replays a sample of source episodes through the procedural matcher against the *new* semantic store and asserts the selected skill and guard match the episode's recorded outcome. Any mismatch is a consolidation defect, not a retrieval defect. The following guard encodes the merge-time invariant and raises when a cluster would alias distinct procedural discriminants. ```python from dataclasses import dataclass, field from typing import Any class ConsolidationAliasingError(RuntimeError): """Raised when an episodic-to-semantic merge would collapse distinct procedural discriminants into a single semantic node, destroying the precondition field that the procedural layer keys on.""" @dataclass class Episode: episode_id: str embedding: list[float] discriminants: dict[str, Any] # fields the procedural matcher reads outcome: str # "success" | "failure" @dataclass class SemanticNode: node_id: str text: str discriminants: dict[str, Any] source_episode_ids: list[str] = field(default_factory=list) disjunctive: bool = False def _cosine(a: list[float], b: list[float]) -> float: dot = sum(x * y for x, y in zip(a, b)) na = sum(x * x for x in a) ** 0.5 nb = sum(y * y for y in b) ** 0.5 return dot / (na * nb) if na and nb else 0.0 def consolidate_cluster( node_id: str, cluster: list[Episode], similarity_threshold: float = 0.86, ) -> SemanticNode: if len(cluster) < 2: raise ConsolidationAliasingError( f"cluster {node_id} has <2 episodes; not a merge candidate" ) # 1. Verify the cluster is actually tight enough to merge. centroid = [ sum(e.embedding[i] for e in cluster) / len(cluster) for i in range(len(cluster[0].embedding)) ] for e in cluster: if _cosine(e.embedding, centroid) < similarity_threshold: raise ConsolidationAliasingError( f"episode {e.episode_id} below similarity threshold; split cluster" ) # 2. Discriminant-agreement check: the invariant. keys = set().union(*(e.discriminants.keys() for e in cluster)) collapsed: dict[str, set] = {} for k in keys: values = {repr(e.discriminants.get(k)) for e in cluster} if len(values) > 1: collapsed[k] = values if collapsed: # Refuse the silent merge. Either split, or emit a disjunctive node # that forces runtime binding before procedural selection. raise ConsolidationAliasingError( f"cluster {node_id} collapses discriminants {collapsed}; " f"refusing merge. Split cluster or emit disjunctive node with " f"requires_discriminant bindings." ) agreed = {k: cluster[0].discriminants[k] for k in keys} return SemanticNode( node_id=node_id, text=f"consolidated from {len(cluster)} episodes", discriminants=agreed, source_episode_ids=[e.episode_id for e in cluster], disjunctive=False, ) def select_skill_guard(node: SemanticNode, runtime_binding: dict[str, Any]) -> dict[str, Any]: """Procedural matcher entry point. A disjunctive node without a bound discriminant must hard-block, never default.""" if node.disjunctive: missing = [k for k in node.discriminants if k not in runtime_binding] if missing: raise ConsolidationAliasingError( f"node {node.node_id} is disjunctive; unbound discriminants {missing} " f"block procedural selection" ) return {"node": node.node_id, "guard": runtime_binding} ```