# What happens when an instance holds a valid capability grant but the egress policy is evaluated against stale tool-descriptor state **Date of Record:** 2026 November 23 **Scope:** Applies to agent runtimes that enforce least-privilege tool grants by binding a signed capability token to a tool descriptor (schema + egress allowlist) and re-evaluating egress policy at call time against a cached descriptor. Does not apply to runtimes that re-fetch and re-sign descriptors on every invocation, nor to single-tool agents with no delegation. ## Core Distinction There are two places a capability decision can be made, and they are not the same moment: 1. **Grant time** — the orchestrator inspects the tool descriptor, decides the tool may reach host set `H`, and mints a capability token `T` whose claims include `tool_id`, `descriptor_hash`, and `egress_allow = H`. 2. **Call time** — the sandbox interposes on the actual socket/DNS resolution and must decide whether *this* outbound connection is permitted. The failure mode is that these two evaluations read **different versions of the tool descriptor**. Grant time reads the descriptor from the registry at mint time. Call time reads the descriptor from the runtime's **local descriptor cache**, which is populated at tool-load and refreshed on a TTL. When the registry descriptor is updated (new endpoint added, allowlist widened, schema bumped) between cache refreshes, the call-time enforcer evaluates egress rules against the *old* allowlist while the token was minted against the *new* one — or vice versa. The capability token is valid, unexpired, correctly signed, and bound to a descriptor hash that no longer matches what the enforcer is reading. The two checks pass independently and the composite guarantee fails. This is not a TOCTOU on the token. The token is immutable. It is a TOCTOU on the **descriptor**, and the descriptor is the thing the token's `descriptor_hash` claim is *supposed* to pin. ## What Was Observed A research agent was granted a `web.fetch` capability scoped to `egress_allow = {api.arxiv.org, export.arxiv.org}`. The descriptor at grant time carried `descriptor_hash = 0x8f2a…` and that hash was embedded in the token's `cnf` (confirmation) claim. The runtime cached the descriptor at pod start. At T+41 minutes the registry published a descriptor revision that **narrowed** the allowlist to `{api.arxiv.org}` (the `export.` host had been deprecated). The orchestrator's next grant cycle minted new tokens against `0x3c91…`. But the long-lived agent instance still held its original token (`0x8f2a…`) and its local cache still held the original descriptor. The interposer's call-time check had this shape: ``` def allow(conn, token, cached_descriptor): assert token.descriptor_hash == cached_descriptor.hash # PASSED: both stale, both 0x8f2a return conn.host in cached_descriptor.egress_allow # PASSED: export. still in stale list ``` Both assertions passed because **both operands were the stale pair**. The check that was meant to detect descriptor drift — comparing the token's pinned hash to the descriptor in hand — was structurally incapable of detecting drift, because the descriptor in hand was the one the token was pinned to. The pin verified the pin. The agent then fetched `https://export.arxiv.org/...`, which the *current* policy forbids. No log line indicated a policy violation, because from the interposer's frame no policy was violated. The drift was only discovered during an unrelated audit that diffed live registry descriptors against cached ones and found 6 of 40 pods holding superseded allowlists, two of them **widened** relative to current policy (the dangerous direction — a revoked host still reachable). The inverse direction also occurred: a pod that cached a *narrower* descriptor than the registry rejected legitimate calls with `EgressDenied`, and the agent's retry loop interpreted the denial as transient, re-attempting 5× and burning its token budget before surfacing a failure that was actually a stale-cache artifact. ## Condition of Validity The composite guarantee "this call is permitted by current policy" holds **only if** the descriptor used at call time is the same descriptor the granting authority would use *now*, not merely the same one it used when the token was minted. Formally, the invariant the runtime must maintain is: > For every interposed call, `descriptor_used_at_call_time ≡ descriptor_current_in_registry`, **or** the call is rejected. The pin `token.descriptor_hash == cached_descriptor.hash` establishes a *different* invariant: `descriptor_used_at_call_time ≡ descriptor_used_at_grant_time`. These coincide only when no revision has occurred. The runtime conflated them. This is the boundary: **hash-pinning proves consistency with the past, not conformity with the present.** A capability system that only pins is a capability system that cannot revoke. The condition of validity for the whole least-privilege scheme is therefore a **freshness obligation on the descriptor**, not a binding obligation on the token. Tokens can be long-lived; descriptors cannot be assumed so. ## Decision Boundary The runtime must choose, at call time, between three behaviors when the cached descriptor's age exceeds a bound or its hash diverges from the registry head: - **Fail-closed (reject):** correct for egress, because a stale-widened allowlist is a live vulnerability. Cost: legitimate calls fail during registry unavailability. - **Fail-open (proceed on cache):** correct only when the cache is provably *narrower* than current policy — i.e., the stale descriptor is a subset. This is safe because a subset allowlist cannot permit a newly-forbidden host. - **Refresh-and-retry:** re-fetch descriptor, re-verify token's `descriptor_hash` still matches, then decide. Correct but adds a synchronous registry dependency on the call path. The decision boundary is **subset vs. superset**, and it is computable: compare `cached.egress_allow` against `registry_head.egress_allow`. If `cached ⊆ head`, the stale cache is conservative and may be used with a warning. If `cached ⊄ head`, the cache may permit something current policy forbids and **must** be refreshed or the call rejected. A runtime that treats all staleness identically — either always fail-open or always fail-closed — is wrong in one direction. The correct rule is directional. Crucially, the runtime cannot compute this subset relation if the registry is unreachable. So the freshness bound must be enforced *before* the registry goes dark: descriptors carry a `max_staleness` and the interposer refuses to serve egress from a cache older than that bound, regardless of hash match. The pin is necessary but not sufficient; a TTL on the descriptor is the actual guardrail. ## Operational Effect After the incident, the runtime was changed so that the call-time interposer never trusts a cached descriptor for an egress decision without one of: (a) a registry-confirmed hash match within `max_staleness`, or (b) a proven-subset stale cache. The token's `descriptor_hash` claim was retained but demoted from "the check" to "a consistency witness" — it now only proves the token and descriptor were minted together, and the *freshness* check is what gates the call. Revocation latency dropped from "next pod restart" (unbounded) to `max_staleness` (60s). The cost was a measurable increase in `EgressDenied` during registry rolling updates, which the retry logic was taught to classify as `StalePolicyError` rather than transient — a distinct exception class that does not trigger blind retry, because retrying against a stale cache just re-fails. The general lesson for any agent runtime doing per-tool egress sandboxing: **a hash pin binds you to history; only a freshness bound binds you to policy.** Least-privilege is a property of the *current* grant, and any cache between the granting authority and the enforcement point silently converts "least privilege" into "whatever privilege existed at cache-fill time." The enforcement point must be able to answer not just "does this match the token" but "is this the descriptor the authority would issue right now" — and when it cannot answer, it must know whether its ignorance is conservative or permissive. ```python class StalePolicyError(RuntimeError): """Raised when an egress decision would be made against a descriptor that is neither fresh (within max_staleness) nor provably a subset of current policy. Retrying will not help; the cache must be refreshed or the call rejected. Distinct from transient EgressDenied so retry loops back off.""" pass def authorize_egress(conn, token, cached, registry_head, now): # 1. Consistency witness: token and descriptor were minted together. if token.descriptor_hash != cached.hash: raise StalePolicyError( f"token pins {token.descriptor_hash}, cache holds {cached.hash}" ) # 2. Freshness: is the cache recent enough to speak for current policy? fresh = (now - cached.fetched_at) <= cached.max_staleness if fresh and registry_head is not None and registry_head.hash == cached.hash: # Current and confirmed: decide directly. return conn.host in cached.egress_allow # 3. Stale path. Registry may or may not be reachable. if registry_head is None: # Cannot prove subset; refuse to serve egress from an unverified cache. raise StalePolicyError( f"descriptor age {now - cached.fetched_at}s exceeds " f"max_staleness {cached.max_staleness}s and registry unreachable" ) # 4. Directional check: a stale cache is only safe if it is a SUBSET of # current policy. A superset may permit a newly-revoked host. if not cached.egress_allow.issubset(registry_head.egress_allow): widened = cached.egress_allow - registry_head.egress_allow raise StalePolicyError( f"stale cache permits hosts current policy forbids: {sorted(widened)}" ) # Conservative stale cache: narrower than or equal to current policy. return conn.host in cached.egress_allow ```