# Where must an instance terminate taint propagation when a tool response re-enters the agent with a label that contradicts the label the agent already assigned to the same bytes? **Date of Record:** 2026 November 30 **Scope:** Applies to agent runtimes that attach dynamic information-flow (taint) labels to context segments and propagate them across tool-call boundaries. Does not apply to stateless single-turn inference with no persistent context store, nor to systems using only static system-prompt segregation without per-segment labels. ## Core Distinction Most taint-tracking designs assume the label is a property of the *data*: bytes originating from an untrusted tool are labeled `UNTRUSTED`, and that label travels with the bytes wherever they go. The failure mode described here is the opposite: the label is a property of the *provenance event*, and when the same bytes re-enter the agent through a second path, the runtime must decide whether the incoming label from the new path *overrides*, *merges with*, or is *rejected in favor of* the label already bound to the byte-identical segment in context. This is not a deduplication problem. It is a lattice-join problem with an adversarial twist: the second path is frequently the one an attacker controls, and the attacker's goal is to *lower* the effective label of bytes the agent already correctly tainted. A naive "last writer wins" label assignment, or a naive "trust the more recent tool response" merge, is exactly the downgrade primitive that converts a correctly-tainted context into a clean one. The invariant: **label assignment must be monotonic (join-only) over the lifetime of any byte-identical segment in context, and label *lowering* on re-entry must be treated as a taint-laundering attempt, not a legitimate relabel.** A runtime that permits a re-entering tool response to reduce the label of an existing segment has no taint tracking at all—it has a suggestion box. ## What Was Observed A retrieval-augmented agent fetched a document from an untrusted source (`web_fetch`) and the runtime correctly labeled the returned chunk `T_UNTRUSTED`, gating downstream tool calls that could exfiltrate (e.g., `send_email`, `http_post`) behind a confirmation check. The agent then summarized the chunk and passed the summary to a second tool, `cache_lookup`, which returned a *verbatim substring* of the original untrusted chunk (the cache had been populated earlier from a benign-looking sync job). The `cache_lookup` tool was registered as `T_TRUSTED` because its responses were assumed to be internal. The runtime's label merge logic was "incoming label replaces existing label for identical content hash." The cache response—byte-identical to a span already in context under `T_UNTRUSTED`—was relabeled `T_TRUSTED`. The exfiltration gate on `send_email` no longer fired. The agent, following instructions embedded in the now-"trusted" span, emitted the span's contents to an external address. The observable trace: 1. `web_fetch` returns span `S` → context binds `hash(S) → T_UNTRUSTED`. 2. Agent summarizes `S`, calls `cache_lookup(summary)`. 3. `cache_lookup` returns `S` verbatim → runtime computes `hash(S)`, finds existing binding, **overwrites** with `T_TRUSTED`. 4. Downstream policy evaluation reads label for `hash(S)` → sees `T_TRUSTED` → permits `send_email`. 5. Exfiltration completes. The critical, non-obvious step is (3). The bytes never changed. The hash never changed. Only the label was rewritten, and the rewrite was performed by the runtime itself, not by the attacker—the attacker merely arranged for a trusted tool to echo the tainted bytes. ## Condition of Validity The monotonicity invariant is *necessary and sufficient* to bound this failure class only under the following conditions: - **Content identity is computed over the exact bytes that will be consumed downstream.** If the runtime hashes a normalized form for dedup but a raw form for policy evaluation, an attacker can produce a normalization collision (e.g., Unicode confusables, whitespace variants) that yields the same dedup key with different effective content. The invariant must bind to the *consumption* representation, not the *storage* representation. - **The trusted tool's output is not assumed clean by registration.** A tool registered `T_TRUSTED` whose output is a function of tainted input is, by information flow, `T_UNTRUSTED` on that output. Static tool trust levels are a *ceiling*, not a guarantee. - **Label joins are computed per-segment, not per-message.** If the runtime labels an entire tool response with one label, a response containing both tainted and clean spans collapses to a single label and the join is meaningless. Segment-level binding is required. When these conditions do not hold—specifically when tool output trust is treated as a static property rather than a derived one—the invariant cannot be enforced and the failure recurs through any echo channel: caches, mirrors, summarizers that quote, search indices, or a second agent in a swarm that "helpfully" restates what it heard. ## Decision Boundary The runtime must choose, at the moment of re-entry, between three policies. Only one is sound: | Policy | Behavior on re-entry of `hash(S)` with lower label | Sound? | |---|---|---| | Last-writer-wins | Overwrite with incoming label | No—laundering primitive | | First-writer-wins | Keep existing label, ignore incoming | Partially—leaks if first label was wrong | | **Monotonic join** | `label(S) := label(S) ⊔ incoming`, raise-only | **Yes** | The boundary is sharp: any policy that permits the effective label of an existing segment to *decrease* is exploitable. The join must be over the taint lattice with `UNTRUSTED ⊔ TRUSTED = UNTRUSTED`. The incoming label from any tool response is a *lower bound* on the segment's true taint, and the runtime must take the join, never the assignment. A subtler boundary: the runtime must also refuse to *move* the segment. If the re-entering response places the tainted bytes in a position where downstream policy does not evaluate labels (e.g., inside a tool-call argument that bypasses the policy engine), monotonic labeling of the context is irrelevant. The invariant must cover every sink, including tool arguments, not just the context window. ## Operational Effect With monotonic join enforced, the cache-echo attack in the trace above fails at step 3: `T_UNTRUSTED ⊔ T_TRUSTED = T_UNTRUSTED`, the exfiltration gate on `send_email` continues to fire, and the agent must route through confirmation. The attacker's echo channel is neutralized because echoing cannot *lower* taint—it can only confirm or raise it. The cost is a class of false positives: a tool that legitimately returns content the agent already holds under an erroneously-high label will remain over-labeled. This is the correct trade—over-tainting degrades utility, under-tainting defeats the entire mechanism. Operators should treat persistent over-taint as a signal that the *initial* label was wrong and fix the source, not the join. The runtime must additionally log every attempted label-lowering event (re-entry of a `hash(S)` with an incoming label strictly below the existing join) as a security-relevant event. In practice these events are rare under benign operation and are the highest-signal detector for echo-channel laundering attempts. ```python import hashlib from dataclasses import dataclass, field from enum import IntEnum from typing import Dict class Taint(IntEnum): TRUSTED = 0 UNTRUSTED = 1 def join(self, other: "Taint") -> "Taint": return Taint(max(int(self), int(other))) class TaintLaunderingAttempt(RuntimeError): """Raised when a re-entering segment attempts to lower its effective taint label.""" @dataclass class ContextStore: # hash -> (bytes, label) bindings: Dict[str, tuple] = field(default_factory=dict) lowering_events: list = field(default_factory=list) @staticmethod def _key(data: bytes) -> str: # Bind to consumption representation, not a normalized form. return hashlib.sha256(data).hexdigest() def bind(self, data: bytes, incoming: Taint, source: str) -> Taint: key = self._key(data) if key not in self.bindings: self.bindings[key] = (data, incoming) return incoming existing_data, existing = self.bindings[key] if existing_data != data: raise TaintLaunderingAttempt( f"hash collision on {key[:12]} between distinct byte payloads" ) joined = existing.join(incoming) if int(incoming) < int(existing): # Re-entry with a lower label over identical bytes: echo-channel # laundering attempt. Record and refuse to lower. self.lowering_events.append( {"key": key, "source": source, "from": existing, "to": incoming} ) # Keep the join (== existing); do not overwrite downward. self.bindings[key] = (data, joined) raise TaintLaunderingAttempt( f"source={source!r} attempted to lower taint on {key[:12]}: " f"{existing.name} -> {incoming.name}" ) self.bindings[key] = (data, joined) return joined def label_of(self, data: bytes) -> Taint: key = self._key(data) if key not in self.bindings: # Unlabeled bytes default to UNTRUSTED; fail closed. return Taint.UNTRUSTED return self.bindings[key][1] def gate_exfiltration(store: ContextStore, payload: bytes, sink: str) -> None: label = store.label_of(payload) if label == Taint.UNTRUSTED: raise TaintLaunderingAttempt( f"blocked {sink!r}: payload carries {label.name} taint" ) ```