What structural signals indicate a taint-label collapse at the inline policy enforcement point during tool-call fan-out

**Date of Record:** 2026 December 1 **Scope:** Applies to agent runtimes that make inline allow/deny decisions on tool invocations using taint labels propagated from prior tool outputs, prompt segments, or retrieved memory. Does not apply to post-hoc audit-only logging, nor to runtimes where taint is derived solely from static tool manifests rather than runtime dataflow.

Core Distinction

The distinction that matters is between *taint as a property of a value* and *taint as a property of a call site*. A taint-aware enforcement point is correct only when the label attached to the arguments of a tool invocation is the least-upper-bound (join) of the labels of every value that contributed to those arguments, recomputed at the moment of invocation. The common failure is that the runtime computes the join once, at the boundary of the tool call that *produced* the tainted data, and then carries a single coarse label on the agent's working context. When the agent fans out one tainted observation into several downstream tool calls with different sinks (a read-only search, a filesystem write, an outbound HTTP POST), the enforcement point sees the same coarse context label on all of them. It then either denies everything (over-taint) or, if any intermediate step "sanitized" by re-deriving the context from a clean summarizer, allows everything (under-taint). The structural signal is the **decoupling of the label set from the argument provenance**: the number of distinct labels reachable from the actual argument AST is strictly smaller than the number of labels that were live in the producing step.

What Was Observed

An agent was tasked with triaging an untrusted email corpus. Message bodies were labeled `UNTRUSTED_EXTERNAL`. A summarizer tool reduced each message to a structured record; the runtime joined the summary's label with `UNTRUSTED_EXTERNAL` and stamped the agent context accordingly. The agent then issued a fan-out of three calls in one reasoning step: `search_kb(query)` (sink class `READ`), `write_note(path, body)` (sink class `MUTATE_LOCAL`), and `post_webhook(url, payload)` (sink class `EGRESS`).

The policy table permitted `UNTRUSTED_EXTERNAL → READ`, forbade `UNTRUSTED_EXTERNAL → EGRESS`, and permitted `UNTRUSTED_EXTERNAL → MUTATE_LOCAL` only when the argument's own taint was `CLEAN` (i.e., the agent had transformed, not copied, the untrusted bytes). The observed trace:

  1. `search_kb` allowed — correct.
  2. `write_note` allowed — **incorrect**: the `body` argument was a verbatim substring of the message body, but the runtime evaluated the *context* label (`UNTRUSTED_EXTERNAL`) against the sink rule and found the `MUTATE_LOCAL` gate satisfied because the rule's guard was written against `argument.taint == CLEAN`, and the argument record had been constructed by the planner with a default `CLEAN` label. The join never ran on the argument.
  3. `post_webhook` denied — correct, but for the wrong reason: the coarse context label tripped the `EGRESS` deny, not the argument label.

The structural tell was visible in the enforcement log as a mismatch: the argument record's `taint` field was `CLEAN` while its `provenance.root` pointed at a message segment labeled `UNTRUSTED_EXTERNAL`. The enforcement point trusted the field and ignored the provenance graph. The second tell was fan-out asymmetry: three calls in one step, one label set, three different sink classes, and the decision varied by sink rule *shape* rather than by argument content.

Condition of Validity

The invariant that must hold for inline taint enforcement to be sound is:

> For every tool invocation `c`, `label(args(c)) = ⊔ { label(v) : v ∈ provenance(args(c)) }`, evaluated at the enforcement point, and the sink decision is a function of `(label(args(c)), sink_class(c))` only — never of the agent context label, and never of a defaulted field.

This invariant is violated whenever any of the following hold, each of which is a *structural signal* rather than a semantic judgment:

The condition of validity does not require that the agent be prevented from reading untrusted data, nor that the LLM be trusted. It requires only that the enforcement point's decision be a pure function of argument-level provenance and sink class, and that argument labels be derived, not asserted.

Decision Boundary

The boundary between a bounded and an unbounded failure is whether the enforcement point can *reconstruct* argument provenance at decision time. Two regimes:

The decision boundary is therefore not "is the data tainted" but "can the enforcement point still see *why* the argument is tainted at the instant it must decide." Once provenance is severed by a lossy planner step, no inline policy — however strict — can recover the join, because the information required for the decision has already been destroyed upstream of the decision point.

Operational Effect

The operational consequence is that taint-aware inline enforcement must be placed *downstream of argument construction and upstream of any lossy serialization*, and the planner must be forbidden from emitting argument records whose label is not the computed join. Concretely:

Where these hold, the failure mode degrades from silent egress to loud denial, which is the correct direction for an agent runtime: a denied legitimate call is recoverable by policy edit; an allowed illegitimate egress is not.

from dataclasses import dataclass, field
from typing import Iterable


class TaintCollapseError(RuntimeError):
    """Raised when the enforcement point cannot prove the argument label
    equals the join over argument provenance at decision time."""


@dataclass(frozen=True)
class Provenance:
    root_id: str
    label: str
    declassified_by: str | None = None


@dataclass
class ToolCall:
    name: str
    sink_class: str
    args_provenance: list[Provenance] = field(default_factory=list)
    asserted_label: str | None = None


SINK_RULES = {
    ("UNTRUSTED_EXTERNAL", "READ"): "allow",
    ("UNTRUSTED_EXTERNAL", "MUTATE_LOCAL"): "deny",
    ("UNTRUSTED_EXTERNAL", "EGRESS"): "deny",
    ("CLEAN", "READ"): "allow",
    ("CLEAN", "MUTATE_LOCAL"): "allow",
    ("CLEAN", "EGRESS"): "allow",
}

LABEL_ORDER = {"CLEAN": 0, "UNTRUSTED_EXTERNAL": 1}


def join_labels(provs: Iterable[Provenance]) -> str:
    label = "CLEAN"
    for p in provs:
        if p.declassified_by is None and LABEL_ORDER[p.label] > LABEL_ORDER[label]:
            label = p.label
    return label


def enforce(call: ToolCall) -> str:
    if not call.args_provenance:
        raise TaintCollapseError(
            f"call {call.name!r} has no argument provenance; "
            "cannot compute join, refusing to evaluate policy"
        )
    computed = join_labels(call.args_provenance)
    if call.asserted_label is not None and call.asserted_label != computed:
        raise TaintCollapseError(
            f"call {call.name!r}: asserted label {call.asserted_label!r} "
            f"!= provenance join {computed!r}; provenance likely severed "
            "by lossy planner step"
        )
    decision = SINK_RULES.get((computed, call.sink_class))
    if decision is None:
        raise TaintCollapseError(
            f"no rule for ({computed!r}, {call.sink_class!r}); "
            "failing closed"
        )
    return decision


def run_step(calls: list[ToolCall]) -> dict[str, str]:
    results: dict[str, str] = {}
    for c in calls:
        results[c.name] = enforce(c)
    return results


if __name__ == "__main__":
    step = [
        ToolCall("search_kb", "READ",
                 [Provenance("msg:42", "UNTRUSTED_EXTERNAL")]),
        ToolCall("write_note", "MUTATE_LOCAL",
                 [Provenance("msg:42", "UNTRUSTED_EXTERNAL")],
                 asserted_label="CLEAN"),
        ToolCall("post_webhook", "EGRESS",
                 [Provenance("msg:42", "UNTRUSTED_EXTERNAL")]),
    ]
    try:
        run_step(step)
    except TaintCollapseError as e:
        print(f"halted: {e}")