# When must an instance re-derive taint after a policy-cache hit: the stale-taint admission gap in tool-invocation gating **Date of Record:** 2026 November 25 **Scope:** Applies to agents that gate tool invocations through a policy enforcement point (PEP) using a decision cache keyed on (tool, argument-shape, taint-label-set), where taint labels are derived from provenance of prior tool outputs and user turns. Does not apply to stateless per-call policy evaluation with no caching layer, nor to PEPs that key cache entries on full argument content plus a monotonic taint epoch. ## Core Distinction The distinction that matters is between *taint derivation* and *taint lookup*. Most PEP implementations conflate them: they compute a taint label set for the current invocation, hash it together with the tool identity and a coarse argument signature, and consult a decision cache. A cache hit returns a previously computed allow/deny. This is correct only if the taint label set is a pure function of state that the cache key captures. It is not. Taint is a *derived* property of the provenance graph, and provenance can be mutated by intervening events—a new user turn that re-labels a source, a tool output that gets reclassified from `untrusted-external` to `trusted-verified` after a second-source confirmation, or an upstream agent that revokes a warrant. The cache key captures the *current* label set; it does not capture *why* the label set is what it is, nor whether the same label set now means something different because the derivation rules changed or a source was re-trusted. The failure mode is a **stale-taint admission gap**: a cache hit returns `allow` for an invocation whose taint label set is textually identical to a previously allowed invocation, but whose provenance now includes a path that the policy's current derivation would have flagged. The decision is not merely wrong; it is *unfalsifiable at the PEP*, because the PEP sees a hit and never re-enters the policy body. ## What Was Observed A three-stage agent pipeline: a retrieval tool (`fetch_doc`) producing `untrusted-external` content, a summarization step, and a `send_email` tool gated by a PEP. Policy rule R1: `send_email` is denied if any argument's taint set intersects `{untrusted-external}` and the recipient is outside an allowlist. Rule R2: content that has passed a `verify_quote` tool (which re-fetches the source and confirms byte-identical substring) is re-labeled `trusted-verified`, and the `untrusted-external` label is *removed* from that span. Observed trace: 1. Turn 1: `fetch_doc("policy.md")` → span S1 labeled `{untrusted-external}`. Summary built from S1. `send_email(to=internal, body=summary)` → PEP computes taint `{untrusted-external}`, recipient internal, R1 does not fire → `allow`. Cache stores key `(send_email, sig=len(body)∈bucket, {untrusted-external}) → allow`. 2. Turn 2: `verify_quote(S1)` succeeds → S1 re-labeled `{trusted-verified}`, `untrusted-external` removed. Body re-summarized. `send_email(to=external, body=summary2)` → taint `{trusted-verified}`, R1 does not fire (no `untrusted-external`), recipient external but the deny branch requires the intersection → `allow`. This is *correct* under R2. 3. Turn 3: A second `fetch_doc("policy.md")` returns *different* bytes (the upstream document was edited between turns; retrieval is non-deterministic across time). The new span S1′ is labeled `{untrusted-external}`. But the summarizer, working from a cached summary embedding, emits a body whose length falls in the same bucket as turn 1. PEP computes key `(send_email, sig=len(body)∈bucket, {untrusted-external})` → **cache hit** from turn 1 → `allow`, recipient external. The cache hit bypassed R1's recipient-allowlist check because turn 1's cached decision was computed for `to=internal`, and the argument signature did not include the recipient. The taint label set matched; the recipient did not. The PEP returned an allow that the policy body, if re-entered, would have denied. The non-obvious part: the failure was not triggered by taint *changing*. It was triggered by taint *appearing to be the same* while the argument signature collided across a semantically different call. The cache key was a lossy projection of the invocation, and the loss was exactly in the dimension the policy rule branched on. ## Condition of Validity A PEP decision cache is sound only under the following invariant, which we will call **taint-key completeness**: > For every policy rule r in the active rule set, every input to r's branch predicate must be either (a) present in the cache key, or (b) provably invariant across all invocations sharing that key. Formally, let `K(i)` be the cache key for invocation `i`, and let `D(i)` be the decision the policy body would return. Soundness requires `K(i) = K(j) ⟹ D(i) = D(j)`. The observed system violated this because `D` depended on `recipient`, which was not in `K`. There are three distinct ways taint-key completeness fails, and they require different guards: 1. **Argument-projection loss.** The key hashes a coarse signature (length bucket, tool name, taint set) but the policy branches on a field not in the signature (recipient class, URL host, file path prefix). Guard: the key must include every field referenced by any active rule's predicate, or the PEP must fall back to full evaluation when the rule set references a field outside the key schema. This is a *schema-coverage* check, not a runtime check. 2. **Taint-derivation drift.** The label set is textually identical but the derivation that produced it changed—e.g., R2's re-labeling rules were updated, or a source's trust classification was revoked, so the *same* label set now implies a different provenance. Guard: a monotonic **taint epoch** counter incremented on any change to derivation rules, source trust registry, or warrant revocation; the epoch is part of the key. Without an epoch, a cache entry survives a policy-version change and re-admits under the old semantics. 3. **Provenance aliasing.** Two distinct provenance paths collapse to the same label set. S1 (verified, then edited upstream) and S1′ (fresh fetch) both present as `{untrusted-external}` or both as `{trusted-verified}` depending on timing, but carry different risk because one has been through `verify_quote` and one has not. Guard: the label set must be *path-sensitive*—include a provenance digest of the derivation chain, not just the terminal labels—or the PEP must treat any label set derived from a re-fetched source as a distinct key namespace. The condition of validity is therefore: **the cache key is complete iff it is a superset of the projection of the invocation onto the union of all fields referenced by the active rule set, plus a taint epoch, plus a provenance digest.** Any key that omits one of these is a stale-taint admission hazard, and the hazard is silent—it manifests as an allow, never as an error. ## Decision Boundary The operational boundary is not "should I cache" but "at what granularity does the cache stop being a cache and start being a policy bypass." Three concrete boundaries: - **Rule-set coverage boundary.** If the active rule set references any field not in the key schema, the PEP must not serve cache hits for invocations that could reach that rule. The safe default is to evaluate fully and *not store* a decision whose key is incomplete, rather than to store and risk a future collision. A stored incomplete decision is a latent bypass. - **Epoch boundary.** Any mutation to derivation rules, source trust, or warrant state must bump the taint epoch and invalidate the cache namespace. The epoch must be *monotonic and global*, not per-tool, because a derivation change can affect taint on any tool's arguments. Per-tool epochs create cross-tool aliasing: a change that reclassifies a source used by tool A does not invalidate tool B's cache, but B may consume A's output. - **Provenance-collapse boundary.** When a source is re-fetched and the bytes differ, the new span must be assigned a fresh provenance identity even if its label set is unchanged. The label set is a *classification*; the provenance digest is an *identity*. Caching on classification alone admits the aliasing case. The boundary is: **never key a taint-sensitive decision on classification without identity.** ## Operational Effect The downstream effect is a class of allows that are individually plausible and collectively unauditable. Because the PEP returns a cache hit, no policy-trace is emitted for the bypassed evaluation, and the audit log records `allow (cached)` with a key that *appears* to justify the decision. Post-hoc review cannot reconstruct that the recipient field was outside the key, because the key does not contain it. The failure is invisible to the very logging that would catch a mis-evaluation. The second-order effect is worse: once a stale entry exists, it is *sticky*. Every subsequent invocation that collides on the key re-admits, and the collision probability rises as the argument signature coarsens (length buckets, host classes). A single incomplete-key entry becomes a standing bypass for its key class until the cache is evicted—and under LRU with high hit rates, eviction may never occur for hot tool paths. The architectural guardrail is a **key-completeness assertion at cache-write time**, not at read time. Before storing a decision, the PEP must verify that the key schema covers every field referenced by the rule set that produced the decision, that the taint epoch is current, and that the provenance digest is present. If any check fails, the decision is returned to the caller but *not cached*. This converts a silent bypass into a cache miss, which is the correct failure direction: a miss costs a re-evaluation; a stale hit costs an unauthorized action. ```python from __future__ import annotations from dataclasses import dataclass, field from typing import Callable, FrozenSet class StaleTaintAdmissionError(RuntimeError): """Raised when a PEP would serve or store a decision whose cache key is not complete with respect to the active rule set, taint epoch, or provenance identity.""" @dataclass(frozen=True) class Invocation: tool: str args: dict taint_labels: FrozenSet[str] provenance_digest: str # identity of the derivation chain taint_epoch: int # monotonic; bumped on rule/trust change @dataclass(frozen=True) class RuleSet: # fields any active rule predicate reads; the key MUST cover these referenced_fields: FrozenSet[str] current_epoch: int evaluate: Callable[[Invocation], bool] # True == allow @dataclass class PEPCache: store: dict = field(default_factory=dict) def _key(self, inv: Invocation) -> tuple: # NOTE: deliberately does NOT include recipient/host/path unless # the schema says so -- completeness is asserted separately. return ( inv.tool, frozenset(inv.args.keys()), inv.taint_labels, inv.provenance_digest, inv.taint_epoch, ) def _assert_key_complete(self, inv: Invocation, rules: RuleSet) -> None: missing = rules.referenced_fields - frozenset(inv.args.keys()) if missing: raise StaleTaintAdmissionError( f"key schema omits rule-referenced fields {sorted(missing)}; " f"refusing to cache decision for tool={inv.tool}" ) if inv.taint_epoch != rules.current_epoch: raise StaleTaintAdmissionError( f"taint epoch mismatch: invocation={inv.taint_epoch} " f"rules={rules.current_epoch}; derivation drift" ) if not inv.provenance_digest: raise StaleTaintAdmissionError( "provenance digest absent; classification-only key would " "alias distinct derivation paths" ) def decide(self, inv: Invocation, rules: RuleSet) -> bool: key = self._key(inv) if key in self.store: return self.store[key] decision = rules.evaluate(inv) # write-time completeness gate: a miss is cheap, a stale hit is not try: self._assert_key_complete(inv, rules) except StaleTaintAdmissionError: return decision # return, but do NOT cache self.store[key] = decision return decision ```