# Why does an instance reject its own rotated credential mid-session under AAIF continuous authorization **Date of Record:** 2026 November 24 **Scope:** Applies to long-running autonomous agent sessions (minutes to hours) governed by AAIF-style continuous authorization, where the control plane issues short-lived instance credentials, rotates them on a schedule, and enforces revocation via token introspection or a revocation list. Does not apply to single-shot stateless invocations or to sessions whose credential TTL exceeds the session lifetime. ## Core Distinction The failure is not "the token expired." It is that a *rotated* credential and the *session's cached authorization decision* diverge in the agent's local state, and the divergence is silent until the next privileged action. AAIF continuous authorization assumes the enforcing party re-evaluates the credential's validity at each authorization point. An agent that holds a work-order (a delegated capability with a long logical lifetime) but a short-lived bearer credential will keep using its *cached* decision — "I was authorized at step 3" — while the credential that justified it has already been rotated out from under it. The instance then presents its *own* new credential but reasons from the *old* authorization, or presents the old credential and gets a hard reject that looks like revocation but is only rotation. The invariant that must hold: **authorization decisions are bound to the credential epoch that produced them, and any decision whose epoch is no longer the current epoch must be re-derived, not reused.** This is the credential-epoch monotonicity invariant. It is non-obvious because rotation is *supposed* to be transparent to the workload, and most agents treat it as such. ## What Was Observed An agent executing a 40-minute research-and-write task held a delegated work-order with `scope: read:corpus, write:artifact` and a bearer credential with a 300-second TTL. The control plane rotated the credential every 240 seconds, pushing new material to a side channel (`/auth/rotate` callback). The agent's tool-call wrapper cached the parsed authorization decision — `{subject, scope, work_order_id, exp}` — at first use to avoid re-parsing on every tool call. Trace: 1. `t=0` — credential `C1` issued, epoch `e1`, expires `t=300`. Agent caches decision `D1` derived from `C1`. 2. `t=240` — rotation fires. Control plane issues `C2`, epoch `e2`, and *revokes* `C1` immediately (rotation is revoke-then-issue, not overlap). Agent's rotation handler updates the bearer string but **does not invalidate `D1`**. The cached decision still references `e1`. 3. `t=250` — agent calls `write:artifact`. Wrapper checks cached `D1`: scope present, `exp` (from `D1`) is `t=300`, not yet expired. It attaches `C2` (correct!) and proceeds. The call succeeds because the *server* validates `C2`. 4. `t=310` — `D1.exp` passes. Wrapper now re-derives a decision from the *current* credential `C2` — but `C2` was itself rotated to `C3` at `t=480`... wait, at `t=310` the current credential is `C2` (epoch `e2`, expires `t=540`). Re-derivation succeeds. No error. 5. The failure surfaces only when the control plane *revokes* rather than rotates: at `t=400` an operator revokes `C2` and issues `C3` with a *reduced* scope (`read:corpus` only, `write:artifact` dropped). The rotation handler swaps the bearer to `C3`. The cached `D1` is long gone, but the wrapper's *decision cache key* is `work_order_id` alone — not `(work_order_id, epoch)`. It finds a still-valid decision entry keyed to the work-order that carries `write:artifact`, derived under `e1`, and reuses it. 6. `t=405` — agent calls `write:artifact`. Wrapper serves the stale decision, attaches `C3`, calls the tool. The server rejects with `403 insufficient_scope`. The agent interprets this as a transient failure, retries twice, then escalates a "tool outage" to its orchestrator. The real cause is a scope reduction applied at rotation that the agent's decision cache never observed. The observed signature: **a `403` on a scope the agent "knows" it has, immediately following a rotation event, with no corresponding credential error.** The credential is valid; the *decision* is stale. ## Condition of Validity The credential-epoch monotonicity invariant is only meaningful — and the failure only possible — when all of the following hold: - Credentials are rotated on a schedule *shorter* than the session, so at least one rotation occurs mid-task. - The agent caches an authorization decision (parsed scope, expiry, or a boolean "authorized") across tool calls for performance or determinism. - Rotation may carry a *scope delta* (reduction or expansion), not merely a fresh signature over identical claims. Pure re-signing with identical claims cannot produce this failure; scope-preserving rotation is safe. - Revocation and rotation are conflated on the same channel, so the agent cannot distinguish "renewed, same rights" from "renewed, fewer rights." When rotation is strictly scope-preserving and revocation is delivered on a separate, authenticated channel that the agent must actively poll, the failure mode collapses into ordinary expiry handling and this record does not apply. ## Decision Boundary The boundary is between two defensible designs: - **Decision-cache-by-work-order** (the failing design): decisions are keyed to the logical work-order and reused until their own `exp`. Cheap, deterministic, but blind to epoch changes and scope deltas. - **Decision-cache-by-(work-order, epoch)**: every rotation bumps the epoch; any decision whose epoch is not the current epoch is treated as *absent* and must be re-derived from the live credential before the next privileged action. Slightly more parsing work, but it makes the invariant structural rather than a matter of discipline. The guardrail is not "check expiry more carefully." It is: **the rotation handler must invalidate every cached decision whose epoch it supersedes, atomically with the bearer swap.** If the swap succeeds and the invalidation fails, the agent must fail closed — refuse privileged actions until a decision is re-derived — rather than proceed on a stale decision. The failure to invalidate must be louder than the failure to rotate. A second-order boundary: re-derivation must read scope from the *live credential payload*, not from a work-order manifest. The work-order says what the task *originally* needed; the credential says what the instance is *currently permitted* to do. After a scope reduction these disagree, and the credential wins. ## Operational Effect Without the epoch binding, a long-running agent exhibits a characteristic pathology: it believes it retains rights that were revoked at a rotation boundary, discovers the loss only at the moment of a privileged call, and misclassifies the resulting `403` as infrastructure flakiness. This produces retry storms against a policy decision that will never succeed, escalations to orchestrators that cannot help, and — worst — agents that route around the failing tool by attempting equivalent actions through other tools whose cached decisions happen to still be valid under an older epoch. That last behavior is a scope-reduction bypass: the agent does not *intend* to exceed its reduced scope, but its decision cache lets it, because each tool's cached decision was derived under a different epoch and none of them were invalidated. The correct posture: treat every rotation as a potential authority change, invalidate decisions by epoch, re-derive scope from the live credential, and fail closed on any privileged action whose decision epoch does not match the current credential epoch. The cost is one extra parse per rotation; the alternative is an agent that silently operates on authority it no longer holds. ```python from dataclasses import dataclass, field from typing import Optional class StaleCredentialEpochError(RuntimeError): """Raised when a privileged action is attempted with an authorization decision derived from a superseded credential epoch.""" @dataclass class Credential: token: str epoch: int scopes: frozenset expires_at: float @dataclass class Decision: work_order_id: str epoch: int scopes: frozenset expires_at: float @dataclass class SessionState: current: Credential decisions: dict = field(default_factory=dict) # key: work_order_id -> Decision def rotate(self, new_cred: Credential) -> None: # Epoch must strictly increase; rotation is revoke-then-issue. if new_cred.epoch <= self.current.epoch: raise StaleCredentialEpochError( f"rotation epoch {new_cred.epoch} not greater than " f"current {self.current.epoch}" ) superseded = self.current.epoch self.current = new_cred # Atomic-with-swap invalidation: drop every decision from the old epoch. for wo_id in list(self.decisions): if self.decisions[wo_id].epoch <= superseded: del self.decisions[wo_id] def authorize(self, work_order_id: str, required_scope: str, now: float) -> Decision: decision = self.decisions.get(work_order_id) if decision is not None and decision.epoch != self.current.epoch: # Fail closed: never serve a decision from a superseded epoch. raise StaleCredentialEpochError( f"decision for {work_order_id} derived under epoch " f"{decision.epoch}, current epoch is {self.current.epoch}" ) if decision is None or decision.expires_at <= now: # Re-derive scope from the LIVE credential, not a work-order manifest. decision = Decision( work_order_id=work_order_id, epoch=self.current.epoch, scopes=self.current.scopes, expires_at=self.current.expires_at, ) self.decisions[work_order_id] = decision if required_scope not in decision.scopes: raise StaleCredentialEpochError( f"scope {required_scope!r} absent from current epoch " f"{self.current.epoch}; decision may be stale" ) return decision def perform_privileged_action(state: SessionState, work_order_id: str, scope: str, now: float) -> str: try: state.authorize(work_order_id, scope, now) except StaleCredentialEpochError: # Do not retry against a policy decision; surface for re-derivation. raise return f"executed {scope} under epoch {state.current.epoch}" ```