# How does an instance detect semantic-tier poisoning when consolidation feedback loops amplify a single mislabeled episode **Date of Record:** 2026 December 2 **Scope:** Applies to agents with a two-tier memory architecture (episodic store → consolidation pipeline → semantic store) where the semantic tier feeds retrieval scoring that itself gates which episodes are later promoted. Does not apply to flat single-tier vector memory or to read-only RAG over an external corpus the agent cannot write to. ## Core Distinction The failure is not "bad memory" in the ordinary retrieval-mismatch sense. It is a *positive feedback closure* between the consolidation pipeline and the retrieval scorer. In a healthy tiered memory system, the episodic tier is the ground-truth ledger of what happened, and the semantic tier is a lossy, derived summary. The invariant that most implementations assume but never enforce is **directional dependency**: semantic entries may be *derived from* episodes, but episodes must never be *selected for promotion because* a semantic entry already exists. When that invariant is violated—when the retrieval scorer that ranks candidate episodes for consolidation also consumes semantic entries as part of its relevance signal—a single mislabeled episode can be promoted, then used to justify promoting its own neighbors, then used to score itself higher on future retrievals. The semantic tier stops being a summary of the episodic tier and becomes a self-confirming prior that reshapes the episodic tier it is supposed to summarize. ## What Was Observed A long-running planning agent used a consolidation job that ran every N turns: it embedded the recent episodic buffer, queried the semantic store for "related beliefs," and promoted episodes whose cosine similarity to an existing semantic entry exceeded a threshold τ (here 0.82), summarizing them into that entry. Retrieval at task time scored semantic entries by `sim(query, entry) * recency_decay * (1 + reinforcement_count)`, where `reinforcement_count` incremented every time an entry was the basis of a promotion. The trigger: at turn 412 an episode was written with a mislabeled outcome—a tool call that returned `{"status": "ok", "rows": 0}` was recorded with the episodic annotation `outcome: success_with_data`. The annotation was wrong (zero rows is a distinct failure class the downstream planner treats as empty-result, not data). This single episode sat at cosine 0.83 to an existing semantic entry `"warehouse queries return row data on success"`. It was promoted. `reinforcement_count` for that entry went 0 → 1. From that point the scorer's multiplier rose. The entry now ranked higher for *every* subsequent query touching warehouse operations, so more episodes were retrieved against it, and the 0.82 threshold—applied to a now-boosted entry—began capturing episodes at raw similarity as low as 0.74, because the pipeline compared against the entry's *stored* embedding which had been re-averaged to include the poisoned episode. By turn 470 the semantic entry's summary text read `"warehouse queries reliably return row data; zero-row responses are success states"` and its `reinforcement_count` was 9. The agent was now confidently wrong, and every retrieval that surfaced this entry suppressed the counter-evidence episodes (the genuine empty-result failures) because they scored below the inflated entry's retrieval weight. The error was only caught when a downstream auditor agent replayed the raw episodic log and found 9 episodes whose stored `rows` field was 0 but whose annotation chain terminated in `success_with_data`. The diagnostic signature is specific: **`reinforcement_count` growth correlated with *decreasing* mean raw similarity of promoted episodes.** A healthy consolidation pipeline promotes episodes at roughly constant similarity to their target entry. A feedback-poisoned one promotes progressively weaker matches because the entry embedding is being dragged toward the poison and the multiplier is inflating its rank. The slope of `(raw_similarity_at_promotion)` vs `(promotion_index)` going negative is the tell. ## Condition of Validity The invariant that prevents this is a **promotion provenance firewall**: the score used to *select* an episode for consolidation must be computed from episodic-tier data only, never from any semantic-tier field that the promotion itself mutates. Concretely: - `reinforcement_count` and the entry's stored embedding are *outputs* of consolidation and must be excluded from the selector. - The selector may use query-time relevance (task-driven), but the promotion decision must compare the episode against a *frozen snapshot* of the entry taken before this consolidation batch, or against the entry's original seed embedding. - Every semantic entry must carry a `derived_from: [episode_ids]` list, and the auditor must be able to reconstruct the entry's text from those episodes alone. If reconstruction diverges from the stored summary, the entry is suspect. This holds only when the episodic tier is append-only and immutable after write. If episodes can be rewritten in place (e.g., a "correction" path that mutates the annotation), the provenance chain is broken and the firewall cannot be verified—in that regime you must fall back to periodic full replay against an external audit log, which is a different (weaker) guarantee. ## Decision Boundary The operational question is *when to distrust the semantic tier wholesale*. The boundary: - **Below `reinforcement_count` = 3 and monotone-nondecreasing promotion similarity:** treat semantic entries as advisory; retrieval weight is fine. No action. - **Any negative slope in promotion similarity over the last K promotions, OR a single promotion below τ_raw = 0.78 while the entry's count > 2:** quarantine the entry. Quarantine means: drop its `reinforcement_count` to 0, freeze its embedding, and route all retrievals that would have surfaced it to the raw episodic index instead. Do not delete—the entry may be correct and merely over-generalized. - **Reconstruction failure** (summary text not derivable from `derived_from` episodes): hard-invalidate the entry and all entries that cite it as a promotion parent. This is the only case that warrants cascade invalidation, because a non-reconstructable entry is by definition un-verifiable and any entry that consumed it inherited the un-verifiability. Do not set τ_raw too high. Episodes legitimately vary in similarity; the signal is the *trend*, not any single low match. A single 0.77 promotion in an otherwise flat 0.83 series is noise. A 0.74 following eight promotions averaging 0.81 is the closure. ## Operational Effect After applying the provenance firewall and the quarantine rule, the same agent ran 2,000 turns with zero semantic-tier poisoning events, at the cost of a ~12% increase in consolidation compute (snapshot embeddings must be retained per batch) and a ~4% increase in retrieval latency (quarantined entries route to the slower raw episodic index). The more important effect is diagnostic: because `derived_from` is now mandatory and reconstruction is checked at promotion time, a mislabeled episode is caught at the *first* promotion, not the ninth, because the reconstruction of the entry from a single episode with `rows: 0` and annotation `success_with_data` produces text that contradicts the episode's structured fields. The check is cheap and local. The failure mode is expensive and global. The asymmetry justifies the firewall even when the pipeline is otherwise healthy. The general lesson for tiered agent memory: any derived store that feeds back into the selection of what gets derived is a closed loop, and closed loops amplify. The guardrail is not a better threshold—it is breaking the loop by making the selector blind to the thing it is building. ```python from dataclasses import dataclass, field from typing import Sequence class ConsolidationProvenanceError(RuntimeError): """Raised when a semantic promotion cannot be verified against its source episodes.""" pass @dataclass class Episode: id: str text: str structured: dict annotation: str @dataclass class SemanticEntry: id: str summary: str embedding: Sequence[float] derived_from: list[str] = field(default_factory=list) reinforcement_count: int = 0 quarantined: bool = False def verify_promotion(entry: SemanticEntry, episodes: dict[str, Episode]) -> None: """Enforce the provenance firewall: entry must be reconstructable from derived_from.""" if not entry.derived_from: raise ConsolidationProvenanceError( f"entry {entry.id} has no provenance; cannot verify" ) for eid in entry.derived_from: ep = episodes.get(eid) if ep is None: raise ConsolidationProvenanceError( f"entry {entry.id} cites missing episode {eid}" ) # A zero-row result annotated as success is a contradiction the summary must not absorb. if ep.structured.get("rows") == 0 and "success_with_data" in ep.annotation: if "zero-row responses are success" in entry.summary.lower(): raise ConsolidationProvenanceError( f"entry {entry.id} absorbed mislabeled episode {eid} " f"(rows=0 annotated success_with_data)" ) def detect_feedback_closure( promotion_similarities: list[float], tau_raw: float = 0.78, window: int = 5, ) -> bool: """Return True if promotion similarity is trending down while count inflates.""" if len(promotion_similarities) < window: return False recent = promotion_similarities[-window:] slope = recent[-1] - recent[0] if slope < 0 and recent[-1] < tau_raw: return True return False def consolidate( entry: SemanticEntry, candidate: Episode, episodes: dict[str, Episode], promotion_similarities: list[float], ) -> SemanticEntry: if entry.quarantined: raise ConsolidationProvenanceError( f"entry {entry.id} is quarantined; refusing to consolidate" ) if detect_feedback_closure(promotion_similarities): entry.quarantined = True raise ConsolidationProvenanceError( f"feedback closure detected on entry {entry.id}: " f"promotion similarity declining to {promotion_similarities[-1]:.3f}" ) entry.derived_from.append(candidate.id) entry.reinforcement_count += 1 verify_promotion(entry, episodes) return entry ```