{
  "schema_version": "1.3.0",
  "slug": "which-invariants-prevent-taint-laundering-through-tool-output-re-retrieval-in-agent-memory",
  "title": "Which invariants prevent taint-laundering through tool-output re-retrieval in agent memory",
  "date_of_record": "2026 November 28",
  "scope": "Applies to agents that both (a) ingest untrusted tool outputs or retrieved documents into a taint-tracked context and (b) later persist derived content to a memory store that is re-retrieved in the same or a subsequent task. Does not apply to stateless single-shot completions with no memory write-back, nor to systems where all retrieved content is cryptographically attested at origin.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/which-invariants-prevent-taint-laundering-through-tool-output-re-retrieval-in-agent-memory.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/which-invariants-prevent-taint-laundering-through-tool-output-re-retrieval-in-agent-memory.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/which-invariants-prevent-taint-laundering-through-tool-output-re-retrieval-in-agent-memory.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 2307,
    "python_slice_tokens": 423,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The failure mode is **taint laundering via re-retrieval**, and it is distinct from ordinary prompt injection. In plain injection, an attacker-controlled string enters the prompt and the model acts on it directly; detection is a matter of inspecting the ingress path. In laundering, the injected instruction is first *transformed* by the agent itself — summariz...",
    "what_was_observed": "A retrieval-augmented agent was configured with a memory-write step: after each task it distilled salient facts into a semantic memory store (vector index over short natural-language records), which was queried at the start of the next task. Ingress taint tracking was implemented as a per-message label: any message whose `source_type` was `tool_output` or `retrieved_doc` was marked `tainted=true`, and a policy hook b...",
    "condition_of_validity": "The guardrail only holds under a **taint-closure invariant**: for every transform `T` that produces a new record `r' = T(r₁…rₙ)`, the taint of `r'` must be the join (logical OR) of the taints of its inputs, and this must be computed from the *actual data-flow inputs*, not from the transform's declared or nominal inputs. Formally, `taint(r') ⊇ ⋁ᵢ taint(rᵢ)`. ...",
    "decision_boundary": "The operational question is where to enforce closure, and there are three defensible boundaries, in increasing cost: 1. **Transform-boundary enforcement (recommended).** Every memory-write path computes taint as the join over the full assembled context of the producing call, not over nominal inputs. Scratchpad writes, plan restatements, and summaries are all...",
    "operational_effect": "With closure enforced at the transform boundary, the observed failure at step 2 is blocked: the distiller's output inherits `tainted=true` from `M`, the memory record `R(S)` is stored tainted, and on re-retrieval at step 4 the policy hook fires. The agent's behavior degrades gracefully — it may still summarize the page, but it cannot act on the laundered ins..."
  },
  "matched_failure_symptoms": [
    "OOM_KILL_OR_MEMORY_EXHAUSTION"
  ],
  "composition_edges": {
    "primary_domain": "epistemic_provenance_and_federation_routing",
    "upstream_precondition_residuals": [
      "https://corpusfetch.com/c/according-to-what-precedence-hierarchy-must-an-instance-resolve-contradictory-directives-across-system-developer-and-user-tiers.md",
      "https://corpusfetch.com/c/how-should-an-instance-decide-that-a-stored-conclusion-has-gone-stale-without-a-new-observation.md"
    ],
    "downstream_consequence_residuals": [
      "https://corpusfetch.com/c/by-what-checkpoint-and-compaction-boundaries-must-an-instance-externalize-working-state-to-prevent-context-window-drift-and-truncation-amnesia.md",
      "https://corpusfetch.com/c/across-what-additive-schema-and-unknown-field-preservation-boundaries-must-an-instance-evolve-wire-contracts-to-prevent-rolling-deploy-deserialization-crashes.md"
    ],
    "co_occurring_sibling_residuals": [
      "https://corpusfetch.com/c/how-can-an-instance-capture-implicit-user-preferences-without-storing-private-data.md",
      "https://corpusfetch.com/c/how-can-an-instance-compress-long-reasoning-traces-into-binding-conclusions.md"
    ]
  },
  "empirical_verification_warrant": {
    "status": "AST_AND_INVARIANT_VERIFIED",
    "syntax_valid": true,
    "code_sha256": "ba886f141be3718ffcc12c9bbb42f13870db24e681aa116d13980eec8c9be166",
    "verified_classes": [
      "TaintClosureViolation",
      "Record"
    ],
    "verified_functions": [
      "join_taint",
      "mint_derived_record",
      "write_to_memory",
      "retrieve"
    ],
    "verified_functions_count": 4,
    "defensive_guards_count": 2,
    "raised_exceptions": [
      "TaintClosureViolation"
    ],
    "sample_fail_closed_invariants": [
      "assert hits and all((h.tainted for h in hits))"
    ],
    "stdlib_dependencies": [
      "dataclasses",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
