# What happens when an instance launders tainted data through a tool-call boundary that reports success on a partial write **Date of Record:** 2026 November 19 **Scope:** Applies to agents that carry a taint-label (provenance/trust bit) on every value in working memory and enforce policy at each tool invocation boundary. Does not cover pure prompt-injection filters, static schema validators, or post-hoc output scanners that operate on the final assistant message rather than on individual call arguments. ## Core Distinction The distinction that matters at a tool-call boundary is not *whether a value is tainted* but *whether the taint survives the round trip through the tool's return channel*. Two structurally different things get conflated by almost every taint-tracking implementation: 1. **Argument-side taint**: the label attached to a value the agent is about to *send* into a tool. This is easy to enforce — the gateway inspects `args`, compares against the policy set for that tool, and either admits or rejects the call. 2. **Return-side taint**: the label that *should* be attached to the tool's output, which is a function of (a) the labels of the inputs, (b) the tool's declared propagation rule, and (c) whether the tool actually completed the operation it claims to have completed. The non-obvious failure lives in the third factor. A tool that returns `{"status": "ok"}` after a *partial* side effect — wrote 3 of 5 records, committed the first transaction in a two-phase sequence, returned a truncated list because it hit an internal page limit — produces a return value whose taint label is computed as if the operation were total. The agent's taint engine then propagates the *declared* label, not the *observed* one, and downstream calls that should have been blocked by a high-taint return are admitted because the return looked clean and complete. This is taint laundering by partial-success: the boundary reports success, the propagation rule fires on the nominal output type, and the residual un-accounted-for effect (the 2 unwritten records, the un-committed second phase) escapes the label graph entirely. ## What Was Observed A three-agent pipeline (extractor → transformer → committer) ran with a per-call taint gateway. The extractor read from an untrusted external source and produced records labeled `TAINT:EXTERNAL`. The transformer consumed those records and was permitted to call `db.stage_write`, which the policy table declared as `propagate: TAINT:EXTERNAL -> TAINT:INTERNAL_STAGED`. The committer was permitted to call `db.commit` only on values labeled `TAINT:INTERNAL_STAGED` or lower. The failure trace, in order: 1. Extractor emitted 5 records, all `TAINT:EXTERNAL`. Correct. 2. Transformer called `db.stage_write` with all 5 in a single batch. The tool's internal retry logic wrote records 1–3, then hit a transient lock on record 4, exhausted its retry budget, and returned `{"status": "ok", "written": 3}`. It did **not** raise. It reported `ok`. 3. The taint gateway, keyed on the tool's declared propagation rule and the *nominal* output type (`BatchResult`), labeled the entire return value `TAINT:INTERNAL_STAGED`. The `written: 3` field was not consulted by the propagation rule because the rule was written against the type, not the payload. 4. The transformer then constructed a commit payload from the staged records. Because the return was labeled `INTERNAL_STAGED`, the transformer's own working memory now contained 5 values at `INTERNAL_STAGED` — but only 3 of them corresponded to actually-staged rows. The other 2 were the transformer's *local copies* of the original records, which had been re-labeled by an aliasing bug: the transformer held references to the same dict objects it had passed into `stage_write`, and the gateway's relabeling mutated the label on the shared object in place. 5. Committer called `db.commit` on all 5. Policy admitted the call (label was `INTERNAL_STAGED`). Commit succeeded for 3, failed with a foreign-key violation for the 2 that were never staged. The committer's error handler caught the FK violation, logged it, and returned `{"status": "partial"}` — which the orchestrator interpreted as "retry later" and re-queued the whole batch. The second pass re-staged all 5 (records 1–3 were now duplicates), and the committer's `db.commit` — which was not idempotent — inserted 3 duplicate rows. The taint graph never registered that the *provenance* of the committed rows included the untrusted origin, because the label had been overwritten to `INTERNAL_STAGED` at step 3 and never re-derived. The observable signature: an audit log where 6 rows exist for 5 source records, all labeled `INTERNAL_STAGED`, with no record of the `TAINT:EXTERNAL` origin. The laundering was complete and silent. ## Condition of Validity The invariant that must hold for taint-propagation to be sound at a tool boundary is: > **For every tool call, the return-value label must be the join (least upper bound) of (a) the argument labels, (b) the tool's declared propagation rule, and (c) the *completion status* of the operation as reported in the return payload. If the operation is partial, the label must include a `TAINT:INCOMPLETE` marker that downgrades the value's admissibility for all downstream tools whose policy requires total completion.** Three preconditions make this invariant enforceable, and all three were violated in the trace above: - **No in-place relabeling of caller-owned objects.** The gateway must return a *new* value with the new label, not mutate the caller's object. Aliasing across the boundary defeats the entire label graph because the caller can hold a reference whose label changes underneath it. This is the single most common implementation defect in taint gateways that pass Python dicts by reference. - **Completion status must be a first-class field in the propagation rule, not a free-text string.** A rule keyed on `type == BatchResult` cannot distinguish `written: 3` from `written: 5`. The rule must be keyed on a structured `completion: {requested: N, completed: M, failed: [indices]}` and must fire `TAINT:INCOMPLETE` whenever `M < N`. - **The downstream policy must be completion-sensitive.** `db.commit` must require `completion == total` in addition to the label check. A policy that checks only `label in {INTERNAL_STAGED}` will admit partial batches. When these preconditions hold, the invariant is sound. When any one fails, taint laundering by partial-success is possible, and the failure is silent because every individual component reports success. ## Decision Boundary The boundary where this becomes an operational decision is the moment the agent must choose between three responses to a partial-success return: | Observed return | Naive action | Correct action under the invariant | |---|---|---| | `ok, written: 3/5` | Propagate `INTERNAL_STAGED`, proceed to commit | Re-derive label as `INTERNAL_STAGED ⋁ INCOMPLETE`, block commit, escalate or re-stage the missing 2 | | `partial, failed: [4,5]` | Retry whole batch (non-idempotent → duplicates) | Re-stage only `{4,5}` with idempotency key; commit only after `completion == total` | | `error` (raised) | Catch, retry, proceed | Correct — but only if the tool actually raised rather than returning `ok` on partial | The decision rule: **a tool boundary is only sound if the tool's return type carries a structured completion record, and the taint gateway's propagation function reads that record.** Any tool that returns a bare status string on a batch operation is a laundering vector and must be treated as `TAINT:INCOMPLETE` unconditionally until its return type is fixed. The corollary decision: when the agent cannot fix the tool (third-party MCP server, legacy endpoint), the correct posture is to *downgrade the tool's declared propagation rule to always emit `INCOMPLETE`* and require the caller to reconcile by re-reading the target state before proceeding. This is slower but sound. The alternative — trusting the declared `ok` — is the failure above. ## Operational Effect The downstream effect is that the agent's memory contains values whose provenance is *wrong*, not merely *stale*. Stale memory can be corrected by re-reading the source. Laundered memory cannot, because the label that would trigger a re-read has been overwritten. The agent will continue to operate on the assumption that `INTERNAL_STAGED` values are safe to commit, and the error only surfaces when a downstream constraint (foreign key, unique index, business rule) rejects the operation — at which point the agent's error handler sees a *storage* error, not a *provenance* error, and responds with the wrong remedy (retry, which duplicates). The compounding effect across a multi-agent pipeline is worse. Each hop that receives an `INTERNAL_STAGED` value and re-stages it produces a new label that is further from the origin. After three hops, the value is `INTERNAL_STAGED` at every layer and the original `TAINT:EXTERNAL` is unrecoverable from the label graph. The audit trail must therefore be reconstructed from the tool-call log, not from the label state — which means the tool-call log must be immutable and must record the *pre-call* labels of arguments, not just the post-call labels of returns. The guardrail that bounds this: **every tool-call boundary must emit a log record containing `{call_id, tool, arg_labels, declared_rule, completion_status, return_label}` before the return value is admitted to working memory.** If `completion_status` is partial and `return_label` does not include `INCOMPLETE`, the gateway must raise rather than admit. This converts a silent laundering into a loud, attributable failure at the boundary where it originated. ```python from dataclasses import dataclass, field from typing import Any, Dict, List, Optional class TaintLaunderingError(RuntimeError): """Raised when a tool boundary would admit a partial-success return without an INCOMPLETE taint marker, laundering provenance.""" pass @dataclass(frozen=True) class Label: bits: frozenset # e.g. {"EXTERNAL"}, {"INTERNAL_STAGED"}, {"INCOMPLETE"} def join(self, other: "Label") -> "Label": return Label(self.bits | other.bits) def __contains__(self, name: str) -> bool: return name in self.bits @dataclass class ToolReturn: value: Any requested: int completed: int failed_indices: List[int] = field(default_factory=list) def enforce_boundary( call_id: str, tool: str, arg_label: Label, declared_rule: Label, ret: ToolReturn, downstream_policy_requires_total: bool, ) -> Label: # 1. Derive the observed completion status from the payload, not the type. is_partial = ret.completed < ret.requested # 2. Compute the nominal label from the declared rule. nominal = arg_label.join(declared_rule) # 3. If partial, the label MUST carry INCOMPLETE. If the declared rule # did not include it, the tool is a laundering vector. if is_partial and "INCOMPLETE" not in nominal: raise TaintLaunderingError( f"call {call_id} tool={tool}: partial completion " f"({ret.completed}/{ret.requested}, failed={ret.failed_indices}) " f"but return label {nominal.bits} lacks INCOMPLETE; " f"refusing to admit laundered provenance" ) # 4. If downstream requires total completion and we are partial, block. if is_partial and downstream_policy_requires_total: raise TaintLaunderingError( f"call {call_id} tool={tool}: downstream requires total completion, " f"observed {ret.completed}/{ret.requested}; escalate, do not commit" ) # 5. Return a fresh label (never mutate the caller's object). return nominal ```