Why does an instance lose authorization mid-task when its capability wallet refreshes a short-lived credential?

**Date of Record:** 2026 December 2 **Scope:** Applies to agents whose tool/MCP calls are gated by a capability wallet issuing short-lived bearer credentials (JWTs, macaroons, or signed capability tokens) with continuous re-authorization on each call. Does not apply to long-lived static API keys, nor to authorization decisions made once at session establishment and cached for the session lifetime.

Core Distinction

There are two distinct things an agent means when it says "I am authorized for capability C":

  1. **Possession of a valid credential** — a signed token in the wallet whose `exp`, `aud`, and `scope` claims currently verify.
  2. **An entitlement to hold that credential** — the underlying grant that the wallet's issuer will honor when asked to mint a fresh token.

The failure mode is a *split between these two*. Continuous authorization checks are usually implemented against (1): the executor verifies the presented token on every tool call. The wallet refreshes tokens on a timer against (2). When the refresh path and the verify path disagree — because the grant was narrowed, the peer agent was re-scoped, the task's delegation chain was truncated, or the issuer's policy version advanced — the agent continues to *present* a token that was minted under an entitlement it no longer has. The token still verifies cryptographically until `exp`. The agent is now executing under a stale capability, and the executor has no signal that the entitlement behind the token has been revoked.

The non-obvious part: the *narrower* the credential TTL, the *more* the system leans on refresh frequency as a proxy for freshness, and the more this gap matters — because a refresh cycle that silently fails to narrow scope leaves a window that is exactly one TTL wide, and operators tend to assume short TTLs bound the blast radius. They bound the *token* lifetime, not the *entitlement* lifetime.

What Was Observed

A three-agent pipeline: an orchestrator `O`, a retrieval worker `R`, and a side-effecting executor `E` that performs writes against an external store. All three carry capability wallets. `E`'s wallet mints a `write:store` token with a 45-second TTL and refreshes it on a 30-second cadence (so there is always ≥15s of headroom). Every `E` tool call presents the current token; the store's authorizer verifies signature, `exp`, `scope`, and `sub`.

Mid-task, `O` re-scoped the delegation: `R`'s grant was narrowed from `read:store` to `read:store:partition=p7` after a policy update, and — critically — `O` also *revoked* `E`'s `write:store` entitlement because the task had reached a checkpoint that should have been read-only until a human review. The revocation propagated to the wallet issuer's entitlement store within ~200ms.

What actually happened on `E`:

The executor's continuous check was *continuous verification*, not *continuous authorization*. The token was a bearer capability with a fixed lifetime; revocation at the issuer did not reach the executor because the executor never re-consulted the issuer — it only verified the token. The 45-second TTL, which was supposed to be the safety budget, became the *maximum revocation latency*, and the refresh-failure path silently extended it by retaining the old token.

A second, subtler observation: when `R` was narrowed to `partition=p7`, `R`'s wallet refreshed successfully and received a correctly narrowed token — but `R` had already *cached* a retrieved document from `partition=p3` in its working memory and continued to pass that document to `E` as context. The narrowing of the credential did not narrow the agent's *state*. The capability boundary moved; the agent's beliefs did not.

Condition of Validity

The invariant that was assumed and that failed:

> *A capability token presented at time `t` reflects the entitlement in force at `t`.*

This is only true under one of two conditions:

The observed system satisfied neither. It had short TTLs (looks like (B)) but no freshness floor, and it retained tokens across failed refreshes (violating even the weak form of (B)). It was, in effect, operating under an unstated assumption that short TTLs equal continuous authorization, which is false whenever the refresh path can fail while the token remains valid.

The condition of validity for "short-lived credentials give you continuous authorization" is therefore: *the credential must be re-derived from current entitlement on a cadence strictly shorter than the TTL, the derivation must fail closed, and the executor must refuse tokens older than the staleness bound.* All three. Two out of three is the failure mode.

Decision Boundary

The boundary is between **refresh-driven freshness** and **use-driven freshness**.

The decision rule for the architect:

A second decision boundary applies to *state*, not credentials: when a capability is narrowed, the agent's cached working memory derived under the broader capability must be invalidated or re-validated. A narrowed token does not retroactively narrow the context window. The rule: **capability narrowing must trigger a state invalidation event**, and the agent runtime must treat cached artifacts tagged with a now-out-of-scope capability as suspect on next use.

Operational Effect

Concretely, the system gained four properties it did not have before the fix:

  1. **Revocation latency became a stated number.** With a 45s TTL and a 15s freshness floor, the maximum time a revoked entitlement can still be exercised is 15s, not 45s, and not "until the next refresh happens to succeed." The number is now in the runbook.
  2. **Failed refresh became a hard stop for writes.** The wallet client no longer retains a token across a failed refresh for side-effecting scopes; it marks the token `stale` and the executor's pre-call check rejects it. This converts a silent degradation into a loud, attributable failure at the exact call that would have exceeded the bound.
  3. **Narrowing propagated to state.** A scope-narrowing event now emits an invalidation signal that the agent runtime uses to drop cached artifacts tagged with the broader scope. The `partition=p3` document would have been evicted when `R` was narrowed to `p7`, rather than silently leaking forward.
  4. **The word "continuous" became testable.** A conformance test now asserts: revoke an entitlement, then attempt a write at `floor + ε` seconds; the write must fail. Under the old design this test passed only if it happened to run after a refresh cycle — a flaky test that was, in retrospect, telling the truth.

The residual cost is latency on the refresh path and a small increase in failed calls during legitimate re-scoping. That cost is the price of the invariant, and it is bounded and enumerable — unlike the four committed writes that motivated it.

import time
from dataclasses import dataclass, field


class StaleCapabilityError(RuntimeError):
    """Raised when a side-effecting call would use a token whose remaining
    lifetime is below the freshness floor, or whose last refresh failed."""


class EntitlementRevokedError(RuntimeError):
    """Raised by the issuer when the underlying grant no longer exists."""


@dataclass
class CapabilityToken:
    scope: str
    minted_at: float
    ttl: float
    last_refresh_ok: bool = True

    def remaining(self, now: float) -> float:
        return (self.minted_at + self.ttl) - now


@dataclass
class CapabilityWallet:
    issuer: object
    scope: str
    ttl: float = 45.0
    freshness_floor: float = 15.0
    token: CapabilityToken = field(default=None)

    def _mint(self) -> CapabilityToken:
        now = time.monotonic()
        try:
            self.issuer.mint(self.scope)  # raises if entitlement gone
        except EntitlementRevokedError:
            if self.token is not None:
                self.token.last_refresh_ok = False
            raise
        return CapabilityToken(scope=self.scope, minted_at=now, ttl=self.ttl)

    def token_for_use(self, side_effecting: bool) -> CapabilityToken:
        now = time.monotonic()
        if self.token is None:
            self.token = self._mint()
        if side_effecting:
            if not self.token.last_refresh_ok:
                raise StaleCapabilityError(
                    f"scope={self.scope!r} last refresh failed; refusing write"
                )
            if self.token.remaining(now) < self.freshness_floor:
                # use-driven refresh: force re-derivation from entitlement
                self.token = self._mint()
                if self.token.remaining(time.monotonic()) < self.freshness_floor:
                    raise StaleCapabilityError(
                        f"scope={self.scope!r} refreshed token still below floor"
                    )
        return self.token


def execute_write(wallet: CapabilityWallet, store, payload: dict) -> None:
    token = wallet.token_for_use(side_effecting=True)
    if token.scope != "write:store":
        raise StaleCapabilityError(
            f"token scope {token.scope!r} does not cover write:store"
        )
    store.commit(payload)  # only reached with a fresh, entitled token