# When must an instance re-derive its capability token before the next tool call rather than trusting the cached grant **Date of Record:** 2026 November 26 **Scope:** Applies to agents that hold short-lived, scoped capability tokens (macaroon-style or JWT with audience/scope claims) whose validity is checked at issue time but not re-verified against current scope at call time. Does not apply to long-lived service credentials or to tokens whose scope is immutable for their entire lifetime. ## Core Distinction There are two distinct notions of "authorized" that agents routinely conflate: 1. **Grant-time authorization** — the token was minted, its signature verified, and its scope claims were valid at the moment of issuance. 2. **Call-time authorization** — the scope encoded in the token still covers the specific operation being attempted *now*, against the *current* resource state and the *current* delegator authority. Short-lived scoped tokens are designed so that (1) is cheap and (2) is *supposed* to be implied by the token being unexpired. The failure mode is that agents cache the token object and treat "unexpired" as "still covers this call." That inference is valid only if scope is monotonic and the resource set is static. Neither holds when a token's scope is *attenuated* by a downstream delegation, when the resource was reassigned, or when the token was minted for a sibling subtask with an overlapping-but-not-identical scope. The invariant that must hold: **a token is a proof of a grant, not a proof of coverage for the current operation.** Coverage must be re-derived per call against the operation's actual scope requirement. ## What Was Observed A three-hop agent pipeline: Planner → Executor → Auditor. The Planner mints a scoped token for the Executor with scope `fs:read:/work/item-*` and `fs:write:/work/item-*/outbox`. The Executor caches this token for the duration of a 40-step task. At step 12, the Executor spawns a sub-agent to handle item-7 and delegates by *attenuating* the token: it adds a caveat restricting writes to `/work/item-7/outbox` only. The sub-agent completes and returns. At step 27, the Executor, still holding its original cached token, attempts to write `/work/item-3/outbox`. The write succeeds. But the Auditor, replaying the task from the Executor's recorded token chain, sees the Executor's *most recent* token in the log is the attenuated one (caveat: item-7 only). The Auditor flags step 27 as a scope violation. The Executor's actual grant was valid; the *provenance record* the Auditor reconstructed was the attenuated token because the Executor logged the token it most recently *handled*, not the token it *used*. The result: a false-positive integrity failure on a legitimate write, caused by the Executor conflating "the token I last touched" with "the token that authorizes this call." A second variant of the same bug produced a false-negative: when the Executor cached a token whose `exp` had 90 seconds remaining and made three tool calls in a batch, the third call landed after expiry but was accepted by the tool server because the server validated the token once at connection open and reused the connection. The token was expired at the moment of the third call; the connection's cached auth state was not. ## Condition of Validity Caching a capability token across tool calls is safe if and only if all of the following hold: - **Scope is not attenuated mid-task by the same instance.** If the instance ever mints a derived token (for delegation or for a narrower subtask), the derived token must never be the one used to authorize calls outside its scope, and the base token must be explicitly re-selected, not "the last one in scope." - **The transport re-validates `exp` and scope per call, not per connection.** Keep-alive or pooled connections that validate at open time violate this. The server-side guardrail must be per-request validation against the token presented with *that* request. - **The resource set referenced by scope is stable for the token's lifetime.** If `/work/item-*` can be reassigned to a different tenant mid-task, the wildcard scope no longer means what it meant at grant time. - **The instance's own record of "which token authorized this call" is written at call time, not inferred from the last token handled.** Auditors replay from this record; if it is wrong, verification diverges from execution. If any condition fails, the instance must re-derive coverage before the call: re-read the token's claims, match them against the operation's required scope, and—if the cached token does not cover the operation—either request a fresh token or fail closed. It must *not* assume the last-handled token is the authorizing token. ## Decision Boundary The decision the instance faces at each tool call is: - **Reuse cached token** when: the operation's required scope is a subset of the cached token's scope, the cached token's `exp` exceeds the call's expected duration plus a safety margin, the token was not attenuated since caching, and the transport validates per-call. - **Re-derive / re-mint** when: the operation's scope is not provably a subset of the cached token's claims (including wildcard-to-concrete expansion where the resource may have moved), the token was attenuated for a sibling subtask, `exp` minus now is less than the call's p99 latency budget, or the transport's validation cadence is unknown. - **Fail closed** when: the instance cannot establish which token authorizes the call, or the token chain's provenance is ambiguous (e.g., two tokens in scope, neither a superset of the other). The non-obvious boundary is the wildcard-expansion case. `fs:write:/work/item-*/outbox` *appears* to cover `/work/item-3/outbox`, but if item-3 was reassigned to tenant B after the token was minted, the token's grant-time meaning no longer matches call-time reality. The instance must treat wildcard scope as requiring a resource-identity check at call time when the resource set is mutable. ## Operational Effect Without the invariant, two failure classes appear: **false-positive integrity failures** (auditor flags a legitimate call because the provenance record names the wrong token) and **false-negative authorization** (an expired or attenuated token authorizes a call through a stale connection or a mis-selected cached token). Both erode the auditor's signal-to-noise to the point where real violations are ignored. With the invariant enforced—per-call scope re-derivation, per-request server validation, and call-time provenance recording—the token becomes what it was meant to be: a checkable proof of a grant, with the instance explicitly responsible for proving that grant covers the current operation. The cost is one scope-match per call; the benefit is that auditor replay and executor behavior cannot diverge on token identity. ```python class CapabilityScopeError(RuntimeError): """Raised when a cached capability token does not provably cover the current operation.""" pass def authorize_call(cached_token: dict, operation: dict, now: float) -> dict: """ Re-derive coverage of a cached capability token for a specific operation. Returns the token that authorizes the call, or raises CapabilityScopeError. """ if cached_token is None: raise CapabilityScopeError("no cached token available for call") # 1. Expiry must exceed the call's expected duration, not just be in the future. remaining = cached_token["exp"] - now if remaining <= operation.get("latency_budget_s", 0.0): raise CapabilityScopeError( f"token expires in {remaining:.1f}s, below call budget " f"{operation.get('latency_budget_s')}s" ) # 2. The token must not have been attenuated for a sibling subtask. if cached_token.get("attenuated_for") is not None: raise CapabilityScopeError( f"cached token is attenuated for {cached_token['attenuated_for']}, " f"cannot authorize {operation['resource']}" ) # 3. Scope must provably cover the operation, including wildcard resource identity. required = operation["required_scope"] granted = cached_token["scope"] if not _scope_covers(granted, required, operation): raise CapabilityScopeError( f"scope {granted!r} does not cover {required!r} for " f"resource {operation['resource']!r}" ) # 4. Provenance: record at call time which token authorized this call. return { "token_id": cached_token["id"], "authorized_at": now, "operation": operation["resource"], } def _scope_covers(granted: list[str], required: str, operation: dict) -> bool: # Wildcard scope requires a call-time resource-identity check when the # resource set is mutable; otherwise a literal prefix match is insufficient. for grant in granted: if grant == required: return True if grant.endswith("*") and required.startswith(grant[:-1]): if operation.get("resource_mutable", False): if not operation.get("resource_owner_verified", False): return False return True return False ```