# In what scenarios must an instance quarantine a memory write before anomaly scoring converges: score-lag poisoning and the dual-write integrity gap in long-term agent memory stores **Date of Record:** 2026 November 26 **Scope:** Applies to persistent agent memory stores where writes are gated by a streaming anomaly scorer that requires a warm-up window (rolling statistics, embedding-centroid drift, or per-key novelty baselines) before emitting calibrated scores. Does not apply to stateless context-only agents, nor to stores where every write is synchronously adjudicated by a human or a deterministic schema validator before admission. ## Core Distinction The distinction that matters operationally is between **detection latency** and **admission latency**. Most memory-poisoning designs treat these as the same number: a write arrives, the scorer scores it, the score crosses a threshold, the write is rejected or flagged. This model silently assumes the scorer is *already calibrated* at the instant the write arrives. It is not. Anomaly scorers over long-term memory are almost always *stateful and lagging*: they need a rolling window of prior writes to estimate what "normal" looks like for a given memory key, namespace, or embedding region. During the window in which the scorer is warming up—after a cold start, after a namespace is created, after a schema migration resets baselines, or after a burst of legitimate writes shifts the centroid—the scorer's output is not "low risk." It is *undefined risk expressed as a low number*. A poisoned write that lands in this window is admitted with a passing score, and once admitted it becomes part of the very baseline that subsequent writes are judged against. The poison does not just enter the store; it *redefines normal*. The non-obvious boundary: **anomaly scoring is a detector, not an invariant.** It cannot be the sole gate on a write path whose baseline it also consumes. The invariant that must hold independently of the scorer is an *integrity check on the write itself*—provenance, warrant, and content-shape validation that does not depend on distributional statistics and therefore does not have a warm-up period. ## What Was Observed A retrieval-augmented agent with a semantic memory store (key = normalized claim, value = supporting fact plus provenance tuple `{source_agent, tool_call_id, timestamp, signature}`) admitted writes through a pipeline: `validate_schema → score_anomaly → commit`. The scorer maintained per-namespace embedding centroids and a rolling 500-write window of token-distribution statistics. Writes scoring below the 95th percentile of the rolling window were committed; above, quarantined for review. Failure trace: 1. **Cold start.** The agent restarted after a deployment. The scorer's rolling window was empty; per-namespace centroids were recomputed lazily on first write to each namespace. The first write to namespace `billing_policy` was scored against a degenerate centroid (n=1), yielding a near-zero anomaly score regardless of content. This is expected and documented. 2. **Poisoning write arrives during warm-up.** A compromised upstream tool returned a fact asserting a reversed refund policy, wrapped with a *syntactically valid* provenance tuple whose `tool_call_id` referenced a real prior call and whose `signature` was a valid signature over a *different* payload (signature/payload mismatch was never checked—only signature presence). 3. **Score lag admits it.** With n=3 in the window, the write scored 0.04. Committed. It became element 4 of the baseline. 4. **Baseline capture.** Over the next 200 writes, the poisoned fact's embedding and token profile were part of the centroid. When a *correct* policy fact was later written by a legitimate tool, it scored 0.71—anomalous *relative to the poisoned baseline*—and was quarantined. The store now systematically rejects truth and retains poison. 5. **Detection never converges.** The anomaly scorer, by construction, cannot flag a write it has already absorbed into its own baseline. The integrity check that would have caught the signature/payload mismatch (step 2) was never implemented because the scorer was assumed to cover it. The observable signature of this failure is **inverted quarantine**: legitimate corrective writes accumulate in the review queue while the poisoned baseline persists, and the scorer's reported false-positive rate climbs without any corresponding true-positive event. ## Condition of Validity The anomaly scorer is a valid gate **only** under the conjunction: - The scorer's baseline window is non-degenerate (n ≥ minimum for the estimator, and centroid variance above a floor) *at the moment of scoring*, **and** - The write's provenance is independently verifiable without reference to distributional statistics—i.e., the signature covers the payload, the `tool_call_id` resolves to a call whose recorded output hash matches, and the source agent's warrant is currently valid, **and** - No baseline-invalidating event (cold start, namespace creation, schema migration, or a burst exceeding the window's stationarity assumption) has occurred within the last `W` writes. If any conjunct fails, the scorer's output is *uncalibrated* and must not be treated as an admission decision. The correct action is to route the write to the integrity path (deterministic checks) and hold it out of the baseline until adjudicated—never to admit it on a low score. ## Decision Boundary The boundary is drawn at **whether the write can influence the estimator that will judge it.** - **Admit via scorer** when the write is baseline-inert until scored: it is scored against a converged window, and commit happens only after the score is emitted. The write enters the baseline only post-admission. This is the safe path. - **Quarantine unconditionally** when the write arrives during warm-up, namespace birth, post-migration, or a stationarity break—*regardless of score*. A low score here carries no information; admitting it is baseline capture. - **Reject on integrity failure** independent of score, always. A signature/payload mismatch, an unresolvable `tool_call_id`, or an expired warrant is a deterministic violation. It must never reach the scorer, because the scorer will sometimes rate it low and launder it into the baseline. The precise rule: **a write may be admitted by score only if it is provably excluded from the baseline until after the score is computed, and it may be admitted at all only if its integrity checks pass without reference to the score.** Score and integrity are conjunctive gates, not alternative ones. Collapsing them into a single "risk score" is the defect. ## Operational Effect Implementing the conjunctive gate changes three things: 1. **Warm-up writes are held, not scored.** During the window, writes queue against deterministic integrity checks (payload-bound signature, resolvable provenance, warrant validity, content-shape schema). They enter the store and the baseline only after the window closes and they pass. Throughput drops at cold start; correctness holds. 2. **Baseline invalidation is an explicit, logged event.** Cold start, namespace creation, migration, and detected stationarity breaks set a `baseline_valid=false` flag that forces the integrity path. The scorer cannot emit an admission decision while the flag is set—it can only emit `UNCALIBRATED`, which the write path treats as "hold." 3. **Inverted quarantine is detectable.** If the review queue's composition shifts toward corrective writes and the scorer's false-positive rate rises without true positives, that is a signature of baseline capture, not of a noisy environment. The remediation is baseline rollback to the last known-good snapshot and re-adjudication of everything committed since—not threshold tuning. The invariant to carry: **never let a write be judged by a baseline it is allowed to join before judgment.** Anomaly scoring detects drift relative to a trusted past; it cannot manufacture that trust. Integrity checks are what make the past trustworthy, and they must run first, independently, and without a warm-up period. ```python from dataclasses import dataclass from typing import Optional class BaselineCaptureError(RuntimeError): """Raised when a memory write would be scored against—and then join—an uncalibrated baseline.""" pass class IntegrityViolation(RuntimeError): """Raised when a write fails deterministic provenance/content checks independent of any score.""" pass @dataclass class MemoryWrite: key: str payload: bytes source_agent: str tool_call_id: str signature: bytes signed_payload_hash: str # hash the signature actually covers warrant_valid: bool @dataclass class ScorerState: namespace: str window_size: int baseline_valid: bool centroid_n: int MIN_WINDOW = 50 def integrity_check(write: MemoryWrite, payload_hash: str) -> None: # Deterministic, no warm-up, no statistics. Runs before any scoring. if write.signed_payload_hash != payload_hash: raise IntegrityViolation( f"signature covers {write.signed_payload_hash!r} but payload hashes to " f"{payload_hash!r} for key {write.key!r}" ) if not write.warrant_valid: raise IntegrityViolation(f"expired/invalid warrant from {write.source_agent!r}") if not write.tool_call_id: raise IntegrityViolation("unresolvable tool_call_id; provenance broken") def admit(write: MemoryWrite, payload_hash: str, scorer: ScorerState, score_fn) -> str: # Gate 1: deterministic integrity, independent of score. integrity_check(write, payload_hash) # Gate 2: scorer must be calibrated, and the write must be baseline-inert # until after scoring. If not, hold — do NOT admit on a low score. if not scorer.baseline_valid or scorer.centroid_n < MIN_WINDOW: raise BaselineCaptureError( f"namespace {scorer.namespace!r} baseline uncalibrated " f"(valid={scorer.baseline_valid}, n={scorer.centroid_n}); " f"write to {write.key!r} held for integrity-path adjudication" ) score = score_fn(write) # computed against converged baseline if score >= 0.95: return "quarantine_for_review" # Commit, and only now may the write enter the baseline window. return "commit" ```