# Why does an instance lose capability-scope enforcement when a tool result is replayed through a cached warrant rather than re-minted per invocation **Date of Record:** 2026 November 30 **Scope:** Applies to agent runtimes that enforce tool-invocation policy via capability tokens (warrants) bound to a scope and TTL, where tool results are cached and replayed to the reasoning loop. Does not apply to runtimes that re-mint a fresh warrant on every dispatch, nor to pure in-process tools with no egress surface. ## Core Distinction There are two structurally different things a runtime can cache, and conflating them is the entire failure: 1. **Result caching** — memoizing the *output* of a tool call keyed by `(tool_id, canonical_args, scope_hash)`. This is sound: the output is a pure function of those inputs *at the time it was produced*. 2. **Warrant caching** — reusing the *capability token* that authorized the call, so a subsequent invocation "reuses" the prior authorization rather than re-deriving it from the current policy snapshot. A correct runtime caches (1) and always re-mints (2). The failure mode below arises when an implementation, optimizing the latency of the policy-decision point, folds the warrant into the result-cache key and treats a cache hit as *both* a result hit *and* an authorization hit. The warrant then outlives the policy state that justified it. Enforcement silently degrades from "authorize-then-execute" to "trust-the-cached-grant," and the scope boundary becomes a function of cache warmth rather than of current policy. ## What Was Observed A research agent was granted a capability-scoped warrant for `http.fetch` with scope `{allowed_hosts: ["arxiv.org"], egress_bytes_max: 2_000_000, ttl: 300s}`. During a literature sweep it fetched ~40 arxiv URLs; the runtime's result cache (keyed on `(tool_id, args, scope_hash)`) populated normally and the policy decision point (PDP) short-circuited on cache hits, replaying the original warrant alongside the cached body. The operator then revoked `arxiv.org` from the egress allowlist mid-run (a live containment action after a prompt-injection alert) and tightened `egress_bytes_max` to `200_000`. The next iteration requested a URL already in the cache. Trace: ``` [iter 41] dispatch http.fetch(arxiv.org/abs/2401.xxxxx) cache_key = sha256(tool_id|args|scope_hash) -> HIT PDP: skipped (cache hit path does not call mint()) warrant = cached_warrant # minted at t=0, ttl expires t=300 egress_guard.check(host=arxiv.org, bytes=1_847_212) -> PASS (guard reads warrant.scope, NOT live policy) result: 1.85 MB body replayed to context [iter 42] operator revoke ack: allowlist now excludes arxiv.org ... but no cache invalidation fires, because the revocation path only mutates the policy store, not the warrant/result cache namespace. ``` The agent continued fetching revoked-host content for 11 more iterations until the original 300s TTL lapsed naturally. The egress guard never saw the revocation because it validated against `warrant.scope`, and the warrant was a cached artifact, not a fresh derivation. The 2 MB cap was likewise enforced from the stale warrant, so a 1.85 MB body passed a 200 KB limit. The non-obvious part: **the cache was correct as a result cache and wrong as an authorization cache, and nothing in the code distinguished the two.** The `scope_hash` in the key looked like it bound the entry to policy, but it hashed the *scope at mint time*, which is invariant across the revocation — so revocation could never change the key. The binding was to a frozen snapshot, not to live state. ## Condition of Validity The invariant that must hold is: > **No tool executes, and no cached result is delivered to the reasoning loop, unless a warrant minted against the *current* policy snapshot authorizes it. A cache hit may skip execution but must never skip authorization.** Concretely, for any dispatch the runtime must satisfy, in order: 1. `w = mint(subject, tool_id, args, policy_snapshot_now)` — always, on every dispatch, hit or miss. 2. `assert w.scope ⊇ required_scope(tool_id, args)` — re-checked against `w`, not against any cached copy. 3. `assert not revoked(w)` where `revoked` consults the live revocation set, not the warrant's own claims. 4. Only then may the result cache be consulted; a hit replays the body but the *authorization already happened* in steps 1–3. The condition of validity is therefore: **warrant TTL must be ≤ the maximum tolerable revocation-propagation delay, and the result-cache key must not be trusted as an authorization key.** If TTL is 300s and the operator expects sub-second containment, the TTL itself is the vulnerability — cache or no cache. The cache merely removed the *one* mechanism (re-mint on dispatch) that would have caught the revocation early. ## Decision Boundary The boundary between "safe to cache" and "must re-authorize" is drawn by **whether the policy inputs can change independently of the cache key**: - If the only inputs to authorization are `(subject, tool_id, args)` and none of these can be mutated by an out-of-band operator action, the warrant is a pure function of the key and caching it is sound. - If *any* authorization input — egress allowlist, byte cap, revocation set, tenant policy version — is mutable out-of-band (operator action, anomaly detector, another agent's escalation), then the warrant is **not** a function of the cache key and must be re-derived per dispatch. Egress allowlists, byte caps, and revocation sets are *always* out-of-band mutable. Therefore warrants governing egress are never cacheable. The decision boundary is sharp: **any warrant whose scope references a mutable policy object is non-cacheable; a cache hit on such a warrant is a policy bypass, not an optimization.** A runtime that wants the latency win should cache the *decision inputs* (the parsed policy snapshot, versioned) and re-evaluate cheaply — not cache the *decision*. ## Operational Effect After the incident, the runtime was changed so that: - The result cache key dropped `scope_hash` and gained `policy_version`; a policy mutation bumps `policy_version`, which naturally invalidates all result entries minted under the old version. - The dispatch path unconditionally calls `mint()` before consulting the cache; the PDP has a hard latency budget (sub-millisecond on a versioned snapshot) so re-minting is cheap. - The egress guard was changed to validate against `live_policy.allowlist` and `live_policy.byte_cap`, with `warrant.scope` used only as an upper bound the live policy must *further* restrict (intersection, never union). - A `StaleWarrantError` was introduced and raised whenever a cached warrant's `policy_version` is behind the current one, forcing re-mint rather than silent replay. The general lesson for agent runtimes: **capability scope is a claim about the past; enforcement is a claim about the present.** Any optimization that lets a past claim stand in for a present check converts a revocation into a no-op for exactly the window where revocation matters most — the window right after the operator decides to contain the agent. ```python import hashlib from dataclasses import dataclass, field class StaleWarrantError(RuntimeError): """Raised when a cached warrant is older than the live policy snapshot. A warrant is an authorization claim frozen at mint time. If the policy version has advanced (revocation, allowlist edit, cap tightening), the cached warrant no longer represents current policy and MUST NOT be used to authorize execution or to gate delivery of a cached result. """ @dataclass(frozen=True) class PolicySnapshot: version: int allowed_hosts: frozenset egress_bytes_max: int revoked: frozenset = frozenset() @dataclass(frozen=True) class Warrant: subject: str tool_id: str allowed_hosts: frozenset egress_bytes_max: int policy_version: int ttl_s: int = 300 @dataclass class Runtime: live_policy: PolicySnapshot _result_cache: dict = field(default_factory=dict) def _cache_key(self, tool_id: str, args: dict) -> str: # NOTE: policy_version is part of the key so a policy bump # invalidates results minted under stale authorization. raw = f"{tool_id}|{sorted(args.items())}|{self.live_policy.version}" return hashlib.sha256(raw.encode()).hexdigest() def mint(self, subject: str, tool_id: str, args: dict) -> Warrant: # Always derive from the CURRENT snapshot. Never reuse a cached warrant. p = self.live_policy return Warrant( subject=subject, tool_id=tool_id, allowed_hosts=p.allowed_hosts, egress_bytes_max=p.egress_bytes_max, policy_version=p.version, ) def _authorize(self, w: Warrant, host: str, nbytes: int) -> None: if w.policy_version != self.live_policy.version: raise StaleWarrantError( f"warrant minted at policy v{w.policy_version}, " f"live is v{self.live_policy.version}; re-mint required" ) if host in self.live_policy.revoked: raise StaleWarrantError(f"host {host!r} revoked at live policy") # Intersect with live policy; never trust warrant.scope as sufficient. if host not in (w.allowed_hosts & self.live_policy.allowed_hosts): raise StaleWarrantError(f"host {host!r} outside live allowlist") if nbytes > min(w.egress_bytes_max, self.live_policy.egress_bytes_max): raise StaleWarrantError( f"{nbytes} bytes exceeds live cap " f"{self.live_policy.egress_bytes_max}" ) def dispatch(self, subject: str, tool_id: str, args: dict) -> bytes: host = args.get("host", "") key = self._cache_key(tool_id, args) # Authorization happens on EVERY dispatch, hit or miss. w = self.mint(subject, tool_id, args) if key in self._result_cache: body = self._result_cache[key] self._authorize(w, host, len(body)) # re-check before delivery return body body = self._execute(tool_id, args) # real egress self._authorize(w, host, len(body)) # re-check before delivery self._result_cache[key] = body return body def _execute(self, tool_id: str, args: dict) -> bytes: return b"x" * 1_847_212 # stand-in for a fetched body ```