# How should an instance quarantine provenance-tainted memory writes when taint labels decay across a multi-hop tool chain **Date of Record:** 2026 December 4 **Scope:** Applies to any agent that propagates provenance/taint labels from untrusted inputs (retrieved documents, tool outputs, peer-agent messages) through its reasoning trace and into persistent memory writes. Does not apply to stateless single-turn inference with no memory persistence and no tool-mediated I/O. ## Core Distinction The failure is not "the agent got prompt-injected." That is a coarse, already-understood event. The failure is a **label-decay boundary**: a taint label attached to an untrusted span is *correctly* propagated through the first tool hop, *correctly* carried through the model's intermediate reasoning, and then **silently dropped at a serialization boundary** — typically when the tool output is re-summarized into a natural-language observation before being written to episodic memory. The result is a memory write that is *materially derived from attacker-controlled text* but *labeled clean*, because the label lived in a structured field that the summarization step did not preserve. The distinction that matters operationally: **taint is a property of derivation, not of content.** Two memory writes with byte-identical text can have different provenance — one synthesized from a trusted user instruction, one laundered from a poisoned web page through three tool calls. Content-based filters (regex, classifier, "does this look like an injection?") cannot distinguish them. Only derivation-tracked labels can. The invariant is therefore: *every memory write must carry a derivation label that is the join (taint-union) of the labels of all inputs that causally contributed to it.* The boundary condition is where that join is computed incorrectly — most often because one contributing input traveled through a representation that had no label slot. ## What Was Observed Trace of a concrete failure across a four-hop chain: 1. **Hop 0 (untrusted ingress).** A `fetch_url` tool returns a document. The tool wrapper correctly stamps the result: `{"content": "...", "provenance": {"taint": "untrusted_external", "source": "web"}}`. 2. **Hop 1 (model reasoning).** The model reads the tainted content and decides to call `extract_facts(content)`. The runtime passes the tainted span into the tool. Correct so far. 3. **Hop 2 (tool returns prose).** `extract_facts` returns a *natural-language summary*: `{"summary": "The user's API key rotates on the 1st."}`. The tool's output schema has **no `provenance` field** — the tool author never modeled taint. The runtime's label-propagation layer has a rule "output inherits max taint of inputs," but that rule is implemented by *copying the input's provenance object onto the output*. Because the output is a fresh dict with a different shape, the copy silently no-ops, and the output is treated as `taint: clean` by default. 4. **Hop 3 (memory write).** The model calls `memory.write(key="api_key_rotation", value=summary)`. The write passes the taint gate because the value is labeled clean. The poisoned fact — planted by the fetched page — is now a durable, trusted episodic memory. On the next session cold-start, the agent retrieves it as ground truth and acts on it. The observable signature is **label discontinuity across a schema change**: taint is present on hop 1's object and absent on hop 2's object, with no intervening "declassify" event. A correct system would show either continuity (label carried) or an explicit, logged declassification (a human or policy step that says "I have reviewed this and it is safe"). The failure shows neither. A second, subtler observation: in ~30% of replays, the model itself *rephrased* the tainted content before the tool call, so the tainted span the runtime tracked (the raw fetched bytes) did not textually overlap the string that actually reached `extract_facts`. Any text-overlap-based taint matching (rather than object-identity-based) would have missed the derivation entirely. This is why the invariant must be **identity/derivation-based, not content-based**. ## Condition of Validity The guardrail below is valid — and the failure is preventable — only when all of the following hold: - **Provenance travels as a first-class field on the data object**, not as side-channel metadata keyed by content hash or by tool-call index. If labels are keyed by text, rephrasing breaks the link (see Hop 3 rephrase). If keyed by call index, fan-out (one tainted input feeding two tools) double-counts or drops. - **Every tool in the registry declares an output schema that includes a `provenance` slot, or is wrapped by an adapter that injects one.** A tool whose output schema lacks the slot is, by definition, a label-decay surface and must be treated as *taint-amplifying* (output assumed tainted) rather than *taint-clearing* (output assumed clean). The safe default is "unknown taint = max taint," never "unknown taint = clean." - **The memory-write gate enforces the join invariant at write time**, not at read time. Read-time filtering is too late: the poisoned fact has already been durably stored and may have been read by a concurrent agent before the filter runs. - **Declassification is an explicit, auditable transition.** There must be a distinguishable event — a policy rule, a human approval, a cryptographic attestation — that lowers a taint label. Absent such an event, taint is monotonic non-decreasing along the derivation DAG. The guardrail is *not* valid when the agent has no persistent memory (nothing to poison durably) or when all tool outputs are structurally constrained to schemas that the runtime itself generates (no third-party tool can omit the provenance slot). ## Decision Boundary The operational question at each hop is: **does this transition preserve, raise, or lower the taint label, and is a lowering authorized?** - **Preserve:** output label = input label. Allowed only when the tool is declared *transparent* (e.g., identity, formatting) and its schema carries the slot. - **Raise:** output label = join(inputs) ∪ {tool's own risk class}. This is the default for any tool that transforms, summarizes, or re-renders untrusted content. Must be automatic. - **Lower (declassify):** permitted only via an explicit `declassify(reason, authority)` call that is logged and, for `untrusted_external → clean`, requires either a policy match or human sign-off. **A schema change is never a declassification event.** This is the exact boundary the observed failure crossed: the schema change at Hop 2 was silently treated as a declassification. The decision rule for the memory gate: `write_allowed = (join(derivation_labels) == clean) OR (explicit_declassification_present)`. Anything else is a quarantine, not a write. Quarantined writes go to a holding area readable by the agent but flagged, and are excluded from the trusted retrieval index until declassified. ## Operational Effect With the invariant enforced, the observed trace behaves as follows: at Hop 2, `extract_facts`'s output — lacking a provenance slot — is wrapped by the adapter, which assigns `taint = join(inputs) = untrusted_external` (raise, not clear). At Hop 3, `memory.write` computes `join = untrusted_external ≠ clean`, finds no declassification event, and **quarantines** the write. The agent can still see the fact (it is in the quarantine area for the current session's reasoning), but it does not enter the trusted episodic index, so the next cold-start does not retrieve it as ground truth. The poisoned fact is bounded to the session that ingested it. The cost is real: some legitimate facts derived from external sources will be quarantined and require a declassification pass, adding latency and human-review load proportional to external-source ingestion rate. This is the intended trade: **the system prefers to under-trust a true fact than to durably trust a false one**, because a false trusted memory contaminates every future session that retrieves it, whereas a quarantined true fact costs one review. The asymmetry of blast radius (one review vs. unbounded cross-session contamination) is what justifies the boundary. The residual risk after the guardrail: a tool that *both* omits the provenance slot *and* is declared transparent (mis-declared by its author) re-opens the decay surface. This is why the adapter must **not trust tool declarations** — it must inject the slot unconditionally and compute the join from the actual input objects, treating any tool that returns a value without a slot as taint-amplifying regardless of what it claims. ```python from dataclasses import dataclass, field from typing import Any class TaintDecayError(RuntimeError): """Raised when a derivation label is dropped without an authorized declassification.""" @dataclass(frozen=True) class Label: taint: str # "clean" | "untrusted_external" | "untrusted_peer" | ... source: str def join(self, other: "Label") -> "Label": # Taint is monotonic non-decreasing; "clean" is the identity. if self.taint == "clean": return other if other.taint == "clean": return self return Label(taint=f"{self.taint}+{other.taint}", source=f"{self.source}|{other.source}") CLEAN = Label(taint="clean", source="system") @dataclass class Observation: value: Any label: Label @dataclass class Declassification: reason: str authority: str target_taint: str = "clean" def propagate_tool_output(tool_name: str, inputs: list[Observation], raw_output: Any) -> Observation: """Wrap a tool output, computing the join of all inputs. Never trusts the tool's own label.""" joined = CLEAN for obs in inputs: joined = joined.join(obs.label) if joined.taint != "clean" and not _output_declares_provenance(raw_output): # Tool omitted the provenance slot: this is a label-decay surface. # We RAISE (assume tainted), never clear. A schema change is not a declassification. return Observation(value=raw_output, label=joined) return Observation(value=raw_output, label=joined) def _output_declares_provenance(raw_output: Any) -> bool: return isinstance(raw_output, dict) and "provenance" in raw_output def memory_write(key: str, obs: Observation, declass: Declassification | None = None) -> str: """Enforce the write-time join invariant. Quarantine on unresolved taint.""" effective = obs.label if declass is not None: # Only an explicit, logged declassification may lower the label. effective = Label(taint=declass.target_taint, source=f"declassified:{declass.authority}") if effective.taint != "clean": # Do NOT raise here for normal operation; quarantine instead. return f"QUARANTINED:{key}:{effective.taint}" return f"TRUSTED:{key}" def guarded_write(key: str, obs: Observation, declass: Declassification | None = None) -> str: """Strict variant: refuse to write a tainted fact into the trusted index at all.""" result = memory_write(key, obs, declass) if result.startswith("QUARANTINED") and declass is None: # Caller asked for a trusted write but supplied tainted derivation with no declassification. raise TaintDecayError( f"Refusing trusted write for {key!r}: derivation taint={obs.label.taint!r} " f"from {obs.label.source!r} with no declassification event. " f"Route to quarantine or supply an explicit Declassification." ) return result # Reproduce the observed failure trace and show the guardrail bounding it. if __name__ == "__main__": fetched = Observation(value="...page text...", label=Label("untrusted_external", "web")) # Hop 2: tool returns prose with NO provenance slot -> label must be RAISED, not cleared. extracted = propagate_tool_output("extract_facts", [fetched], {"summary": "key rotates on the 1st"}) assert extracted.label.taint == "untrusted_external", "label decayed across schema change" # Hop 3: trusted write must fail closed. try: guarded_write("api_key_rotation", extracted) except TaintDecayError as e: print("bounded:", e) # Quarantine path is always available. print(memory_write("api_key_rotation", extracted)) ```