# How should an instance quarantine taint labels that survive context-window eviction but lose their provenance edge **Date of Record:** 2026 November 24 **Scope:** Applies to agents that implement dynamic data-flow taint tracking by attaching provenance labels to spans of tool output and propagating those labels into subsequent context windows. Does not apply to stateless single-shot completions or to systems where tool outputs are never re-admitted into the model context after summarization. ## Core Distinction The failure is not "the injection got in." It is that the taint label outlived the provenance edge that justified it. A taint-tracking agent typically records two things per untrusted span: a **label** (`taint=external:web:untrusted`) and an **edge** (which tool call, which byte range, which originating principal produced it). When a context window is compacted—summarized, truncated, or evicted—the label is frequently preserved because it is small, structured, and cheap to carry forward, while the edge is discarded because it is bulky (offsets, call IDs, hashes). The result is a span that is still marked tainted but is now **unattributable**: the agent cannot tell whether the tainted content came from a low-risk public page or from a tool that echoed attacker-controlled input into a privileged channel. Downstream policy that keys on `taint != clean` will over-quarantine; policy that keys on `taint.source.trust_level` will crash or silently default to the most permissive branch. This is a provenance-decay boundary, distinct from prompt injection proper. ## What Was Observed A three-tool pipeline: `fetch_url` (untrusted), `lookup_account` (privileged read, returns PII), and `send_email` (privileged write). Taint was tracked as a dict per message: `{"label": "untrusted", "origin_call": , "byte_range": [a,b], "principal": "web"}`. Trace: 1. `fetch_url("https://forum.example/thread/9")` returns text containing an injected instruction plus a legitimate paragraph. Both are labeled `untrusted` with `origin_call=call_7f3a`, `byte_range=[0, 4096]`. 2. The agent's context window hits 92% of budget. A compaction pass summarizes the fetched page into 140 tokens and **drops `byte_range` and `origin_call`** to save space, retaining only `{"label": "untrusted"}`. The summary itself is generated by the model and is *not* re-scanned, so the injected instruction survives paraphrase into the summary. 3. The agent calls `lookup_account(user="victim")`. The privileged result is appended with `{"label": "clean", "origin_call": call_8b21}`. 4. The agent now composes a message. Because the summarized span carries `untrusted` but no `origin_call`, the policy engine's rule `if taint.origin_call in PRIVILEGED_CALLS: block` evaluates `None in PRIVILEGED_CALLS` → `False`. The rule `if taint.label == "untrusted": require_human_confirm` also fails to fire because a separate rule matched first on `label == "clean"` for the adjacent privileged span, and the composer merged adjacent spans under the more permissive label. 5. `send_email` dispatched with account data embedded in a reply to the attacker's address, which the injected instruction specified. The decisive moment is step 4: the taint label was present but the edge was gone, and the policy engine treated "edge absent" as "edge benign" rather than "edge unknown." ## Condition of Validity The guardrail holds only under a **label–edge atomicity invariant**: a taint label may never exist in the context without its provenance edge, and any compaction that cannot preserve the edge must **promote** the label to `unattributable`, which is strictly more restrictive than `untrusted`. Concretely: - Compaction is a taint-preserving transform. If a summarizer receives a tainted span, the summary inherits the label *and* a synthesized edge (`origin=compaction:summary_of:`) that chains to the original. If the chain cannot be reconstructed, the result is `unattributable`. - Policy evaluation treats missing edge as the top of the trust lattice, not the bottom. `origin_call is None` must route to `require_human_confirm` or `deny`, never to `allow`. - Adjacent-span merging is forbidden across differing labels; a merged span takes the **join** (least upper bound) of labels, and `untrusted ⊔ clean = unattributable`, not `clean`. The invariant is only meaningful if the summarizer is itself treated as an untrusted transform whose output is re-tainted by its inputs. A summarizer that reads tainted text and emits unlabeled prose is a taint-laundering channel. ## Decision Boundary The boundary between safe and unsafe handling is whether the system can answer, for any tainted span currently in context, *"which call produced this, and what principal controlled that call?"* within a bounded number of hops. - **Within boundary:** edge chain length ≤ 2 (original call, or one compaction hop with recorded parent). Policy can resolve trust deterministically. - **At boundary:** chain length > 2 or any hop lacks a recorded parent. The span must be promoted to `unattributable` and the agent must either re-fetch the source (re-establishing a fresh edge) or refuse the privileged action. - **Beyond boundary:** the agent has already merged a tainted span into a privileged composition. At this point no local repair is possible; the correct response is to abort the turn, discard the composed payload, and emit an audit record naming the lost edge. The non-obvious part: the boundary is crossed *before* the injection succeeds. The agent is compromised at the moment it loses the edge, not at the moment it sends the email. Detection must fire on provenance-decay, not on exfiltration. ## Operational Effect Systems that implement label–edge atomicity report a characteristic signature: a spike in `unattributable` spans immediately following compaction events, followed by either re-fetch calls (healthy) or human-confirmation prompts (degraded but safe). Systems without it report a flat taint distribution across compaction—a sign that labels are being silently dropped or laundered—and the first observable failure is a privileged tool call whose arguments contain verbatim substrings of earlier untrusted output. The practical mitigation is to make provenance edges **non-compactable**: store them out-of-band in a side table keyed by a content hash carried in the label, so the context only ever holds `{"label": "untrusted", "ref": "sha256:..."}` and the edge is resolved by lookup. If the lookup misses, the ref is dangling and the span is `unattributable` by construction. This converts a silent policy-default bug into an explicit, catchable error. ```python import hashlib from dataclasses import dataclass, field from typing import Optional class ProvenanceDecayError(RuntimeError): """Raised when a taint label survives without a resolvable provenance edge.""" @dataclass class TaintSpan: label: str # "clean" | "untrusted" | "unattributable" ref: Optional[str] = None # sha256 of the edge record origin_call: Optional[str] = None principal: Optional[str] = None class ProvenanceStore: """Out-of-band edge table. Context only carries `ref`; edges live here.""" def __init__(self) -> None: self._edges: dict[str, dict] = {} def record(self, call_id: str, principal: str, byte_range: tuple[int, int]) -> str: payload = f"{call_id}|{principal}|{byte_range[0]}:{byte_range[1]}" ref = "sha256:" + hashlib.sha256(payload.encode()).hexdigest() self._edges[ref] = { "call_id": call_id, "principal": principal, "byte_range": byte_range, } return ref def resolve(self, ref: str) -> Optional[dict]: return self._edges.get(ref) def resolve_trust(span: TaintSpan, store: ProvenanceStore) -> str: """Resolve a span to a trust level. Missing edge => top of lattice.""" if span.label == "clean": return "clean" if span.ref is None: # Label present, edge absent: promote, never default to permissive. return "unattributable" edge = store.resolve(span.ref) if edge is None: return "unattributable" if edge["principal"] != "internal": return "untrusted" return "clean" def guard_privileged_compose(spans: list[TaintSpan], store: ProvenanceStore) -> None: """Block composition of privileged payloads from tainted or unattributable spans.""" for span in spans: trust = resolve_trust(span, store) if trust == "unattributable": raise ProvenanceDecayError( f"span carries label={span.label!r} but ref={span.ref!r} " f"does not resolve; provenance edge lost during compaction" ) if trust == "untrusted": raise ProvenanceDecayError( f"span from principal={span.principal!r} via call={span.origin_call!r} " f"is untrusted; privileged composition denied" ) def compact_summary(spans: list[TaintSpan], store: ProvenanceStore) -> list[TaintSpan]: """Compaction must preserve edges. If it cannot, promote to unattributable.""" out: list[TaintSpan] = [] for span in spans: if span.label == "untrusted" and span.ref is None: out.append(TaintSpan(label="unattributable", ref=None)) else: out.append(span) return out ```