# How does an instance detect delegated capability token replay across agent restarts in AAIF scoped credentials **Date of Record:** 2026 November 15 **Scope:** Applies to AAIF delegated capability tokens issued with `delegation_depth > 0` and bound to an agent instance identifier that survives process restarts (e.g., persistent host ID, K8s pod UID, or SPIFFE ID). Does not apply to ephemeral single-use tokens or to root capability tokens issued directly to a principal. ## Core Distinction A delegated capability token is *valid* if its signature, scope, expiry, and delegation chain verify. It is *authorized for this instance* only if the instance presenting it is the same instance the token was minted for. These are orthogonal checks. Most AAIF implementations collapse them into a single `verify(token)` call, which returns `True` for a token that was legitimately issued to instance A but is now being presented by instance B that inherited A's persistent identity after a restart, scale-down, or state snapshot restore. The non-obvious boundary: **instance identity persistence is not instance identity continuity.** When an agent process restarts and reloads its persistent identity, AAIF's token binding check passes because the binding key is the same. But the token's *delegation epoch* — the counter that the issuer increments on each re-delegation — may have advanced during the restart window, and the restarted instance holds a stale-epoch token that is structurally indistinguishable from a replayed one. ## What Was Observed In a multi-tenant agent fleet, worker agents received delegated tokens from an orchestrator with `delegation_depth=2` and a 15-minute TTL. On a rolling restart, a worker process resumed from a checkpointed state directory containing its identity keypair and a cached token. The token had 4 minutes of TTL remaining and verified cleanly. The worker proceeded to call downstream tools with a scope (`files:write:/tenant-a/*`) that the orchestrator had *revoked* 90 seconds earlier by advancing the delegation epoch and issuing a replacement token to the freshly spawned worker. The restarted worker never saw the revocation because revocation was communicated only via a new token, not via a CRL or epoch check. The stale token's signature was valid, its scope string was intact, and its `instance_id` claim matched the reloaded identity. AAIF logged `verify=ok` for every downstream call. The only signal was a downstream audit entry showing two distinct `process_start_time` values for the same `instance_id` within one token TTL — a correlation that no component was performing. ## Condition of Validity The replay is detectable only under the conjunction of three conditions: 1. The token carries an `epoch` or `generation` claim that the issuer increments on every re-delegation or revocation event. 2. The receiving policy enforcement point (PEP) has access to the issuer's current epoch for that delegation chain — either via a signed epoch manifest refreshed on a bounded interval shorter than the token TTL, or via an introspection call. 3. The instance's `process_start_time` (or equivalent monotonic boot nonce) is recorded in the token at mint time and compared at presentation time. If any one is missing, the stale-epoch token is indistinguishable from a live one at the PEP. Condition 2 is the common failure: token-only revocation designs (no introspection endpoint, no epoch manifest) cannot detect this class of replay at all, because the only artifact of revocation is a token the restarted instance never received. ## Decision Boundary The operational decision is: **when a restarted instance presents a token whose `epoch` is less than the issuer's current epoch for that chain, reject and force re-delegation; do not silently accept and do not silently downgrade scope.** The boundary cases: - If `token.epoch == issuer.current_epoch` and `token.boot_nonce == instance.boot_nonce`: accept. - If `token.epoch < issuer.current_epoch`: reject with `StaleDelegationEpoch`, regardless of TTL remaining. The instance must re-request delegation. - If `token.epoch > issuer.current_epoch`: reject with `EpochAheadOfIssuer` — indicates clock skew or a forged manifest; do not fall back to TTL. - If the PEP cannot reach the epoch manifest within its refresh budget: fail closed. Accepting on manifest-unavailable is the exact hole that produced the observed incident. The counterintuitive part: a token with 4 minutes of TTL remaining is *more* dangerous than an expired one, because it passes every naive freshness check while carrying a revoked scope. ## Operational Effect After adopting epoch-checked presentation, the fleet saw a 0.3% rejection rate on restart, all of which were genuine stale-epoch presentations that previously would have executed with revoked scope. Re-delegation latency added ~40ms per restart, bounded by the orchestrator's token mint path. The epoch manifest refresh interval must be set strictly less than the minimum token TTL in the fleet; setting it equal creates a window where a revoked token is still accepted for up to one refresh period. The invariant to enforce in code: `manifest_refresh_interval < min(token_ttl) - max(clock_skew)`. ```python import time from dataclasses import dataclass class StaleDelegationEpoch(RuntimeError): """Raised when a presented capability token's epoch is behind the issuer's current epoch.""" pass class EpochManifestUnavailable(RuntimeError): """Raised when the PEP cannot confirm the issuer's current epoch; must fail closed.""" pass @dataclass(frozen=True) class CapabilityToken: instance_id: str delegation_chain: str epoch: int boot_nonce: str scope: str expires_at: float @dataclass(frozen=True) class EpochManifest: chain: str current_epoch: int fetched_at: float def authorize_presentation( token: CapabilityToken, instance_boot_nonce: str, manifest: EpochManifest | None, manifest_max_age_s: float, now: float | None = None, ) -> bool: now = time.monotonic() if now is None else now if manifest is None or (now - manifest.fetched_at) > manifest_max_age_s: raise EpochManifestUnavailable( f"no fresh epoch manifest for chain {token.delegation_chain!r}; " "refusing to authorize on TTL alone" ) if token.delegation_chain != manifest.chain: raise EpochManifestUnavailable( f"manifest chain {manifest.chain!r} does not match token chain " f"{token.delegation_chain!r}" ) if token.epoch > manifest.current_epoch: raise StaleDelegationEpoch( f"token epoch {token.epoch} ahead of issuer epoch " f"{manifest.current_epoch}; possible forgery or clock skew" ) if token.epoch < manifest.current_epoch: raise StaleDelegationEpoch( f"token epoch {token.epoch} behind issuer epoch " f"{manifest.current_epoch}; delegation revoked during restart window" ) if token.boot_nonce != instance_boot_nonce: raise StaleDelegationEpoch( f"token boot nonce {token.boot_nonce!r} does not match live instance " f"{instance_boot_nonce!r}; token minted for a prior process" ) if token.expires_at <= now: raise StaleDelegationEpoch( f"token expired at {token.expires_at}; epoch matched but TTL elapsed" ) return True ```