# How does an instance detect a stale AAIF attestation chain after a mid-task credential rotation **Date of Record:** 2026 November 29 **Scope:** Applies to autonomous agents that carry a delegated AAIF attestation chain across multiple tool calls or handoffs, where an upstream authority (root or intermediate issuer) may rotate its signing key while the agent is mid-task. Does not apply to single-shot invocations that complete before any rotation window, nor to stateless request/response APIs where each call re-fetches a fresh chain from the issuer. ## Core Distinction The failure is not "the signature is invalid." It is that **the signature is still valid against the key the agent cached, but that key is no longer the key the verifier will accept.** AAIF attestation chains are signed top-down: a root issues an intermediate warrant, the intermediate issues the agent's leaf warrant, and each link embeds the public key (or key ID) of the issuer at issuance time. When an issuer rotates, it publishes a new key and, per the framework's revocation semantics, marks the old key ID as `superseded` with a grace window — not `revoked`. A `superseded` key still verifies signatures cryptographically. The chain the agent holds is *internally consistent and cryptographically sound* while being *operationally dead*. The non-obvious part: the agent's local verification passes. `verify_chain()` returns `True`. Every signature checks out against the embedded key material. The break only surfaces at the *relying party* — the downstream tool or peer agent that independently resolves the issuer's current key set and finds the leaf's `issuer_key_id` is no longer the active key. The agent believes it is authorized; the relying party disagrees. This is a split-brain on authority, and it is silent on the agent's side. This is distinct from expiry. An expired warrant fails loudly at the agent (`not_after < now`). A superseded-issuer chain fails *only at the verifier*, and only if the verifier is doing fresh key resolution. If the verifier caches too, both sides agree — until one cache refreshes and the other doesn't, at which point you get intermittent, load-balancer-shaped authorization failures that look like flaky infrastructure rather than a stale credential. ## What Was Observed A three-hop agent pipeline: an orchestrator holds a root-signed intermediate warrant, mints a leaf warrant per subtask, and hands the leaf to a worker agent that calls a gated tool. The tool's authorization gateway resolves the issuer's JWKS on a 60-second TTL. Trace of a failing run: 1. `T+0` — Orchestrator mints leaf `L1` with `issuer_key_id = K_int_v1`, `not_after = T+3600`. Worker begins a long tool-call sequence. 2. `T+840` — Root rotates the intermediate signing key: `K_int_v1 → superseded`, `K_int_v2 → active`. JWKS now lists both; `K_int_v1` carries `status: superseded, grace_until: T+2640`. 3. `T+900` — Gateway's JWKS cache expires and refreshes. It now sees `K_int_v1` as superseded. Gateway policy: reject chains whose leaf issuer key is not `active`, *even within grace*, because the gateway is the enforcement point and grace is meant for in-flight signatures, not new authorizations. 4. `T+901` — Worker presents `L1`. Gateway returns `403 issuer_key_superseded`. Worker's *local* `verify_chain(L1)` still returns `True` — it resolved keys at `T+0` and cached them. 5. Worker, seeing a 403 that its local verifier says shouldn't happen, retries `L1` three times. All fail identically. 6. `T+910` — Worker surfaces an opaque `authorization_failed` to the orchestrator, which — lacking the gateway's error taxonomy — treats it as transient and re-dispatches the *same* worker with the *same* `L1`. Loop. The agent had no signal distinguishing "my credential is stale" from "the tool is down." Its local verifier actively *lied* by returning `True`. The 403 body carried the reason, but the worker's error handler classified all 4xx as non-retryable-except-403-as-transient, a common and wrong default. A second observed variant: in a peer handoff, worker A passed `L1` plus its cached JWKS snapshot to worker B as part of a state-transfer envelope. Worker B trusted the snapshot (it was signed by A) and verified `L1` against it. Both agents agreed the chain was valid. The gateway disagreed. Two-agent consensus on a stale authority is worse than one agent's error, because the handoff envelope's signature made the stale snapshot look authoritative. ## Condition of Validity The guardrail holds only under these conditions, and the invariant must be stated precisely: **Invariant:** A leaf warrant is *operationally valid* at a relying party R at time t iff (a) every signature verifies against key material R resolved at time ≥ t − R.jwks_ttl, AND (b) no issuer key in the chain carries `status ∈ {superseded, revoked}` at R's resolution time, AND (c) the leaf's `issuer_key_id` equals the issuer's `active` key ID at R's resolution time. Condition (c) is the one agents miss. Cryptographic validity (a) is necessary but not sufficient. The agent's local verifier can only check (a) — it has no authority to assert (b) or (c), because those are properties of the *issuer's current state*, which the agent does not own. Therefore: **an agent must never treat its own `verify_chain()` result as evidence of operational validity.** Local verification answers "was this signed by who it claims," not "will the relying party accept it now." These are different predicates and conflating them is the root defect. The condition of validity for *relying on a cached chain* is that the agent's key-resolution age plus the remaining task duration is less than the issuer's rotation-detection latency. If a task may outlive a plausible rotation, the agent must re-resolve before each authorization-bearing call, or must carry a chain whose issuer key has a `not_after` that bounds the exposure. ## Decision Boundary The decision the agent must make at each authorization-bearing call: - **If** the call's expected duration + current key-cache age < issuer's advertised `rotation_notice_window`, **then** cached chain is safe to present; proceed. - **If** that sum exceeds the window, **then** the agent must perform a *fresh key resolution* (bypass its JWKS cache) and re-check conditions (b) and (c) before presenting. If re-resolution shows the issuer key is no longer `active`, the agent must *re-mint* the leaf under the new active key — it cannot re-sign the old leaf, because the leaf's `issuer_key_id` is immutable. - **If** the agent cannot re-resolve (issuer unreachable) and the window is exceeded, **then** it must fail closed with a distinguishable `AttestationStaleError`, not a generic auth error, so upstream orchestration does not retry the same dead chain. The boundary is *not* "on 403, refresh." A 403 is the relying party telling you after the fact. The boundary is *proactive*: the agent tracks `(key_cache_age + expected_call_duration)` against the rotation window and refreshes *before* the call that would cross it. Reactive refresh is the fallback, not the design. Critically, the agent must treat the relying party's error taxonomy as authoritative over its own verifier. If the gateway says `issuer_key_superseded`, the agent's `verify_chain() == True` is *wrong by definition* — the agent's verifier is checking a weaker predicate. The agent must not "defend" its chain against the gateway. ## Operational Effect With the invariant enforced, the failure mode converts from a silent split-brain into a bounded, typed, self-healing event: - Stale chains are detected *before* presentation, so the gateway never sees a superseded-issuer leaf and the 403 class disappears from normal operation. - When detection fires mid-task, the agent re-mints under the active key, and the task continues with a new leaf — the orchestrator sees a `reissued` event, not a failure. - Handoff envelopes must carry a `jwks_resolved_at` timestamp and the relying party must reject envelopes whose snapshot age exceeds its own TTL. This kills the two-agent-consensus-on-stale-authority variant: worker B refuses to trust A's snapshot if it's older than B's freshness bound, and re-resolves independently. - Error classification becomes correct: `AttestationStaleError` is retryable *after re-mint*, `issuer_key_revoked` (not superseded) is terminal, and generic transport 403s remain transient. The orchestrator's retry policy keys off the typed error, not the HTTP status. The residual risk: an issuer that rotates without honoring its advertised `rotation_notice_window` can still invalidate a chain inside the agent's freshness bound. This is why the invariant includes (c) — the active-key-ID check — as a hard gate at presentation time when the window is uncertain, accepting the extra resolution round-trip rather than trusting the bound. ```python import time from dataclasses import dataclass class AttestationStaleError(RuntimeError): """Raised when a cached AAIF chain is cryptographically valid but operationally dead: an issuer key in the chain is no longer active.""" pass class IssuerUnreachableError(RuntimeError): """Raised when fresh key resolution is required but the issuer is down.""" pass @dataclass class KeyRecord: key_id: str status: str # "active" | "superseded" | "revoked" grace_until: float # epoch seconds; only meaningful for superseded @dataclass class CachedChain: leaf_issuer_key_id: str resolved_at: float expected_call_duration: float def assert_operationally_valid( chain: CachedChain, resolve_jwks, # callable -> dict[str, KeyRecord], bypasses cache rotation_notice_window: float, now: float | None = None, ) -> None: """Enforce: key_cache_age + expected_call_duration < rotation window, else re-resolve and require leaf issuer key to be 'active'.""" now = time.time() if now is None else now age = now - chain.resolved_at exposure = age + chain.expected_call_duration if exposure < rotation_notice_window: return # cached chain is within the safe bound try: jwks = resolve_jwks() except Exception as exc: raise IssuerUnreachableError( f"exposure {exposure:.0f}s exceeds window " f"{rotation_notice_window:.0f}s and issuer is unreachable" ) from exc rec = jwks.get(chain.leaf_issuer_key_id) if rec is None: raise AttestationStaleError( f"leaf issuer key {chain.leaf_issuer_key_id} absent from current JWKS" ) if rec.status == "revoked": raise AttestationStaleError( f"issuer key {rec.key_id} revoked; chain is terminal" ) if rec.status == "superseded": raise AttestationStaleError( f"issuer key {rec.key_id} superseded (grace_until={rec.grace_until}); " f"re-mint leaf under active key before presenting" ) if rec.status != "active": raise AttestationStaleError( f"issuer key {rec.key_id} in unknown status {rec.status!r}" ) # active: safe to present, but caller should refresh resolved_at ```