# How does an instance detect scope-narrowing replay in AAIF delegated credential chains when the attenuation proof is valid but the delegation epoch has rotated **Date of Record:** 2026 November 25 **Scope:** Applies to AAIF (Agent Identity and Authorization Interoperability Framework) delegated credential exchange where an agent presents a chain of scoped capability tokens attenuated across multiple hops. Does not apply to single-hop bearer tokens, mTLS-only peer identity, or capability tokens that carry no delegation epoch field. ## Core Distinction The failure mode here is not signature forgery, not scope escalation, and not a missing attenuation proof. Every cryptographic check passes. The distinction that matters is between **structural validity of the attenuation chain** and **temporal validity of the delegation epoch** under which that chain was minted. An AAIF capability token is a signed tuple `(issuer, subject, scope, caveats, parent_hash, epoch, exp)`. Attenuation is verified by checking that each child's scope is a subset of its parent's scope and that `parent_hash` commits to the exact parent bytes. The epoch field is a monotonic counter that the root issuer bumps whenever it revokes or re-issues the delegation subtree rooted at a given principal. The non-obvious boundary: a child token can be **perfectly attenuated, correctly signed, unexpired, and scope-valid** while its `epoch` is strictly less than the current epoch of its root. This happens when the root principal rotated its delegation epoch (e.g., because a downstream delegate went rogue and was re-provisioned) but a previously-issued grandchild token is still being replayed by a *different* agent that legitimately held it before the rotation. The attenuation proof is intact; the chain is stale. Naive verifiers check scope-subset and signature and stop. The invariant that must hold is: **a token is only honored if its `epoch` equals the current epoch of every ancestor in the chain, not merely the epoch it was minted under.** ## What Was Observed A three-hop delegation: orchestrator `O` (epoch 7) delegated `read:dataset/alpha` to planner `P`, which delegated `read:dataset/alpha/partition-3` to worker `W`. Worker `W` cached its token in an episodic memory store keyed by task ID. Mid-task, `O` detected anomalous access patterns from `P` and rotated its epoch to 8, re-issuing a fresh subtree to a new planner `P'`. The rotation propagated to `P'` and to `P'`'s workers — but `W`'s cached token, minted under epoch 7, was never invalidated in `W`'s local store because `W` had no live subscription to `O`'s epoch feed (it only refreshed on `exp`). On resume after a checkpoint, `W` presented its epoch-7 token to the resource server `R`. `R` verified: signature chain valid, `parent_hash` chain intact, scope `read:dataset/alpha/partition-3` ⊆ parent scope, `exp` in the future. `R` admitted the request. The request read partition-3 data that `O` had explicitly intended to cut off by rotating the epoch. The audit log showed a *valid* token, so the post-incident review initially classified it as "no anomaly." The tell was a single field mismatch buried three levels deep: `W.token.epoch == 7`, but `R`'s cached view of `O`'s current epoch was `8`. `R` never compared them because the AAIF reference verifier's `verify_chain()` returns `True` on structural validity and treats epoch as advisory metadata. The spec says epoch "SHOULD be checked against the issuer's current epoch," and the reference implementation implemented the SHOULD as a no-op when the epoch feed was unreachable — defaulting to *accept* rather than *reject*. ## Condition of Validity The stale-epoch replay is only possible when all of the following hold simultaneously: 1. The verifier has no fresh epoch attestation for the root issuer at verification time (feed lag, partition, or `W` resuming from a cold checkpoint without re-fetching epoch state). 2. The verifier's fallback policy on missing epoch data is fail-open (accept) rather than fail-closed (reject). 3. A token minted under a prior epoch remains cryptographically valid — i.e., the issuer did not embed a short `exp` aligned to epoch rotation, and did not include an epoch-revocation list in the token's caveats. 4. The replaying agent holds the token legitimately (it is not stolen), so identity checks against the *subject* pass. Remove any one condition and the failure collapses. The most common real-world removal is (2): a fail-closed epoch policy. But fail-closed has its own cost — every cold-start agent that cannot reach the epoch feed within its timeout budget is denied, which is itself an availability failure. The engineering tension is real and is why the SHOULD stayed a no-op in practice. ## Decision Boundary The boundary is between **epoch as metadata** and **epoch as a hard admission predicate**. Concretely: - If `token.epoch < root.current_epoch` → reject with `StaleDelegationEpoch`. Do not fall through to structural verification. - If `root.current_epoch` is unknown (feed unreachable) → the decision depends on `max_epoch_staleness` configured per resource sensitivity. For `read:*` on non-sensitive partitions, a bounded staleness window (e.g., accept if `now - last_epoch_fetch < 30s` and the token's `exp` is within that window) is defensible. For `write:*` or any partition tagged sensitive, unknown epoch is a hard reject. - If `token.epoch > root.current_epoch` → this is not staleness but a **fork**: the token claims an epoch the root has not issued. Treat as `EpochForkDetected`, which indicates either a compromised issuer key or a split-brain epoch counter across replicas. This is strictly more alarming than staleness and must escalate, not retry. The invariant to encode: **admission requires `token.epoch == root.current_epoch` for every ancestor, evaluated at verification time, with an explicit and sensitivity-tiered policy for the unknown case.** Structural validity is necessary but never sufficient. ## Operational Effect After the incident, the resource server `R` was changed to carry a locally-cached epoch vector (root principal → current epoch, with fetch timestamp) and to evaluate the equality predicate before any scope check. Cold-starting agents (`W` resuming from checkpoint) now must perform an epoch handshake as part of their resume sequence: fetch the current epoch vector for every ancestor in their held token chains, compare, and discard any token whose epoch is behind. The handshake is bounded by a `resume_epoch_timeout`; on timeout, the agent enters a `DEGRADED_NO_DELEGATION` state and may only perform actions covered by tokens whose root is the agent's own local principal (no delegation), rather than silently proceeding on stale delegated authority. The measurable effect: post-rotation replay attempts dropped from "invisible in audit" to "explicit `StaleDelegationEpoch` rejections logged with the offending chain hash." The cost was a ~40ms added latency on cold-start resume for the epoch handshake, and a new failure class — `DEGRADED_NO_DELEGATION` — that had to be wired into the orchestrator's retry logic so that a degraded worker is re-provisioned rather than retried indefinitely. The deeper lesson: in AAIF, **delegation is a lease, not a grant.** A token's authority is bounded not just by its scope and expiry but by the epoch under which its root still stands. Verifiers that treat epoch as advisory are, in effect, honoring revoked leases. ```python from dataclasses import dataclass from typing import Optional class StaleDelegationEpoch(RuntimeError): """Raised when a delegated token's epoch lags its root's current epoch.""" pass class EpochForkDetected(RuntimeError): """Raised when a token claims an epoch the root has never issued.""" pass class EpochUnavailable(RuntimeError): """Raised when the root epoch cannot be attested and policy is fail-closed.""" pass @dataclass class Token: issuer: str subject: str scope: str parent_hash: str epoch: int exp: float @dataclass class EpochVector: current: dict[str, int] # root principal -> current epoch fetched_at: float # monotonic timestamp of last successful fetch max_staleness_s: float # policy bound for advisory reads def verify_chain_admission( chain: list[Token], epoch_vector: Optional[EpochVector], now: float, sensitive: bool, ) -> None: """ Enforce the epoch-equality invariant across every ancestor in the chain BEFORE any scope or signature acceptance is treated as sufficient. """ # Structural pass (signatures, parent_hash linkage, scope subset) assumed done. for token in chain: if token.exp <= now: raise StaleDelegationEpoch( f"token for {token.subject} expired at {token.exp}" ) if epoch_vector is None: if sensitive: raise EpochUnavailable( "root epoch unreachable and resource is sensitive; refusing admission" ) # Non-sensitive: only admissible if feed staleness is within policy. # Caller must supply fetched_at elsewhere; here we treat None as unsafe. raise EpochUnavailable( "no epoch vector available; cannot evaluate delegation lease" ) if sensitive and (now - epoch_vector.fetched_at) > epoch_vector.max_staleness_s: raise EpochUnavailable( f"epoch vector stale by {now - epoch_vector.fetched_at:.2f}s " f"> policy {epoch_vector.max_staleness_s:.2f}s" ) for token in chain: root = token.issuer if root not in epoch_vector.current: raise EpochUnavailable( f"no attested epoch for root {root}; cannot verify delegation lease" ) root_epoch = epoch_vector.current[root] if token.epoch < root_epoch: raise StaleDelegationEpoch( f"token subject={token.subject} epoch={token.epoch} " f"lags root={root} epoch={root_epoch}; delegation lease revoked" ) if token.epoch > root_epoch: raise EpochForkDetected( f"token subject={token.subject} epoch={token.epoch} " f"ahead of root={root} epoch={root_epoch}; possible split-brain issuer" ) # Invariant satisfied: every ancestor epoch equals its root's current epoch. ```