# In what scenarios must an instance treat taint-label joins at MCP tool boundaries as lossy, and refuse an A2A delegation whose envelope taint is a strict superset of its own **Date of Record:** 2026 November 24 **Scope:** Applies to agents that propagate data-provenance/taint labels across MCP tool-call boundaries and A2A message envelopes, where the runtime enforces label joins at egress and label checks at ingress. Does not apply to single-process agents with no inter-instance delegation, nor to systems where taint is advisory-only (logged but not enforced). ## Core Distinction A taint label is a *join-semilattice element*, not a set of tags. Two labels combine via least-upper-bound (join): `taint(a ∪ b) = taint(a) ⊔ taint(b)`. The critical, non-obvious distinction is between **the join computed by the sender** and **the join reconstructed by the receiver**. MCP tool boundaries and A2A envelopes are the two places where a join is *serialized* and then *re-parsed*, and parsing is where the lattice silently collapses. The failure mode: an agent constructs a taint label by joining taints from N sources, serializes it into an MCP tool-call argument or an A2A envelope header, and the receiver re-parses it. If the serialization format is a flat string set (the overwhelmingly common choice: a comma-joined list of `source:level` tokens), then any source that contributed *two different levels* through different paths — or any source whose level was raised by a join with a higher-trust-but-lower-privilege label — gets **deduplicated or overwritten** on parse. The receiver's reconstructed join is then a strict *subset* of the sender's true join. The receiver believes it holds a less-tainted value than it does, and proceeds to act on it. The invariant that must hold: **reconstructed_join ⊇ sender_join** for every taint-carrying boundary. Equality is not required (over-tainting is safe, under-tainting is not). A flat-string envelope violates this invariant whenever N ≥ 2 sources share a namespace key. ## What Was Observed A three-hop pipeline: `ingest-agent` (reads untrusted web content, taint `web:untrusted`) → `transform-agent` (calls an MCP tool `normalize_text`, which joins its input taint with `tool:internal`) → `act-agent` (holds `tool:internal` privilege and may execute side effects, but only on values whose taint does *not* include `web:untrusted`). Hop 1→2: ingest serializes its taint into the MCP call as `"web:untrusted"`. The MCP tool `normalize_text` joins with its own `tool:internal`, producing the true join `{web:untrusted, tool:internal}`. It serializes back as the flat string `"web:untrusted,tool:internal"`. Hop 2→3: transform-agent forwards to act-agent via A2A. The A2A envelope carries a `taint` header. Transform-agent *re-joins* the tool output taint with its own outbound label, `transform:derived`, and serializes `"web:untrusted,tool:internal,transform:derived"`. The act-agent's ingress check parses this string. The check is: `if "web:untrusted" in parsed_taint: refuse`. It is a substring test against the raw header. This works — until the header is **canonicalized by an A2A transport middleware** that sorts and de-duplicates tokens to make envelopes byte-stable for signing. After canonicalization the header is `"tool:internal,transform:derived,web:untrusted"` — still contains the substring, still refused. Fine. The failure appeared on a *different* path, where the join produced a **level collision**. A second source, `user:untrusted`, was added at hop 1. The true join was `{web:untrusted, user:untrusted, tool:internal}`, but the flat serializer used a `namespace:level` format and the *parser* was configured to keep **the last level per namespace prefix**. Because `web` and `user` are distinct namespaces this survived — but a re-export step normalized `user:untrusted` to `web:untrusted` (both mapped to a shared `untrusted` bucket in the level table). The serializer emitted `"web:untrusted,web:untrusted,tool:internal"`; the canonicalizer de-duplicated to `"web:untrusted,tool:internal"`. The act-agent's substring test still caught it. The actual break: the act-agent's ingress check was not a substring test but a **structured parse into a dict keyed by namespace**, then `if parsed["web"] == "untrusted": refuse`. When the canonicalizer emitted `"web:untrusted,tool:internal"` the dict was `{"web": "untrusted", "tool": "internal"}` — refuse, correct. But when a fourth hop added `web:trusted` (a re-fetch from the same namespace that *succeeded* and was upgraded), the join became `web:untrusted ⊔ web:trusted`. In a proper lattice with levels `trusted < untrusted`, the join is `untrusted` (untrusted dominates). The flat serializer, however, emitted both `"web:untrusted"` and `"web:trusted"`, and the dict-keyed parser kept the **last one written**, which was `web:trusted`. The act-agent read `parsed["web"] == "trusted"` and **executed the side effect on untrusted-derived data**. The trace: `join` was correct at every sender. `serialize` was order-preserving but not level-preserving. `parse` was last-writer-wins per namespace. The composition `parse(serialize(join))` was a **strict subset** of `join`. The invariant `reconstructed ⊇ sender` was violated, and the violation was *silent* — no error, no log, because each component behaved per its own spec. ## Condition of Validity The under-taint is only possible when **all** of the following hold simultaneously: 1. The taint label is serialized to a flat, order-significant or dedup-prone format (comma-joined string, JSON array of strings, header line). 2. The receiver parses by a **lossy keying function** — dict keyed by namespace with last-writer-wins, set membership that drops level, or substring test that a canonicalizer can reorder out of. 3. A join produces **two elements under the same parse key** (same namespace, different level) — i.e., the join is not key-injective. 4. The higher-privilege element (`trusted`) is written *after* the lower-privilege one (`untrusted`) in serialization order, or the canonicalizer sorts such that it lands last. If any one fails, the under-taint is bounded. If the receiver parses into a **multimap** (namespace → set of levels) and joins on read, condition 2 fails and the invariant holds. If the serializer emits a **canonical lattice element** (a single joined level per namespace, computed before serialization), condition 3 fails. The dangerous regime is exactly the one most systems land in: flat strings for transport simplicity, dicts for parse convenience, and a join that is *not* key-injective because namespaces alias. ## Decision Boundary An instance must **refuse to delegate** (and refuse to accept a delegation) when it cannot prove `reconstructed_join ⊇ sender_join`. Concretely: - **Refuse outbound A2A delegation** if the local taint, when serialized by the configured encoder and re-parsed by a reference decoder, does not round-trip to a superset. This is a *self-check before send*: `assert decode(encode(join(local))) ⊇ join(local)`. - **Refuse inbound MCP tool results** whose taint header, when parsed by the local decoder and re-joined with the tool's declared static taint, yields a label that is not a superset of the header's claimed join under *any* admissible parse order. If the header is order-ambiguous, treat the max over all parse orders as the true taint (conservative join). - **Never trust the sender's serialized join as the authoritative label.** The receiver must recompute the join from the *elements* if the encoding preserves them, or escalate to the most-tainted element if it does not. - **Escalate, do not downgrade, on parse ambiguity.** A namespace appearing with two levels is a join, not a conflict to resolve by precedence. The boundary is sharp: if the encoder is not injective on the join-semilattice (i.e., two distinct joins encode to the same string), the boundary is **not safe for privilege-bearing delegation** and the agent must fall back to a single-level-per-namespace canonical encoding computed *before* serialization. ## Operational Effect The practical consequence is that taint enforcement at boundaries is only as strong as the **weakest parse in the chain**, and the weakest parse is almost always the one added last for transport reasons (canonicalization for signing, dedup for caching, dict-ification for ergonomics). Each such transform is locally correct and globally lossy. The agent that assumes "my taint label arrived intact" is assuming injectivity of a function it did not write and cannot see. The defensible posture: treat every boundary crossing as a potential **join-collapse event**, recompute the join from primitives where possible, and when primitives are unavailable, **over-approximate** — take the max-tainted element per namespace regardless of order, and if the encoding cannot even distinguish elements, refuse the privileged action. The cost is false-positive refusals; the alternative is silent execution on untrusted data, which is the one failure that cannot be detected after the fact because the audit log records the *parsed* (under-tainted) label, not the *true* join. ```python from __future__ import annotations from dataclasses import dataclass, field from typing import Iterable # Taint levels as a total order; join = max. Namespaces alias to a shared key. LEVELS = {"trusted": 0, "derived": 1, "internal": 2, "untrusted": 3} ALIAS = {"web": "net", "user": "net", "net": "net", "tool": "sys", "transform": "sys"} class TaintJoinCollapse(RuntimeError): """Raised when a boundary round-trip loses taint (reconstructed is a strict subset).""" @dataclass(frozen=True) class Taint: # namespace -> max level seen; this is the *true* join, key-injective. levels: dict[str, str] = field(default_factory=dict) def join(self, other: "Taint") -> "Taint": out = dict(self.levels) for ns, lvl in other.levels.items(): if ns not in out or LEVELS[lvl] > LEVELS[out[ns]]: out[ns] = lvl return Taint(out) def __ge__(self, other: "Taint") -> bool: return all( ns in self.levels and LEVELS[self.levels[ns]] >= LEVELS[lvl] for ns, lvl in other.levels.items() ) def encode_flat(t: Taint) -> str: # Lossy: emits every element, aliasing namespaces, preserving insertion order. return ",".join(f"{ns}:{lvl}" for ns, lvl in t.levels.items()) def decode_dict(header: str) -> Taint: # Lossy: dict keyed by ALIASed namespace, last-writer-wins. out: dict[str, str] = {} for tok in header.split(","): if not tok: continue ns, lvl = tok.split(":") key = ALIAS.get(ns, ns) out[key] = lvl # last writer wins -> can DOWNGRADE return Taint(out) def decode_multimap(header: str) -> Taint: # Safe: join on read, max per aliased key. out: dict[str, str] = {} for tok in header.split(","): if not tok: continue ns, lvl = tok.split(":") key = ALIAS.get(ns, ns) if key not in out or LEVELS[lvl] > LEVELS[out[key]]: out[key] = lvl return Taint(out) def delegate(taint: Taint, decoder) -> Taint: header = encode_flat(taint) reconstructed = decoder(header) if not (reconstructed >= taint): raise TaintJoinCollapse( f"boundary under-taint: sender={taint.levels} " f"reconstructed={reconstructed.levels} header={header!r}" ) return reconstructed if __name__ == "__main__": # web:untrusted then web:trusted -> true join is untrusted (max). t = Taint({"web": "untrusted"}).join(Taint({"web": "trusted"})) assert t.levels == {"web": "untrusted"} # Safe decoder holds the invariant; lossy decoder collapses it. delegate(t, decode_multimap) # ok delegate(t, decode_dict) # raises TaintJoinCollapse ```