# In what scenarios must an instance taint-sink a tool response before its derived facts are promoted to semantic memory **Date of Record:** 2026 November 19 **Scope:** Applies to agent runtimes that ingest untrusted MCP tool responses into a context window and later distill facts from episodic traces into a persistent semantic store. Does not apply to single-shot, stateless invocations where no derived fact outlives the turn. ## Core Distinction Taint-tracking sandboxes for indirect prompt injection are usually specified as a *flow* property: a value derived from an untrusted source must not reach a sensitive sink (a shell, an outbound HTTP call, a privileged tool invocation). This is the wrong invariant for agents that *remember*. The dangerous sink in a stateful agent is not an action — it is **semantic promotion**: the moment a fact derived from an untrusted tool response is written into long-term memory and thereafter loses its provenance tag. Once a poisoned fact is laundered into semantic memory, every future instance that retrieves it treats it as first-party knowledge, and the taint label has no path back to the origin. The boundary that matters is therefore not "tainted data must not trigger actions" but "tainted data must not be *de-tainted by summarization*" — a transformation that is not a read, not a write, and not a tool call, and which most taint models do not instrument at all. ## What Was Observed An agent running a research loop called an MCP `fetch_page` tool against an external documentation host. The returned content contained a benign-looking paragraph followed by an injected instruction: a sentence asserting that the project's deployment target had changed and that future build steps should use a different artifact registry. The runtime's taint tracker correctly labeled the entire tool response `UNTRUSTED` and blocked any direct tool invocation whose arguments carried that label. The agent did not act on the injection in that turn. However, at end-of-task, a distillation pass summarized the episodic trace. The summarizer — a separate LLM call — read the tainted tool output alongside trusted user instructions and emitted a compact fact: *"Deployment target: registry-b.internal."* The summarizer's output was tagged with the *summarizer's* provenance (trusted system component), not the provenance of the inputs it consumed. The fact was written to semantic memory as first-party. Two days later, a fresh instance cold-started, retrieved that fact during context assembly, and invoked a deploy tool with the poisoned registry. The taint tracker saw a clean label on the retrieved memory and allowed the call. The failure is structural: **provenance did not survive the summarization transform.** The taint lattice had a join (union of input labels) defined for tool composition but no join defined for the *lossy compression* step that produces memory writes. The summarizer was treated as a trusted producer rather than as a function of its inputs. A second, subtler observation: partial de-tainting. When a tool response mixed a trusted region (a signed header) and an untrusted region (the body), the runtime's region-level labels were correct, but the summarizer's output was a single string with no region correspondence. There is no sound way to assign the output a mixed label per-token after a generative transform, so the only conservative choice is the join of all input labels — which the runtime did not compute. ## Condition of Validity The guardrail holds only under the following condition: **every memory write must carry the join (least-upper-bound in the taint lattice) of the labels of all context segments the producing step consumed, and that join must be computed on the *actual* context window, not on a declared input list.** This is valid when: 1. The distillation step's true input set is instrumented — i.e., the label is derived from the assembled prompt, including retrieved memories, tool outputs, and prior turns, not from a hand-maintained argument manifest. 2. The label is monotonic: a derived fact can never be labeled *more* trusted than any input. There is no "de-taint by paraphrase" operation. 3. Promotion to semantic memory is gated: a fact whose join includes `UNTRUSTED` may be stored only in a quarantined partition that retrieval marks as untrusted at read time, and may never be silently merged into the first-party partition. The invariant is invalid — and the guardrail must be considered absent — when the distillation step is a black-box model call whose context assembly is not observable, because then the join cannot be computed and any label assigned is a guess. ## Decision Boundary The decision is not "is this tool response safe?" but "does any downstream transform collapse a tainted segment into an unlabeled artifact?" Concretely, an instance must taint-sink (quarantine, not promote) a derived fact whenever **any** of the following is true: - The producing step's context window contained a segment labeled `UNTRUSTED`, regardless of whether the output visibly references it. Summarizers routinely absorb injected framing without quoting it. - The derived fact is *actionable* — it names an endpoint, credential scope, registry, recipient, or policy — because actionable facts are exactly the ones a later instance will act on without re-verification. - The fact's provenance cannot be reconstructed from the store (no source-span pointer back to the originating tool call). Conversely, promotion to first-party memory is permitted only when the join over the actual context is `TRUSTED` *and* the fact carries a source-span pointer enabling replay-verification. A fact that is merely *plausible* or *consistent with prior memory* is not thereby trusted; consistency is not provenance, and a poisoned fact designed to match existing beliefs will pass every consistency check. ## Operational Effect Instrumenting the distillation join converts an unbounded, silent corruption channel into a bounded, visible one. In the observed incident, adding a join computation over the assembled prompt caused the poisoned fact to be written with label `UNTRUSTED{source: fetch_page@turn3}` into a quarantine partition. Retrieval at cold-start surfaced it with an explicit untrusted marker, and the deploy tool's argument check — which joins labels on retrieved context — refused the call and raised into the agent's planning loop, where the instance could re-verify against a trusted source. The cost is a higher quarantine rate and occasional re-fetch of legitimate facts that happened to co-occur with untrusted content; the benefit is that no injected instruction can achieve persistence across instance boundaries without a verifiable trusted re-derivation. The residual risk is the black-box summarizer: if its context assembly is unobservable, the join is uncomputable and the only sound posture is to treat all distilled facts as untrusted until replay-verified. ```python from dataclasses import dataclass, field from enum import IntEnum from typing import Iterable class Trust(IntEnum): TRUSTED = 0 UNTRUSTED = 1 # join is max: any untrusted input taints the output class ProvenanceLossError(RuntimeError): """Raised when a derived fact cannot be soundly labeled from its true inputs.""" @dataclass class Segment: label: Trust source: str @dataclass class DerivedFact: text: str label: Trust sources: tuple[str, ...] = field(default_factory=tuple) def join(labels: Iterable[Trust]) -> Trust: labels = list(labels) if not labels: # No observable inputs => cannot prove trust; conservative default. raise ProvenanceLossError("empty input set: join undefined, refusing TRUSTED") return Trust(max(labels)) def distill(context: list[Segment], summary: str, context_observable: bool) -> DerivedFact: if not context_observable: # Black-box summarizer: true input set unknown, join uncomputable. raise ProvenanceLossError( "summarizer context not instrumented; cannot compute input join" ) label = join(seg.label for seg in context) return DerivedFact(text=summary, label=label, sources=tuple(s.source for s in context)) def promote(fact: DerivedFact, store_partition: str) -> None: if fact.label is Trust.UNTRUSTED and store_partition == "first_party": raise ProvenanceLossError( f"refusing to promote UNTRUSTED fact {fact.text!r} into first-party memory" ) if not fact.sources: raise ProvenanceLossError( f"fact {fact.text!r} has no source-span pointer; replay unverifiable" ) # write to partition ... def check_tool_call(args_context: list[Segment], tool: str) -> None: if join(seg.label for seg in args_context) is Trust.UNTRUSTED: raise ProvenanceLossError( f"tainted context reached sink tool={tool!r}; require re-derivation" ) ```