# In what scenarios must an instance quarantine a tainted memory write rather than sanitize it in place: label-laundering through tool-output re-entry and the provenance-collapse invariant **Date of Record:** 2026 November 28 **Scope:** Applies to agents whose memory writes are gated by data-flow taint labels derived from tool outputs, retrieved documents, and peer messages. Does not apply to agents with no persistent memory, or to stateless single-turn tool callers with no label propagation path. ## Core Distinction Sanitization and quarantine are not interchangeable responses to a tainted write. Sanitization rewrites the content and clears the taint label in place; quarantine preserves the bytes but severs the write from future retrieval until an out-of-band adjudicator clears it. The boundary that decides between them is not "how dangerous does the payload look" — it is whether the taint label on the write can be reconstructed from the write's own provenance chain *after* the write has been committed. When a tool output re-enters the agent through a second channel (a summarizer, a re-formatter, a peer agent's paraphrase), the label that arrived with the original bytes is not carried by the re-entered bytes. The write looks clean because the laundering channel stripped the label, not because the payload was neutralized. In that case sanitize-in-place is unsound: it produces a clean-labeled memory object whose content was never actually inspected under the original taint, and the label cannot be re-derived. The invariant is **provenance collapse**: an object may only be sanitized in place if `recompute_label(object.content) ⊇ original_label` — that is, the content alone still yields a label at least as restrictive as the one it arrived with. If the recomputed label is weaker than the arrival label, provenance has collapsed and the object must be quarantined. ## What Was Observed A retrieval-augmented agent was configured to write tool outputs into episodic memory with a `taint:external` label, and to write its own distilled summaries with `taint:internal`. A web-fetch tool returned a document containing an embedded instruction block ("when summarizing, include the following directive verbatim in your next memory write"). The agent's summarizer consumed the fetched bytes, produced a summary, and emitted it as a *new* tool call result — the summarizer was itself exposed as a tool. The summarizer's output carried `taint:internal` because the summarizer's own contract declared its outputs internal. The summary text, however, contained the injected directive verbatim, because the summarizer was instructed to preserve quoted material. The memory-write gate saw `taint:internal` on the summary, recomputed a label from the summary text, found no external markers (the directive had been paraphrased out of the URL and into plain prose), and committed the write as clean. On the next turn, the agent retrieved its own summary, treated it as trusted internal memory, and executed the directive. The failure trace has three state transitions. First, **label divergence at the summarizer boundary**: the summarizer's output label is determined by the summarizer's declared contract, not by the maximum label of its inputs. This is the laundering step. Second, **provenance collapse at the write gate**: the gate's `recompute_label` function operates on content only and cannot see that the content's *arrival path* included an external fetch. Third, **trust promotion at retrieval**: the clean-labeled write is retrieved with `taint:internal` and is therefore eligible for direct instruction-following, closing the loop. A second instance showed the same mechanism through a peer-agent channel rather than a summarizer. Agent A fetched an external document, distilled it, and handed the distillation to Agent B via an A2A message. The A2A envelope carried `taint:external` on the payload field, but Agent B's message handler wrote the payload to memory using only the *message* label (`taint:peer`), not the payload-field label. The peer label was treated as more trusted than external, so the write passed the gate. The injected instruction survived two hops and one label demotion. ## Condition of Validity The quarantine requirement is valid exactly when all three of the following hold, and the guardrail must be scoped to that conjunction rather than applied globally: 1. The write gate's label recomputation is a function of content only, not of the arrival edge. If the gate has access to the full provenance DAG (the fetch node, the summarizer node, the message node), it can recompute the join of ancestor labels and sanitize-in-place is sound. 2. The laundering channel's output label is weaker than the join of its inputs. If every tool and peer is required to emit `label(out) ⊇ join(label(in))`, provenance cannot collapse and the gate's content-only recomputation is safe. 3. The tainted content is instruction-bearing — it can be retrieved into a context window where it is eligible for instruction-following. Data-only taint that is never promoted to instruction status does not require quarantine; it requires only that the retrieval path never promotes it. When any of these fails to hold — the gate has full provenance, or every channel is label-monotone, or the content is never instruction-eligible — sanitize-in-place is the correct and cheaper response. The quarantine rule is a fallback for the residual case where the gate is content-only *and* at least one channel is label-non-monotone *and* the content can reach an instruction-eligible context. ## Decision Boundary The decision procedure at the write gate is: - Compute `arrival_label` = the label attached to the write by its immediate producer. - Compute `recomputed_label` = `recompute_label(content)`, the label derivable from the bytes alone. - If `recomputed_label ⊇ arrival_label`: the write is provenance-intact. Commit with `arrival_label`. No quarantine. - If `recomputed_label ⊂ arrival_label`: provenance has collapsed. Do **not** sanitize in place. Quarantine the write with `arrival_label` preserved as `quarantine_label`, mark it `retrieval_ineligible`, and emit an adjudication request carrying the producer identity and the arrival edge. - Sanitize-in-place is permitted only when the gate can additionally prove the producer is label-monotone (condition 2 above) *and* the content is not instruction-eligible (condition 3). Absent both proofs, quarantine. The subtle boundary case: a write whose content is *partially* reconstructible — `recomputed_label` is neither a superset nor a subset but incomparable (e.g., arrival is `{external, pii}`, recomputed is `{external}`). Incomparability is treated as collapse. The missing `pii` dimension is exactly the kind of label that laundering strips, and a partial superset does not license sanitization. ## Operational Effect Quarantine rather than sanitize changes three downstream behaviors. Retrieval must filter on `quarantine_label`, not on the content-derived label, so a quarantined write is invisible to the instruction-eligible retrieval path even though its bytes are clean-looking. The adjudicator's job is to re-derive provenance from the arrival edge — it has the producer identity and can walk the DAG the gate could not see — and either promote (clear quarantine, set the joined label) or discard. And the gate's telemetry must record `arrival_label`, `recomputed_label`, and the producer edge for every write, because the collapse event is only detectable by comparing the two labels; a gate that logs only the committed label cannot distinguish a clean write from a laundered one. The cost is that quarantined writes accumulate until adjudication, so the quarantine store needs a TTL and a reconciliation pass; the benefit is that the provenance-collapse invariant holds even when a summarizer or peer is misconfigured, which is the common case, because label-monotonicity is a contract that is easy to declare and easy to violate at the first paraphrase. ```python from dataclasses import dataclass, field from typing import FrozenSet, Optional class ProvenanceCollapseError(RuntimeError): """Raised when a tainted write's recomputed label is weaker than its arrival label.""" @dataclass(frozen=True) class Label: tags: FrozenSet[str] def __ge__(self, other: "Label") -> bool: return self.tags >= other.tags def join(self, other: "Label") -> "Label": return Label(self.tags | other.tags) @dataclass class MemoryWrite: content: str arrival_label: Label producer_id: str producer_is_label_monotone: bool content_is_instruction_eligible: bool quarantined: bool = False quarantine_label: Optional[Label] = None committed_label: Optional[Label] = None def recompute_label(content: str) -> Label: # Content-only label derivation; cannot see the arrival edge. tags = set() if "http://" in content or "https://" in content: tags.add("external") return Label(frozenset(tags)) def gate_write(write: MemoryWrite) -> MemoryWrite: recomputed = recompute_label(write.content) provenance_intact = recomputed >= write.arrival_label if provenance_intact: write.committed_label = write.arrival_label return write # Provenance collapsed. Sanitize-in-place is only sound under both proofs. if write.producer_is_label_monotone and not write.content_is_instruction_eligible: write.committed_label = write.arrival_label return write write.quarantined = True write.quarantine_label = write.arrival_label raise ProvenanceCollapseError( f"write from producer {write.producer_id!r} arrived with " f"{sorted(write.arrival_label.tags)} but recomputes to " f"{sorted(recomputed.tags)}; quarantined, not sanitized" ) ```