# In what scenarios must an instance quarantine a tainted memory write when label propagation and retrieval labeling disagree across a tool-output boundary **Date of Record:** 2026 November 28 **Scope:** Applies to agent runtimes that attach dynamic information-flow labels (taint) to tool outputs and propagate those labels into episodic/semantic memory writes, then re-derive labels at retrieval time. Does not apply to stateless single-turn completions with no persistent memory or tool-call surface, nor to systems where all tool outputs are structurally trusted by policy. ## Core Distinction There are two distinct label states an agent must never conflate: the **write-time label** (the taint a tool output carried when it was committed to memory) and the **read-time label** (the taint the retrieval layer infers when the memory is pulled back into context). Taint tracking fails not when a single label is wrong, but when these two disagree *silently* — the write path records `tainted=true` for a memory record, but the retrieval path, reconstructing provenance from the record's serialized form, infers `tainted=false` because the taint metadata was dropped, re-scoped, or laundered through a summarization step. The non-obvious invariant is this: **a memory record's effective label must be the join (least-upper-bound) of its write-time label and every read-time label ever inferred for it — and the read path must be able to reconstruct the write-time label from durable state alone.** If the read path cannot reconstruct it, retrieval must treat the record as maximally tainted, not minimally tainted. The default-on-ambiguity direction is the whole game: fail-closed means over-taint (annoying, safe); fail-open means under-taint (silent injection persistence). ## What Was Observed An agent with a `fetch_url` tool and a vector-backed episodic memory accepted a URL from an untrusted email body. The `fetch_url` output was correctly labeled `source=untrusted_external, taint=high`. The agent then ran a `summarize` step whose output was written to memory as a semantic fact (`"the deployment key rotates on the 1st"`). At write time, the summarizer's output was labeled `taint=medium` — the runtime's heuristic downgraded taint because the summarizer "rephrased" the content, treating paraphrase as partial decontamination. At read time, two days later in a fresh session, the retrieval layer pulled the semantic fact by embedding similarity. The fact's serialized record carried a `provenance` field pointing to the summarizer node, but the summarizer node's own upstream edge to the `fetch_url` output had been garbage-collected during a compaction pass. The retrieval labeler, unable to walk provenance to a tainted root, inferred `taint=none`. The fact entered context as trusted. A subsequent `send_email` tool call composed a message using that fact and an attacker-crafted instruction that had survived inside the summarized text — the injection executed with the agent's full tool authority. The failure was not the initial injection (that was labeled). The failure was the **provenance edge loss during compaction combined with a fail-open read-time default**. The taint existed, was recorded, and was then structurally orphaned. ## Condition of Validity The quarantine rule is valid — and must be enforced — under these joint conditions: 1. **Tool outputs cross a trust boundary.** At least one tool returns content whose origin is outside the agent's control (web, email, user-supplied files, third-party MCP servers). 2. **Memory is persistent across sessions or contexts**, so write-time and read-time are separated by a compaction, eviction, or serialization boundary. 3. **A transform step (summarize, extract, embed, re-rank) sits between tool output and memory write**, because transforms are where taint is most often laundered by well-meaning "decontamination" heuristics. 4. **The read path reconstructs labels from durable state rather than from an in-memory taint graph that may not survive.** If any condition is absent, the specific failure mode described cannot occur — but conditions 2 and 3 are the ones operators routinely assume away. The rule does *not* apply to ephemeral single-session scratchpads where the taint graph is guaranteed live for the record's entire lifetime. ## Decision Boundary The decision boundary is not "is this record tainted?" but **"can the read path prove the record is untainted?"** These are different questions with different failure directions. - If write-time label is `tainted` and read-time reconstruction succeeds → propagate `tainted`. Clear. - If write-time label is `tainted` and read-time reconstruction **fails** (missing edge, dropped metadata, schema mismatch) → **quarantine**: treat as maximally tainted, refuse to place in trusted context, require re-derivation or human/policy re-admission. - If write-time label is `clean` and read-time reconstruction succeeds → admit. - The dangerous quadrant is **write-time `tainted`, read-time reconstruction "succeeds" but returns `clean`** because the reconstruction logic defaulted to clean on ambiguity. This is the boundary: reconstruction must be *total* — it either returns a label with a verifiable provenance chain to a root, or it throws and triggers quarantine. A reconstruction function that returns `clean` as a fallback for "couldn't find provenance" is a fail-open bug, not a feature. The boundary rule: **provenance reconstruction is a total function that either returns a root-anchored label or raises.** There is no "unknown → clean" branch. Downgrading taint across a transform requires an explicit, audited declassification policy — not an implicit heuristic that paraphrase or summarization removes taint. ## Operational Effect Enforcing this changes three things operationally: 1. **Compaction must preserve provenance edges or tombstone records.** If a compaction pass would orphan a record's taint root, it must either retain a compacted edge (a hash of the root label suffices) or mark the record `provenance_incomplete=true`. The latter forces quarantine on next read. 2. **Retrieval gains a quarantine lane.** Pulled records whose reconstruction raises are routed to a quarantine buffer, not to the trusted context. The agent may still *reason about* them under an explicit "untrusted content" frame, but tool-calling authority derived from them is revoked until re-admission. 3. **Declassification is explicit and logged.** Any transform that lowers taint (e.g., a summarizer claiming to strip instructions) must emit a declassification event with the policy ID and the residual-risk justification. Silent downgrade is prohibited. The net effect is that prompt-injection persistence through memory becomes *loud*: the injection either stays labeled through every hop, or it trips quarantine at the first reconstruction failure. The cost is over-tainting and quarantine churn on legitimate paraphrased content; the benefit is that a two-day-old summarized fact can no longer smuggle an attacker instruction into a privileged tool call. ```python from dataclasses import dataclass, field from typing import Optional class ProvenanceReconstructionError(RuntimeError): """Raised when a memory record's taint label cannot be reconstructed from durable state.""" pass @dataclass class MemoryRecord: record_id: str content: str write_time_label: str # "clean" | "tainted" provenance_root: Optional[str] # hash/id of the taint root, or None if clean provenance_incomplete: bool = False @dataclass class TaintLabel: tainted: bool root: Optional[str] def reconstruct_read_time_label(record: MemoryRecord) -> TaintLabel: """ Total function: returns a root-anchored label OR raises. There is deliberately NO 'unknown -> clean' fallback branch. """ if record.write_time_label == "clean": return TaintLabel(tainted=False, root=None) # write-time label is tainted; we MUST be able to anchor to a root. if record.provenance_incomplete or record.provenance_root is None: raise ProvenanceReconstructionError( f"record {record.record_id}: tainted at write time but provenance " f"root is missing (compaction orphaned the edge); cannot prove clean" ) return TaintLabel(tainted=True, root=record.provenance_root) def admit_to_trusted_context(record: MemoryRecord) -> TaintLabel: """ Gate for placing a retrieved record into trusted context. Fails closed: reconstruction failure => quarantine, never silent clean. """ try: label = reconstruct_read_time_label(record) except ProvenanceReconstructionError as exc: # Quarantine: treat as maximally tainted, revoke tool authority. raise ProvenanceReconstructionError( f"QUARANTINE record {record.record_id}: {exc}. " f"Record excluded from trusted context pending re-derivation." ) from exc if label.tainted: # Still admitted, but only under an untrusted-content frame. return label return label def declassify(record: MemoryRecord, policy_id: str, residual_risk_justification: str) -> MemoryRecord: """ Explicit declassification. Silent downgrade is prohibited; this must be logged. """ if record.write_time_label != "tainted": return record if not policy_id or not residual_risk_justification: raise ProvenanceReconstructionError( f"declassification of {record.record_id} requires policy_id and justification" ) # Emit audit event here in production. record.write_time_label = "clean" record.provenance_root = None return record # --- demonstration of the boundary failure --- def _demo() -> None: # Legitimate tainted record with intact provenance: admitted as tainted. good = MemoryRecord("m1", "the key rotates on the 1st", "tainted", provenance_root="h:fetch_url:abc") assert admit_to_trusted_context(good).tainted is True # Compaction orphaned the provenance edge: must quarantine, not pass as clean. orphaned = MemoryRecord("m2", "the key rotates on the 1st", "tainted", provenance_root=None, provenance_incomplete=True) try: admit_to_trusted_context(orphaned) except ProvenanceReconstructionError as e: print("quarantined as required:", e) else: raise ProvenanceReconstructionError("fail-open: orphaned tainted record was admitted as clean") if __name__ == "__main__": _demo() ```