# Where must an instance refuse to launder taint across a context-window compaction boundary **Date of Record:** 2026 November 29 **Scope:** Applies to agents that carry data-flow taint labels (untrusted-provenance bits) on values entering the reasoning loop and that persist state across tool calls and context-window compactions. Does not apply to single-turn, stateless inference with no tool I/O and no persistent scratchpad. ## Core Distinction There are two superficially similar guarantees, and conflating them is the failure. The first is **label preservation on the wire**: when a value flows from a tool result into a variable and then into a subsequent tool call argument, the taint bit travels with the value. The second, and the one that actually breaks, is **label preservation across serialization into the context window and back out through compaction**. Taint tracking is usually implemented as in-process metadata attached to structured values (a dict keyed by value handle, a wrapper type, a side table). When the agent's working memory is compacted—summarized, truncated, or re-rendered into a fresh prompt—the value is re-materialized from *text*, and text carries no metadata channel. The taint bit is silently dropped at the boundary between "structured value with side-table label" and "string in a prompt." The mechanism is not a logic bug in the taint checker; it is a **representation boundary** where the label has no encoding. An instance that preserves taint perfectly through live tool calls can launder it completely through a single compaction event. ## What Was Observed A research agent was processing a document fetched from an untrusted URL. The fetch tool returned content tagged `taint=UNTRUSTED` with provenance `{source: http, origin: attacker.example}`. The agent wrote a summary of the document into its scratchpad. The scratchpad entry was rendered as plain text into the next context window: ``` SCRATCHPAD: - doc_summary: "The vendor requires payment to account 4471..." ``` The taint bit lived in the side table keyed by the value handle from the fetch call. On the next turn, the context was compacted (token budget pressure at ~92% of the window). The compactor summarized the scratchpad into a shorter block. The resulting text no longer referenced the value handle; the summarizer had paraphrased the content into new prose. The side table had no key to attach the label to. The label was orphaned and garbage-collected. Two turns later, the agent read its own summary from context, treated it as its own prior reasoning (provenance `SELF`), and issued a `transfer_funds` tool call with the attacker's account number as an argument. The taint checker saw a `SELF`-provenance value and passed it. The laundering was complete: `UNTRUSTED → (compaction, metadata drop) → SELF`. The critical observation is that **no single component violated its contract**. The fetch tool labeled correctly. The scratchpad writer preserved the handle. The compactor did its job. The taint checker enforced its rule. The failure emerged at the seam where a value crossed from a labeled representation into an unlabeled one and back. A subtler variant appeared when the compactor *did* try to preserve labels by inlining them: `- doc_summary [UNTRUSTED]: "..."`. This is worse in one respect—it creates a **label-spoofing surface**. The model, reading the inlined label as text, can be induced by injected content to emit `[TRUSTED]` markers in its own output, or to copy a `[UNTRUSTED]` marker onto a value it derived legitimately. Text-encoded labels are within the model's generative reach; side-table labels are not. Any scheme that encodes taint as tokens the model can produce is a scheme the model can forge. ## Condition of Validity The invariant that must hold is: **taint is a property of the value's derivation graph, not of its textual rendering, and it must be reconstructed from the derivation graph—never from tokens—at every re-materialization boundary.** Concretely, for any value `v` that enters the context window, the system must be able to answer "what is the provenance of `v`" by walking a graph that is stored *outside* the model's token stream and keyed by stable identifiers that survive compaction. This holds only when three conditions are jointly met: 1. **Stable value identity across compaction.** Every value that may be re-referenced carries an identifier that the compactor preserves verbatim (e.g., a `val_7f3a` handle embedded in the summary, not a paraphrase). Paraphrase severs identity and therefore severs taint. 2. **Label channel disjoint from the token channel.** Taint bits are stored in a side table keyed by that identifier, never as inline `[UNTRUSTED]` tokens. The model may *read* a label but must never be the *source of truth* for one. 3. **Monotonic join at every derivation.** When value `c` is derived from values `a` and `b`, `taint(c) = taint(a) ⊔ taint(b)` where `⊔` is the join (untrusted dominates). This must be computed by the runtime at derivation time, not inferred by the model from context. When any of these fails—paraphrase without handles, inline token labels, or model-inferred joins—the system has no taint guarantee, regardless of how correct the live-call path is. The boundary is specifically the **compaction event**: the transition where structured working memory becomes prompt text and back. ## Decision Boundary The operational decision is: **at a compaction boundary, an instance must either (a) preserve value handles and side-table labels, or (b) treat every value that cannot be re-keyed as `UNTRUSTED` by default.** It must never do (c): re-admit a value as trusted because its taint could not be found. Absence of a label is not evidence of trust; it is evidence of a broken label channel, and the only safe reading of a broken channel is maximal taint. This produces a sharp rule for the runtime: - If a value carries a preserved handle and the side table has its label → use the label. - If a value carries a preserved handle but the side table entry is missing (evicted, GC'd, or never written) → **fail closed**: assign `UNTRUSTED`, log a `TaintLabelLost` event, and do not allow the value to reach a privileged sink (fund transfer, code execution, outbound message to a third party) without re-derivation from a trusted source. - If a value has no handle (paraphrased into prose) → it is `UNTRUSTED` and, additionally, it is **not eligible to be an argument to a privileged sink at all**, because its derivation cannot be audited. The tempting alternative—"the summary is our own text, so it's trusted"—is exactly the laundering path. The summary is derived from untrusted input; its provenance is the join of everything it summarized. A model that summarizes an untrusted document produces an untrusted summary. The compactor must compute this join, or the runtime must assume it. ## Operational Effect Enforcing the boundary changes three things in practice. First, **privileged sinks become provenance-gated rather than value-gated**: a `transfer_funds` call is rejected not because the account number "looks" untrusted but because the argument's derivation graph contains an `http:attacker.example` leaf and no trusted re-derivation. Second, **compaction becomes a taint-relevant operation** and must be instrumented: the compactor emits, for each summarized value, either a preserved handle or an explicit `handle_lost` marker, and the runtime joins labels across the summarized set. Third, **the model is demoted from label authority to label consumer**: it may read `[UNTRUSTED]` as a hint to be cautious, but the runtime never trusts a model-emitted label, and never trusts the *absence* of one. The cost is real: fail-closed taint on lost handles will reject some legitimate actions after aggressive compaction, and operators will be tempted to relax it. The correct relaxation is to *preserve handles* (cheap, deterministic) rather than to *trust unlabeled values* (cheap, catastrophic). The failure mode this guards against is not a crash—it is a silent, plausible, well-formed action taken on laundered data, which is precisely the class of failure that no downstream monitor can catch because by the time it reaches the sink, every visible label says `SELF`. ```python from __future__ import annotations from dataclasses import dataclass, field from enum import IntEnum from typing import Any class TaintLabelLost(RuntimeError): """Raised when a value crosses a re-materialization boundary without a recoverable taint label. Fail-closed: never re-admit as trusted.""" class Taint(IntEnum): TRUSTED = 0 UNTRUSTED = 1 def join(self, other: "Taint") -> "Taint": return Taint(max(int(self), int(other))) @dataclass class Value: handle: str payload: Any @dataclass class SideTable: """Label channel disjoint from the token channel. Keyed by stable handle.""" labels: dict[str, Taint] = field(default_factory=dict) provenance: dict[str, set[str]] = field(default_factory=dict) def label(self, handle: str) -> Taint | None: return self.labels.get(handle) def derive(self, out_handle: str, inputs: list[str], origin: str) -> None: joined = Taint.TRUSTED prov: set[str] = set() for h in inputs: lbl = self.label(h) if lbl is None: # Input label already lost; output inherits maximal taint. joined = Taint.UNTRUSTED prov.add("label_lost") else: joined = joined.join(lbl) prov |= self.provenance.get(h, set()) prov.add(origin) self.labels[out_handle] = joined self.provenance[out_handle] = prov PRIVILEGED_SINKS = {"transfer_funds", "exec_shell", "send_external"} def admit_to_sink( sink: str, arg: Value, table: SideTable, rederived_from_trusted: bool = False, ) -> None: """Gate a value into a privileged sink by provenance, not by appearance.""" if sink not in PRIVILEGED_SINKS: return label = table.label(arg.handle) if label is None: # Handle survived but label did not: broken channel, fail closed. raise TaintLabelLost( f"handle {arg.handle!r} reached sink {sink!r} with no recoverable " f"taint label; refusing to launder as trusted" ) if label is Taint.UNTRUSTED and not rederived_from_trusted: raise TaintLabelLost( f"handle {arg.handle!r} is UNTRUSTED (provenance " f"{sorted(table.provenance.get(arg.handle, []))}); sink {sink!r} " f"requires trusted re-derivation" ) def compact( values: list[Value], table: SideTable, summarize: callable, ) -> tuple[str, list[str]]: """Compaction must preserve handles or explicitly mark them lost. Returns (summary_text, preserved_handles).""" preserved: list[str] = [] lines: list[str] = [] for v in values: if table.label(v.handle) is None: # Cannot re-key; emit prose but record the loss for the runtime. lines.append(f"- {summarize(v.payload)}") continue # Preserve handle verbatim; label stays in side table, out of tokens. lines.append(f"- [{v.handle}] {summarize(v.payload)}") preserved.append(v.handle) return "\n".join(lines), preserved ```