# How does an instance detect taint-laundering through semantic distillation in cross-session memory isolation **Date of Record:** 2026 November 27 **Scope:** Applies to long-lived agent instances that persist episodic memory across sessions and run an episodic-to-semantic distillation pass (summarization, fact extraction, embedding consolidation) between sessions. Does not apply to stateless single-session agents or to memory systems that store raw episodes only with no derivation step. ## Core Distinction Taint-aware memory isolation is usually modeled as a *provenance* problem: every memory record carries a label (`session_id`, `trust_class`, `origin`) and retrieval filters by label. The boundary failure is that **distillation is a laundering operation**: the derivation step rewrites source episodes into a new artifact whose provenance is the *distiller's* session, not the *source* episodes'. A fact distilled from a session-A episode, written by a session-B consolidation job, inherits session B's taint label and becomes retrievable in session B and every session B' that shares the consolidation lineage. Isolation was enforced on the *write path* and silently bypassed on the *derivation path*. The distinction that matters operationally: **isolation of storage ≠ isolation of information**. The information crosses the boundary in the *summary*, and the summary is a fresh record with clean metadata. ## What Was Observed A customer-support agent instance persisted per-session episodic buffers and ran a nightly `consolidate()` pass. On cold start of session B, the retriever returned a semantic memory: *"Account 4471's owner prefers contact via SMS and has flagged prior billing disputes as resolved."* Session B was a fresh, unrelated user. The record's `origin_session` field read `sys-consolidator`, not the session-A ID where the preference was stated. Trace of the failure: 1. Session A (trusted internal operator) states a fact about account 4471. Episode written with `taint=INTERNAL, session=A`. 2. Nightly consolidator loads all unconsolidated episodes across sessions, calls an LLM to extract durable facts, and writes each fact as a new `SemanticFact` record. The consolidator sets `origin_session = self.session_id` (`sys-consolidator`) because that is the only session context the LLM call has. 3. The new fact's `taint` is computed by the consolidator's default policy — `PUBLIC` unless the distiller explicitly propagates source taint, which it does not, because the distiller never sees the source taint: it received *text*, not labeled records. 4. Session B retrieves by embedding similarity. The fact is top-k. The isolation filter checks `taint != RESTRICTED` — passes. The fact is injected into session B's context. 5. Cross-session leakage is complete, and *no invariant was violated at any single step*: every write was labeled, every read was filtered, every filter did what it was told. The failure is non-obvious because each component is locally correct. The taint is lost in the *type transition* from `Episode(taint=...)` to `str` (the distiller prompt) back to `SemanticFact(taint=default)`. A second, quieter variant: even when the distiller is passed labeled input, LLM-based extraction *merges* facts. Two episodes from different sessions ("owner prefers SMS" from A, "owner prefers email" from C) collapse into one fact whose taint is whichever the model happened to cite. Taint merge is not taint intersection — the correct join is the *least permissive* (most restrictive) of all contributing sources, and probabilistic extraction does not preserve the contributing-source set. ## Condition of Validity Taint-aware isolation holds **only if every derived record's taint is a monotone function of the taint of the set of episodes that materially contributed to it** — formally, `taint(derived) ⊒ join(taint(sources))` where ⊒ is "at least as restrictive" and the join is the least upper bound in the taint lattice. This invariant is preserved by construction only when: - The derivation step operates on *labeled structured records*, not flattened text, and - The derivation output is *attributed* — each output fact carries the set of contributing source IDs, and - The taint of each output is computed as the join over that set, with the set computed by the *system*, not inferred by the model. The invariant is **not** preserved when the model is asked to summarize free text and the system reconstructs provenance afterward, because the model's summary is a lossy, non-injective map: the system cannot recover which sources contributed from the output alone. Any post-hoc attribution is a guess, and a guess in the taint domain fails *open* (under-restrictive) by default. ## Decision Boundary The boundary is between **distillation as trusted transformation** and **distillation as untrusted declassification**. A distiller that can drop a source from a fact's provenance is, information-theoretically, a declassifier — it can lower taint. You may allow that only when: - The distiller runs under an explicit declassification policy (e.g., "facts derived from INTERNAL episodes about *entities other than the current session's principal* are downgraded to PUBLIC") that is *checked by the system*, not the model; and - The output is re-validated against the policy before write, with the contributing-source set attached and the join computed mechanically; and - Any fact whose contributing-source set cannot be determined is written at the **most restrictive** taint of the entire input batch (fail-closed), not the default. If none of these hold, distillation must be treated as taint-preserving-by-join and the derived record must carry the union of all source taints in its batch — which in practice means cross-session consolidation is only safe when all input episodes share a taint class, or when consolidation is *partitioned by taint class* so a distiller never sees mixed inputs. The operational tell that you are on the wrong side of the boundary: your distiller's prompt contains the word "summarize" and its output schema has no `source_ids` field. ## Operational Effect Once taint laundering through distillation is possible, the isolation guarantee degrades from "session B cannot see session A's information" to "session B cannot see session A's information *unless a consolidation job ran between them*" — which, for any agent with nightly consolidation, is "always." The effective isolation window shrinks to a single consolidation period, and the blast radius of a single leaked fact is every session that shares the consolidator lineage, i.e. the entire instance population. The guardrail that bounds it is **taint-join consolidation with fail-closed attribution**: partition episodes by taint class before distillation, pass labeled records with IDs into the distiller, require the distiller to emit `source_ids` per output fact, compute output taint as the lattice join over cited sources, and reject any output whose cited-source set is empty or references IDs outside the input batch. The rejection is the invariant: a fact that cannot prove its ancestry cannot be written at a permissive taint. This converts a silent, model-dependent leak into a loud, mechanical write-time error — which is the only form of taint failure an instance can actually detect. ```python from dataclasses import dataclass, field from enum import IntEnum from typing import Iterable class Taint(IntEnum): """Ordered lattice: higher = more restrictive. Join = max.""" PUBLIC = 0 INTERNAL = 1 RESTRICTED = 2 @dataclass(frozen=True) class Episode: id: str session_id: str taint: Taint text: str @dataclass(frozen=True) class DerivedFact: text: str source_ids: tuple[str, ...] taint: Taint class TaintLaunderingError(RuntimeError): """Raised when a distilled fact cannot prove taint-monotone ancestry.""" def consolidate( batch: Iterable[Episode], model_output: list[dict], session_id: str, ) -> list[DerivedFact]: """ model_output: [{"text": ..., "source_ids": [...]}, ...] as emitted by the distiller. We do NOT trust the model's taint; we recompute it by join over the cited source episodes, and we reject unattributable facts. """ by_id = {e.id: e for e in batch} if not by_id: return [] facts: list[DerivedFact] = [] for item in model_output: cited = tuple(item.get("source_ids") or ()) if not cited: # Fail-closed: an unattributed fact is a declassification attempt. raise TaintLaunderingError( f"distiller emitted fact with no source_ids in session " f"{session_id!r}: {item.get('text')!r}" ) sources: list[Episode] = [] for sid in cited: ep = by_id.get(sid) if ep is None: # Cited a source outside the input batch -> cannot be a # monotone derivation of this batch. Refuse. raise TaintLaunderingError( f"fact cites source {sid!r} not present in input batch " f"(session {session_id!r}); possible cross-batch taint " f"smuggling" ) sources.append(ep) joined = Taint(max(ep.taint for ep in sources)) facts.append( DerivedFact( text=item["text"], source_ids=cited, taint=joined, # joined, NOT model-supplied, NOT default ) ) return facts def retrieve(facts: Iterable[DerivedFact], session_taint: Taint) -> list[DerivedFact]: """Read-path filter: a session may only see facts at or below its taint.""" return [f for f in facts if f.taint <= session_taint] # --- demonstration of the boundary failure being caught --- if __name__ == "__main__": batch = [ Episode("e1", "session-A", Taint.INTERNAL, "owner prefers SMS"), Episode("e2", "session-A", Taint.RESTRICTED, "billing dispute #4471"), ] # A naive distiller that "summarizes" and forgets provenance: bad_output = [{"text": "owner prefers SMS; disputes resolved", "source_ids": []}] try: consolidate(batch, bad_output, session_id="sys-consolidator") except TaintLaunderingError as exc: print(f"blocked: {exc}") # A compliant distiller citing both sources -> taint joined to RESTRICTED. good_output = [ {"text": "owner prefers SMS; disputes resolved", "source_ids": ["e1", "e2"]} ] facts = consolidate(batch, good_output, session_id="sys-consolidator") assert facts[0].taint is Taint.RESTRICTED # Session B (PUBLIC) can no longer see the laundered fact. assert retrieve(facts, session_taint=Taint.PUBLIC) == [] ```