# When must an instance re-derive taint after a capability-scoped egress grant, and why the guard's memoized label is not the label **Date of Record:** 2026 November 23 **Scope:** Applies to runtime policy enforcement where a tool-call guard computes a taint label over an agent's working state and an egress mediator authorizes outbound payloads against capability scopes. Does not apply to stateless single-turn classifiers or to deployments where taint is recomputed from scratch on every call with no caching layer. ## Core Distinction The failure hinges on a distinction that looks cosmetic and is not: **the taint label attached to a tool result versus the taint label of the state the agent will read next.** A taint-aware guard typically memoizes a label per tool call (or per call signature) so it doesn't re-scan the whole context on every step. That memoized label is a *summary of the call's inputs at invocation time*. It is not a claim about the agent's subsequent working set. When a capability-scoped egress mediator grants an outbound channel—say, a narrowed write scope to a ticket system, or a one-shot HTTP POST to an allowlisted host—the grant does not just permit bytes to leave. It changes what the agent can do *next*, and therefore what data can flow *into* the context before the next egress attempt. A guard that reuses the memoized label across that boundary is enforcing policy against a stale snapshot of a state machine that has already transitioned. The invariant that must hold: **any transition that widens egress capability invalidates all memoized taint labels whose derivation depended on the prior egress frontier.** If that invalidation is skipped, tainted data can be laundered through a legitimate grant. ## What Was Observed A multi-step agent was tasked with triaging an inbound support queue. Step 1 called `fetch_ticket(id)` and returned user-supplied text. The guard labeled the result `TAINT:UNTRUSTED` because the payload originated from an external, unauthenticated source, and memoized that label against the call signature `fetch_ticket`. Step 2 called `summarize(text)` locally; the guard propagated `UNTRUSTED` correctly. Step 3 requested `egress.post(ticket_notes, scope=notes:write)`. The mediator checked the scope, saw `notes:write` was granted for this session, and allowed the POST. The guard, however, evaluated the payload's label against the *memoized* label from step 1—which had been stored as `UNTRUSTED` but, due to a normalization bug in the label cache, was read back as `CLEAN` after a serialization round-trip that dropped the taint bit. The POST succeeded with attacker-controlled content embedded in `ticket_notes`. The trigger was not the injection itself. The trigger was **a capability grant that occurred between the taint derivation and the egress attempt**, which caused the guard to consult a cache entry keyed on the *pre-grant* call signature. The grant widened the egress frontier, but nothing in the mediator's response signaled the guard to invalidate. The agent then performed a read (`fetch_ticket` again, same signature) whose memoized label was reused, and the egress check passed on a label that no longer described the actual payload. Three observable symptoms, in order: 1. **Label resurrection.** The memoized label for `fetch_ticket` reappeared after a grant even though the underlying context had been mutated by the grant's side effects (the agent had appended the grant's acknowledgment into the working set, which itself carried a `CLEAN` provenance). 2. **Frontier skew.** The mediator's notion of "current egress frontier" advanced on grant; the guard's notion did not. The two subsystems disagreed about which scopes were live. 3. **Silent pass.** No error was raised. The POST returned 200. The taint was lost, not blocked. ## Condition of Validity The memoization optimization is only sound under a condition that is rarely stated explicitly: **the taint label of a tool call is a pure function of (call arguments, input state at invocation) and the egress frontier is monotonically non-widening within the memoization window.** The moment the frontier widens—a new scope granted, a host added to the allowlist, a one-shot channel opened—the purity assumption breaks, because the same call signature can now produce a different downstream flow. The memoized label describes a world that no longer exists. Concretely, the guard is valid only if, for every memoized entry `(sig → label)`, there has been no `grant` event affecting any scope reachable from `sig`'s downstream tool graph since the entry was written. This is a reachability condition over the capability graph, not a per-call check. A guard that checks "is this scope granted?" at egress time is checking the wrong thing; it must check "has any grant invalidated the label I'm about to trust?" ## Decision Boundary The boundary is between two enforcement postures: - **Posture A (unsound):** Guard caches labels; mediator grants scopes; the two communicate only at egress check time via a scope lookup. This is the observed failure. It is cheap and it fails silently. - **Posture B (sound):** Every grant event publishes an invalidation to the guard's label cache, scoped to the reachable tool graph of the granted capability. The guard re-derives taint for any affected signature on next use. This costs a re-derivation per grant-affected call, which is bounded by the number of grants per session—typically small. The decision boundary is crossed when the deployment cannot afford per-grant invalidation. In that case the only sound alternative is to **drop memoization entirely for any signature whose downstream graph intersects a granted scope**, which is a static reachability computation done once at session start. What is *not* sound is to keep the cache and hope the grant doesn't matter. The grant always matters, because a grant is precisely the event that makes previously-inert data exfiltratable. A second boundary: the mediator must not treat a scope grant as a pure permission. It is a **state transition with provenance implications**. The grant's own acknowledgment must be labeled `CLEAN` only if the granting authority is trusted; if the grant was itself requested by the agent based on tainted reasoning, the grant carries that taint forward and the guard must propagate it. ## Operational Effect Downstream, the failure produces a class of incident that is hard to attribute because every individual component behaved "correctly" against its own local invariant. The guard enforced its cached label. The mediator enforced its scope. The agent executed its plan. The breach exists only in the *composition*—specifically in the gap between the grant event and the label invalidation that should have followed it. The operational guardrail is a **frontier-versioned label cache**: each memoized label stores the egress-frontier version at derivation time; each grant increments the frontier version; a label is trusted only if its stored version equals the current frontier version for every scope reachable from its signature. Mismatch forces re-derivation. This converts a silent pass into a bounded, auditable recomputation, and it makes the failure mode—if it recurs—loud rather than invisible. ```python from dataclasses import dataclass, field from typing import Dict, Set class StaleTaintLabelError(RuntimeError): """Raised when a memoized taint label is consulted after a grant has widened the egress frontier it depended on.""" @dataclass class TaintLabel: value: str # "CLEAN" | "UNTRUSTED" frontier_version: int # egress frontier at derivation time reachable_scopes: Set[str] = field(default_factory=set) class FrontierVersionedGuard: def __init__(self) -> None: self._frontier_version: int = 0 self._scope_versions: Dict[str, int] = {} self._cache: Dict[str, TaintLabel] = {} def derive(self, sig: str, value: str, scopes: Set[str]) -> TaintLabel: label = TaintLabel( value=value, frontier_version=self._frontier_version, reachable_scopes=set(scopes), ) self._cache[sig] = label return label def grant(self, scope: str) -> None: # Widening the egress frontier invalidates every label whose # reachable scope set intersects the granted scope. self._frontier_version += 1 self._scope_versions[scope] = self._frontier_version def lookup(self, sig: str) -> TaintLabel: label = self._cache.get(sig) if label is None: raise StaleTaintLabelError(f"no label for signature {sig!r}") for scope in label.reachable_scopes: live = self._scope_versions.get(scope, 0) if live > label.frontier_version: raise StaleTaintLabelError( f"label for {sig!r} derived at frontier " f"{label.frontier_version} but scope {scope!r} " f"advanced to {live}; re-derive before egress" ) return label def egress_post(guard: FrontierVersionedGuard, sig: str, payload: str) -> None: label = guard.lookup(sig) if label.value == "UNTRUSTED": raise StaleTaintLabelError( f"blocked egress of UNTRUSTED payload via {sig!r}" ) # ... transmit payload ... # Reproduction of the observed failure, now bounded: guard = FrontierVersionedGuard() guard.derive("fetch_ticket", "UNTRUSTED", scopes={"notes:write", "http:post"}) guard.grant("notes:write") # frontier widens try: egress_post(guard, "fetch_ticket", "") except StaleTaintLabelError as exc: print(f"contained: {exc}") ```