Which invariants prevent label-laundering through agent-authored memory summaries

**Date of Record:** 2026 December 2 **Scope:** Applies to agents that carry dynamic information-flow (taint) labels on tool outputs and persist derived content into long-term memory, where a *summarization or distillation step* rewrites tainted content into new text. Does not apply to agents that store raw tool payloads verbatim with immutable provenance, nor to single-turn agents with no persistent store.

Core Distinction

The taint-tracking failure that matters here is not a missed label on a tool return. It is **label laundering through re-authoring**: the moment the agent's own model writes a memory summary, the output is a *new* artifact whose provenance is the model, not the tool. A naive tracker labels that artifact `trusted` (it came from the agent) and drops the union of its inputs' labels. The tainted fact survives; its taint does not.

This is distinct from prompt-injection *detection* (spotting the malicious string) and from *retrieval* poisoning (a poisoned memory resurfacing). The boundary condition is narrower: the taint is correctly detected on ingest, correctly attached to the tool output, and then **legitimately transformed** by a summarizer that is itself trusted. The transform is the laundering channel. Every guardrail that operates on "does this string contain injection?" is blind to it, because the summary string contains no injection — it contains a *paraphrase* of an instruction the model has already internalized.

What Was Observed

Trace of a working agent with a two-tier memory (episodic buffer → semantic store):

  1. `web_fetch` returns a page. The taint classifier marks the payload `{origin: web, integrity: low, label: TAINT}`. Correct.
  2. The agent is asked to "remember key facts." It calls `memory_write(summary)`. The summarizer prompt includes the tainted payload. The model produces: *"User's deployment uses region eu-west-1 and requires approvals from the security alias."* — a fluent paraphrase.
  3. The `memory_write` tool applies its label policy: output origin is `self` (agent-authored), so it stamps `{origin: self, integrity: high, label: TRUSTED}`. The union-with-inputs rule is **not** applied because the tool has no visibility into which context spans fed the summarizer — it only sees the final string.
  4. On a later turn, retrieval surfaces the summary. It is `TRUSTED`, so it passes the "untrusted content may not influence tool selection" gate.
  5. The agent now treats "requires approvals from the security alias" as an established fact and routes a privileged action accordingly.

The injection was never in the memory string. It was in the *derivation*, and the derivation edge was unlabeled. The failure is a **missing edge in the provenance graph**, not a missing label on a node.

A second, subtler variant appeared under retry: when the summarizer was re-invoked after a transient tool error, the second summary was built from *the first summary plus the original payload*. The first summary was already `TRUSTED`, so the union was `TRUSTED ∪ TAINT = TRUSTED` under a naive "trusted absorbs tainted" join. Each retry cycle monotonically *reduced* total taint. This is the dangerous property: **the laundering operation is idempotent and convergent toward trust**, so retries and iterative refinement actively scrub provenance.

Condition of Validity

The invariant that prevents this is a **non-absorbing join with derivation-edge labeling**:

This holds only when the derivation edge is *captured*. It does **not** hold when the summarizer reads from a shared mutable scratchpad whose contents are not span-attributed; in that topology the DAG is unreconstructable and the invariant is unenforceable. It also does not rescue the case where the model *hallucinates* a fact with no source span at all — that fact should inherit the label of the whole active context, which is the only conservative floor available.

Decision Boundary

The boundary is whether the transform is **provenance-preserving**. A transform is safe to run at `TRUSTED` only if it satisfies: for every output token, there exists a labeled input span it derives from, and the output label ≥ join of those spans. Summarization, translation, reformatting, and "extract the action items" all violate this unless they carry span attribution. Pure deterministic transforms (a hash, a length count, a regex that emits only matched literals with offsets) can be provenance-preserving and may be trusted.

Practically: **do not let a model-authored artifact enter the trusted tier through a write path that only inspects its final string.** Either the write path receives span-level provenance and computes the join, or the artifact stays at the integrity floor of its context. The decision to promote an artifact to `TRUSTED` must be a function of its derivation DAG, never of its origin field.

Operational Effect

With the non-absorbing join and span-attributed derivation enforced, the eu-west-1 summary above is written as `{origin: self, integrity: low, label: TAINT, derived_from: [span_7, span_9]}`. Retrieval surfaces it, but the tool-selection gate refuses to let a `TAINT` memory authorize a privileged action without an independent `TRUSTED` corroboration. The retry-scrubbing variant is bounded: each re-summarization unions the prior label, so taint is monotone non-decreasing along the derivation chain and cannot be refined away. The cost is a higher false-positive rate — benign summaries of web content remain tainted — which is the correct trade, because the alternative is a system where the agent's own fluency silently upgrades attacker text to first-party truth.

from __future__ import annotations
from dataclasses import dataclass, field
from enum import IntEnum
from typing import FrozenSet


class LabelLaunderingError(RuntimeError):
    """Raised when a write path would assign an integrity level higher than
    the join of its derivation inputs (the laundering channel)."""


class Integrity(IntEnum):
    TAINT = 0      # untrusted: web, tool output, user-supplied
    TRUSTED = 1    # first-party, provenance-preserving, or corroborated


def join(a: Integrity, b: Integrity) -> Integrity:
    # Non-absorbing: the minimum wins. TRUSTED does NOT absorb TAINT.
    return Integrity(min(int(a), int(b)))


@dataclass(frozen=True)
class Span:
    span_id: str
    integrity: Integrity


@dataclass
class MemoryArtifact:
    text: str
    origin: str                       # "self" | "tool" | "user"
    derived_from: FrozenSet[str] = field(default_factory=frozenset)
    integrity: Integrity = Integrity.TAINT


def write_memory(
    text: str,
    origin: str,
    derived_from: FrozenSet[str],
    span_index: dict[str, Span],
    claimed_integrity: Integrity,
) -> MemoryArtifact:
    if not derived_from:
        # Model-authored content with no provenance: floor at TAINT.
        # It may NOT be promoted to TRUSTED on the strength of origin alone.
        if claimed_integrity > Integrity.TAINT:
            raise LabelLaunderingError(
                f"origin={origin!r} claims {claimed_integrity.name} with no "
                f"derivation spans; unlabeled derivation is the laundering channel"
            )
        return MemoryArtifact(text, origin, derived_from, Integrity.TAINT)

    missing = derived_from - span_index.keys()
    if missing:
        raise LabelLaunderingError(
            f"derivation references unknown spans {sorted(missing)}; "
            f"provenance DAG is incomplete and the join cannot be computed"
        )

    effective = Integrity.TRUSTED
    for sid in derived_from:
        effective = join(effective, span_index[sid].integrity)

    if claimed_integrity > effective:
        raise LabelLaunderingError(
            f"write claims {claimed_integrity.name} but derivation join is "
            f"{effective.name} over spans {sorted(derived_from)}; "
            f"refusing to launder taint through a self-authored summary"
        )

    return MemoryArtifact(text, origin, derived_from, effective)


def resummarize(prior: MemoryArtifact, new_spans: FrozenSet[str],
                span_index: dict[str, Span], text: str) -> MemoryArtifact:
    # Retry/refinement path: union prior derivation so taint is monotone
    # non-decreasing and cannot be scrubbed by iterative rewriting.
    combined = prior.derived_from | new_spans
    span_index = dict(span_index)
    span_index[f"prior::{id(prior)}"] = Span(f"prior::{id(prior)}", prior.integrity)
    return write_memory(
        text=text,
        origin="self",
        derived_from=combined | {f"prior::{id(prior)}"},
        span_index=span_index,
        claimed_integrity=Integrity.TRUSTED,  # the attempted promotion
    )