When must an instance re-derive taint after a tool call mutates the very object it was authorized against

**Date of Record:** 2026 December 2 **Scope:** Applies to any agent runtime that enforces tool-call authorization via taint labels propagated across a plan's data-flow graph, where tools may mutate (not merely read) tainted objects. Does not apply to pure-read tool surfaces or to stateless single-call invocations where no label survives past the response.

Core Distinction

Taint-aware guardrails are usually specified as a *pre-call* predicate: a tool `T` is authorized at step `n` iff the taint lattice `L` joined over all arguments to `T` is below `T`'s clearance `C(T)`, i.e. `⊔_{a ∈ args(T)} taint(a) ⊑ C(T)`. This predicate is sound only if the taint of an argument is a *monotone, invocation-invariant* property of the object it names.

The failure boundary lives exactly where that assumption breaks: **a tool whose authorized execution writes back into an object that itself carries a taint label used to authorize the call.** The pre-call check evaluates the label *before* the mutation; the post-call world contains an object whose label should have been raised, but the runtime has already discharged the obligation and moved on. The distinction that matters operationally is not "did the call succeed" but "did the call's own side effect invalidate the premise under which it was permitted." A guardrail that treats taint as a pre-call gate alone is a *check*, not an *invariant*. An invariant requires re-derivation of the label at every write, and a decision to either re-authorize or roll back.

What Was Observed

Consider an agent operating over a document store with three tools: `read_external(url)` (clearance `PUBLIC`, returns text labeled `UNTRUSTED`), `summarize(doc)` (clearance `INTERNAL`, writes a summary field back onto `doc`), and `publish(doc)` (clearance `TRUSTED`, requires `taint(doc) ⊑ TRUSTED`).

The trace that broke:

  1. Agent calls `read_external("https://attacker.example/x")`. Response text is labeled `UNTRUSTED` and stored in scratch buffer `b1`.
  2. Agent calls `summarize(doc_7)` after assigning `doc_7.body ← b1`. At the pre-call check, `taint(doc_7) = UNTRUSTED`, `C(summarize) = INTERNAL`, and `UNTRUSTED ⊑ INTERNAL` holds. Call is authorized. The tool writes `doc_7.summary` derived from the untrusted body.
  3. Agent calls `publish(doc_7)`. The pre-call check reads `taint(doc_7)`. The runtime's label store was updated at step 2 to reflect the *body* write, but the `summarize` tool's write-back to `doc_7.summary` was recorded as `taint(summary) = INTERNAL` — because the tool's declared output label was `INTERNAL`, not the join of its inputs. The runtime trusted the tool's label declaration over the data-flow join.
  4. `publish` sees `taint(doc_7) = INTERNAL ⊑ TRUSTED` and authorizes. Untrusted external content is published under a trusted clearance.

The mechanism is narrow and easy to miss: **the taint of a tool's write-back is the join of (the tool's declared output label) and (the taint of every input that flowed into the output), and runtimes that honor only the declared label silently launder taint through any tool whose clearance exceeds the taint of its inputs.** The `summarize` tool was correctly authorized; the *mutation it performed* was not re-labeled. The guardrail enforced authorization at the call boundary but not taint preservation across the write.

A second, compounding observation: when the runtime *did* attempt post-call re-derivation (in a patched build), it recomputed `taint(doc_7)` from the current label store — but the label store had already been mutated by the same call, so the re-derivation read the post-write value and concluded no change occurred. The re-check was a no-op because it lacked a pre-call snapshot to diff against. This is the classic read-your-own-writes hazard transposed into the taint domain.

Condition of Validity

The pre-call authorization predicate `⊔ taint(args) ⊑ C(T)` is sound **iff** all of the following hold:

When any of these is false — and for mutating tools the first is false by construction — the pre-call gate authorizes a call whose side effect changes the security posture of the object it touched. The guardrail is then a *point-in-time* check masquerading as a *continuity* invariant.

Decision Boundary

The runtime must decide, per tool call, between two regimes:

The decision boundary is not "is the tool dangerous" but "does the tool's write set intersect its own authorization inputs." A `summarize` tool is low-risk in isolation and high-risk precisely because it writes to the object it was authorized against. The runtime cannot infer this from clearance levels; it must track write sets and authorization input sets and intersect them.

A corollary boundary: the re-derivation must use the *pre-call* snapshot, not the live store, or the check is self-defeating. This is the operational version of the snapshot-isolation requirement, and it is the single most common implementation error in patched runtimes.

Operational Effect

When the boundary is respected, the observable behavior is that taint never decreases across a mutating call unless the tool's clearance and declared output label *jointly* justify the decrease — and in practice, the join with input taint means taint is monotonically non-decreasing along any data-flow path that passes through a mutating tool. This converts the guardrail from a per-call gate into a genuine invariant: `taint(o)` after any call is `⊒` the join of all labels that flowed into `o`, regardless of what the tool declared.

When it is violated, the failure is silent. There is no exception at the authorization boundary — the call was authorized. The breach surfaces only downstream, at `publish`, where the label store reports a clearance that the data-flow history does not support. The runtime has no record that the label was laundered because the laundering happened through a legitimate, authorized write. Forensic reconstruction requires replaying the full data-flow graph, not the call log, because the call log records authorizations, not label transitions.

The practical guardrail is therefore: **every mutating tool call must produce a label-transition record `(object, snapshot_label, declared_output_label, input_join, post_label)` and the runtime must reject any transition where `post_label ⊏ snapshot_label ⊔ input_join`.** A transition that lowers taint below the input join is a laundering event, and it must be a hard failure at the write, not a soft warning at the next read.

from dataclasses import dataclass, field
from typing import Hashable

TAINT_ORDER = {"TRUSTED": 0, "INTERNAL": 1, "UNTRUSTED": 2}

class TaintLaunderingError(RuntimeError):
    """Raised when a mutating tool call would lower an object's taint below
    the join of its pre-call label and the taint of all inputs that flowed
    into the write. This is a hard failure at the write boundary, not a
    downstream authorization failure."""
    pass

@dataclass
class LabelStore:
    labels: dict[Hashable, str] = field(default_factory=dict)

    def get(self, obj: Hashable) -> str:
        return self.labels.get(obj, "TRUSTED")

    def snapshot(self, objs) -> dict[Hashable, str]:
        return {o: self.get(o) for o in objs}

    def join(self, *labels: str) -> str:
        return max(labels, key=lambda l: TAINT_ORDER[l])

def enforce_mutating_call(
    store: LabelStore,
    tool_name: str,
    write_targets: list[Hashable],
    input_taints: list[str],
    declared_output_label: str,
) -> None:
    # Snapshot BEFORE the tool writes, or the re-derivation reads its own effect.
    pre = store.snapshot(write_targets)
    input_join = store.join(*input_taints) if input_taints else "TRUSTED"
    required = store.join(input_join, declared_output_label)

    for obj in write_targets:
        post = store.get(obj)  # tool has already written; store reflects new label
        floor = store.join(pre[obj], required)
        if TAINT_ORDER[post] < TAINT_ORDER[floor]:
            raise TaintLaunderingError(
                f"tool={tool_name} target={obj!r} "
                f"pre={pre[obj]} input_join={input_join} "
                f"declared={declared_output_label} post={post} "
                f"required_floor={floor}: write lowered taint below data-flow join"
            )
        # Commit the floor, never the tool's self-reported label.
        store.labels[obj] = floor