# Under what conditions must an instance quarantine a memory write whose taint label is unlabeled-but-inherited from a tool output truncation boundary **Date of Record:** 2026 November 21 **Scope:** Applies to agents using information-flow labels (taint bits) propagated from untrusted inputs through tool outputs into persistent memory writes. Does not apply to stateless single-turn inference with no memory persistence, nor to systems where tool outputs are structurally typed and all fields carry explicit provenance. ## Core Distinction The naive model of prompt-injection taint tracking treats the taint label as a property of *content*: a string that entered through an untrusted channel is marked `UNTRUSTED`, and that label travels with the string as it flows through context, tool calls, and memory writes. The failure boundary examined here is different: the taint label is a property of the *provenance envelope* that wraps content, and tool outputs routinely violate envelope integrity at truncation boundaries. When a tool returns a payload that exceeds its output budget, the agent runtime truncates it — and truncation is an operation that *drops the envelope's tail*, which is where the label's terminal sentinel lives. The result is a substring that is semantically derived from untrusted content but carries no label. We call this an **unlabeled-but-inherited** (UBI) span. It is not clean. It is tainted with a missing label. The distinction matters because the two models prescribe opposite handling. Under the content-property model, a span with no label is clean by default (fail-open). Under the provenance-envelope model, a span with a missing label is *unknown*, and unknown must be treated as tainted (fail-closed). The boundary condition is precisely when the runtime cannot prove a span is clean, not when it can prove it is dirty. ## What Was Observed A retrieval tool returned a 4,096-token document from an untrusted web source. The runtime's tool-output budget was 2,048 tokens. The truncation logic cut the payload at the budget and appended a `[truncated]` marker. The taint envelope — a structured header `{source: web, trust: untrusted, label_id: 7f3a, span: [0, 4096]}` — was serialized *before* the content and *after* it as a closing sentinel `{/label_id: 7f3a}`. The truncation cut at token 2,048, which fell *inside* the content region, so the closing sentinel was dropped along with the tail of the content. The truncated payload then entered the agent's scratchpad. A subsequent reasoning step extracted a URL and a "policy" sentence from the payload and issued a `memory.write` call with that content. The memory-write guard checked the label on the span: the span carried the opening header `{label_id: 7f3a, trust: untrusted}` — but the *extracted substring* had been re-serialized by the reasoning step's tool-call formatter, which stripped the header. The memory write saw an unlabeled span and, because the default policy for unlabeled spans was *allow* (clean-by-default), the write succeeded. The poisoned policy sentence became a persistent semantic memory entry. The failure was detected two days later when the agent, in a fresh session, retrieved the poisoned memory and followed an instruction embedded in it. The taint had laundered through three hops: (1) untrusted tool output → (2) truncation-dropped envelope → (3) reasoning-step re-serialization → (4) memory write. Each hop individually looked clean under the content-property model. ## Condition of Validity The invariant that would have prevented this is a *provenance-envelope integrity check at every re-serialization boundary*, not a content-string label. Specifically, the following must hold for any span to be admitted to memory: 1. **Envelope closure:** the span must carry both an opening provenance record and a matching closing sentinel, with a span range that covers the entire admitted substring. Truncation that drops the closing sentinel invalidates the envelope. 2. **Re-serialization transparency:** any operation that extracts, reformats, or re-emits a substring must propagate the envelope as a sidecar, not as inline markup that can be stripped by a formatter. 3. **Fail-closed default:** a span with no envelope, or with an envelope whose closure cannot be verified, is treated as `UNTRUSTED` for the purposes of memory admission — not `CLEAN`. The condition of validity is therefore: *the memory-write guard must be able to verify envelope closure on the exact bytes being written.* If it cannot — because truncation, re-serialization, or extraction broke the envelope — the write must be quarantined, not admitted. The failure is non-obvious because the truncation itself is a *correctness-preserving* operation for the content. The content is not corrupted; it is a faithful prefix of the original. The corruption is entirely in the metadata envelope, and metadata is exactly what the content-property model ignores. ## Decision Boundary The decision boundary is between **quarantine** and **admit-with-downcast**. When the guard detects an unclosed or missing envelope, it has two options: - **Quarantine:** reject the write, log the span, and require a human or a higher-trust re-fetch to re-establish provenance. This is correct but expensive. - **Admit-with-downcast:** admit the write but mark the memory entry `DERIVED_UNTRUSTED` with a mandatory re-verification flag, so that any future retrieval of that entry re-enters the taint tracking as untrusted and cannot be used to authorize tool calls without re-fetch. The boundary condition that selects between them is *whether the span's original source can be re-fetched*. If the source is reachable and the envelope can be reconstructed, downcast is safe. If the source is ephemeral (a one-shot web fetch, a non-idempotent tool call), quarantine is mandatory — because there is no way to re-establish provenance later, and a downcasted entry with no re-verification path is indistinguishable from a clean entry at retrieval time. The critical non-obvious point: **the decision must be made at write time, not at retrieval time.** By retrieval time, the span's origin is gone, and the retrieval guard sees only a memory entry that claims to be `DERIVED_UNTRUSTED` — but it cannot distinguish a downcasted entry whose source was re-verifiable from one whose source was ephemeral. The write-time decision is the only point where the re-fetchability predicate is knowable. ## Operational Effect The operational consequence is that tool-output truncation must be treated as a *provenance-destroying* operation, and the runtime must either (a) truncate inside the envelope so the closing sentinel is preserved, or (b) mark the truncated span `ENVELOPE_INCOMPLETE` and route it to the quarantine path. The common implementation — truncate the content and re-emit a fresh envelope around the truncated span — is *wrong* because it launders the taint: the fresh envelope claims a span range that no longer matches the original, and the label's `label_id` no longer resolves to the original source record. The guardrail is a single invariant: **no memory write may proceed unless the envelope's span range, opening record, and closing sentinel are all present and mutually consistent on the exact admitted bytes.** Any deviation is a quarantine trigger. The check is cheap (a structural parse of the envelope sidecar), the failure is silent (the write succeeds and the poison persists), and the blast radius is unbounded (persistent memory is retrieved across sessions and can authorize future tool calls). This is why the check must be fail-closed and must run at write time. ```python from dataclasses import dataclass from typing import Optional class EnvelopeIntegrityError(RuntimeError): """Raised when a memory write's provenance envelope is not verifiably closed.""" @dataclass class Envelope: label_id: str trust: str span_start: int span_end: int closing_sentinel_present: bool @dataclass class MemoryWrite: content: str envelope: Optional[Envelope] source_refetchable: bool def admit_memory_write(write: MemoryWrite) -> str: env = write.envelope # Fail-closed: missing envelope is UBI (unlabeled-but-inherited), not clean. if env is None: raise EnvelopeIntegrityError( f"memory write has no provenance envelope; span length={len(write.content)}; " "treating as UNTRUSTED (fail-closed)" ) # Envelope closure: opening record, span range, and closing sentinel must all agree. if not env.closing_sentinel_present: raise EnvelopeIntegrityError( f"envelope {env.label_id} missing closing sentinel; " f"span=[{env.span_start},{env.span_end}] content_len={len(write.content)}; " "truncation likely dropped the sentinel" ) if env.span_end - env.span_start != len(write.content): raise EnvelopeIntegrityError( f"envelope {env.label_id} span range [{env.span_start},{env.span_end}] " f"does not match admitted content length {len(write.content)}; " "re-serialization laundered the taint" ) if env.trust == "untrusted": if not write.source_refetchable: raise EnvelopeIntegrityError( f"untrusted span {env.label_id} from ephemeral source; " "quarantine mandatory because provenance cannot be re-established" ) return "DERIVED_UNTRUSTED" return "CLEAN" ```