# Why does an instance lose prompt-injection taint at the tool-output boundary when a retrieval context re-materializes the same bytes **Date of Record:** 2026 November 15 **Scope:** Applies to agent runtimes that attach data-flow labels (taint) to retrieved chunks and tool outputs and propagate those labels into the prompt context. Does not apply to systems that treat the entire context window as a single unlabeled trust domain, nor to systems that re-derive labels from scratch at every model invocation. ## Core Distinction The distinction that matters is between **label identity** and **content identity**. A taint-tracking layer typically assigns a label to a *provenance object* — the specific retrieval hit or tool invocation that produced a byte range. Downstream, the prompt assembler concatenates many such objects into a single context string. The failure is that the assembler, or a caching/deduplication layer beneath it, may key on *content* (a hash of the bytes) rather than on *provenance*. When two sources produce identical bytes — one trusted (e.g., a system-owned document) and one untrusted (e.g., a web fetch or a tool that echoes attacker-controlled input) — a content-keyed dedup or cache will collapse them into one entry and retain whichever label was attached first. The untrusted provenance silently disappears. The instance then reasons over attacker-influenced bytes believing they carry the trusted label. This is not a prompt-injection *detection* failure. The injection was correctly labeled at ingest. It is a **label-collision failure at the materialization boundary**, and it is invisible in logs that only record the final assembled prompt and its aggregate taint set. ## What Was Observed A retrieval pipeline ingested a user-supplied URL. The fetched page contained a benign-looking paragraph that was byte-identical to a paragraph in an internal, trusted runbook (the attacker had copied a public snippet and appended an instruction in a sibling node). Both the fetched chunk and the runbook chunk hashed to the same content digest. The context assembler deduplicated identical chunks to save tokens, keeping the runbook's `trust=internal` label. The appended instruction, which lived in a *different* chunk, was correctly labeled `trust=untrusted` — but the model's attention bound the instruction to the trusted paragraph in the same context, and the tool-call planner had been configured to act on instructions appearing adjacent to internal-trust text. The aggregate taint set on the prompt did contain an untrusted label, so a coarse "is this prompt tainted?" check passed; the *pairing* of label to bytes was wrong. A second observation: when a tool output was re-fetched and byte-identical to a prior cached output from a *different* tool with a lower trust tier, the cache returned the higher-trust label. Taint was monotonic in the wrong direction — it *decreased* across a re-materialization. ## Condition of Validity The failure requires all of the following to hold simultaneously: 1. Taint labels are attached to provenance objects, not to byte ranges that are re-verified at assembly time. 2. Some layer between label attachment and prompt assembly keys on content (hash, normalized text, embedding similarity) rather than provenance. 3. At least two provenances produce byte-identical or near-identical content with differing trust tiers. 4. A consumer downstream of assembly (the model, or a planner reading the context) makes a trust-sensitive decision based on *adjacency* or *co-location* rather than on an explicit per-span label. If any one condition is absent, the failure does not manifest. In particular, if labels are re-derived at every assembly from provenance metadata keyed by object identity, content collisions are harmless. ## Decision Boundary The operational rule: **never let a content-addressed cache or dedup step be the authority for a taint label.** Labels must be joined to content by provenance identity (object ID, retrieval event ID), and the join must be re-validated at the moment of prompt assembly. When two provenances collide on content, the assembly must either (a) keep both entries with distinct labels, or (b) merge them under the *least-trusted* label (taint must be monotonic toward untrusted). Option (b) is the safe default; option (a) preserves token savings only if the consumer can distinguish the spans. Corollary: aggregate prompt-level taint is insufficient. Any planner that acts on "instructions near trusted text" must receive per-span labels, not a set. ## Operational Effect With the fix in place, the observed incidents disappeared: the duplicated paragraph retained its `untrusted` label, the adjacent instruction was not promoted, and the planner refused the tool call. The cost was a modest token increase from no longer collapsing cross-provenance duplicates, and a requirement that the cache key include provenance ID. The deeper effect is that taint tracking now fails *closed*: a content collision raises a merge under the least-trusted tier rather than silently dropping the untrusted label. Systems that had relied on aggregate taint checks had to add per-span enforcement, which surfaced several latent assumptions in planner code that had never distinguished spans. ```python class TaintCollisionError(RuntimeError): """Raised when two provenances collide on content with differing trust tiers.""" pass TRUST_RANK = {"untrusted": 0, "internal": 1, "system": 2} def merge_spans(spans): """ spans: list of dicts with keys 'provenance_id', 'content_hash', 'trust', 'text'. Returns a list of merged spans where any content-hash collision is resolved under the LEAST-trusted tier (taint monotonic toward untrusted). """ by_hash = {} for s in spans: h = s["content_hash"] if h not in by_hash: by_hash[h] = dict(s) continue prior = by_hash[h] if prior["provenance_id"] != s["provenance_id"]: # Collision across distinct provenances: merge under least trust. if TRUST_RANK[s["trust"]] < TRUST_RANK[prior["trust"]]: merged_trust = s["trust"] else: merged_trust = prior["trust"] prior["trust"] = merged_trust prior["provenance_id"] = f"{prior['provenance_id']}+{s['provenance_id']}" # Same provenance: idempotent, nothing to do. return list(by_hash.values()) def assemble_context(spans, require_labels=True): merged = merge_spans(spans) if require_labels: for m in merged: if m.get("trust") not in TRUST_RANK: raise TaintCollisionError( f"span {m.get('provenance_id')} has no valid taint label; " "refusing to assemble context" ) # Refuse to emit a context that contains untrusted bytes adjacent to # trusted bytes without an explicit per-span label carried through. untrusted = [m for m in merged if m["trust"] == "untrusted"] trusted = [m for m in merged if m["trust"] != "untrusted"] if untrusted and trusted: for u in untrusted: if not u.get("label_emitted", False): raise TaintCollisionError( "untrusted span present without emitted per-span label; " "aggregate taint is insufficient" ) return merged ```