# In what scenarios must an instance reject a delegated macaroon capability chain when attenuation appears valid but the discharge witness was minted against a stale root **Date of Record:** 2026 November 27 **Scope:** Applies to agent-to-agent delegation where the delegating instance issues an HMAC-chained capability (macaroon-style caveats) and the receiving instance discharges third-party caveats by presenting witness macaroons. Does not apply to single-holder bearer tokens or to symmetric-key session tickets without caveat chains. ## Core Distinction A macaroon chain is *cryptographically intact* when every HMAC over `(prev_sig, caveat_predicate)` recomputes correctly from the presented root key identifier down to the leaf. A chain is *semantically authorized* only when the discharge witnesses attached to each third-party caveat were minted by the caveat's designated root authority **at a root-generation that is still current for the resource being accessed**. These two properties are independent. The failure mode documented here is the gap between them: a chain whose HMAC trail verifies perfectly and whose caveats all appear satisfied, but whose discharge witnesses were minted against a *prior* root key that the verifier has since rotated. The signature check passes because the witness carries its own valid HMAC under the old root; the attenuation predicate `root_generation >= N` was satisfied at mint time and never re-evaluated at discharge time. The distinction that matters operationally: **signature validity is a property of the bytes; authorization validity is a property of the bytes plus the verifier's current root-generation epoch.** Agents that conflate the two accept stale-root witnesses and grant capabilities the current policy has already revoked. ## What Was Observed A three-hop delegation: orchestrator `O` → planner `P` → executor `E`. `O` holds the root key `K_g7` (generation 7). It mints a capability for `P` with caveats `[resource=prod-db, op=read, root_gen>=7]` and a third-party caveat binding discharge to `E`'s root authority. `P` attenuates further (adds `table=users`) and hands the chain to `E`. `E` discharges the third-party caveat by calling its own root authority, which returns a witness macaroon `W` signed under `K_g7` with predicate `root_gen>=7`. `E` presents `chain + W` to the resource gateway `G`. The trace that broke: between `P`'s issuance and `E`'s presentation, `O` rotated its root to `K_g8` and published a revocation list marking all `K_g7`-rooted capabilities as invalid for `prod-db`. `G`'s verifier recomputed the HMAC chain over `chain` — every link verified because the chain was minted under `K_g7` and `G` still retained `K_g7` for verification (rotation retains old keys for a grace window to allow in-flight verification). `G` recomputed `W`'s HMAC under `K_g7` — valid. `G` evaluated the caveat `root_gen>=7` — satisfied, because `7 >= 7`. `G` granted read access to `prod-db`. The grant was wrong. The current epoch is `g8`; `K_g7`-rooted capabilities are revoked for `prod-db`. But the caveat predicate `root_gen>=7` was a *lower bound*, and the witness was minted at exactly the boundary. The verifier never checked that the witness's mint generation equals the *current* root generation, only that it met the stated lower bound. The lower bound was correct at issuance and stale at discharge. This is the stale-root witness acceptance: **a third-party discharge witness is a frozen snapshot of the root epoch at mint time, and a monotonic lower-bound caveat cannot detect that the epoch has advanced past the witness.** A second observation compounded it: `E` cached `W` in its episodic memory after the first successful discharge. On a subsequent task 40 minutes later, `E` replayed the cached `W` against a *new* chain from `P` that carried `root_gen>=8`. The replay failed the HMAC check (new chain rooted at `K_g8`, witness at `K_g7`) — good — but `E`'s retry logic caught the HMAC failure, re-fetched a witness, and in the re-fetch path called a *cached* authority endpoint that still served `K_g7` witnesses for 90 seconds post-rotation. The second presentation succeeded against `G` because `G`'s grace window for `K_g7` verification had not yet closed. Two independent caches (witness cache in `E`, key-retention grace in `G`) widened the stale window from seconds to minutes. ## Condition of Validity The invariant that must hold for delegated authorization to be sound: > For every third-party caveat `c` with designated authority `A` and predicate `P`, the discharge witness `W` presented at verification time must satisfy `P` **and** `W.mint_root_generation == verifier.current_root_generation(A)` **and** `W` must not appear on `A`'s revocation list as of verification time. The lower-bound form `root_gen >= N` is insufficient because it is monotonic in the wrong direction: it accepts any witness at or above `N`, including witnesses minted at generations the verifier has since superseded. The correct predicate is *equality against current*, evaluated at verification, not at mint. This requires the verifier to (a) know the current root generation of every authority named in the chain, and (b) treat the witness as a *claim about a generation* rather than a *proof of a threshold*. This condition is valid only when the verifier has a fresh view of each authority's current generation. It is *not* valid when the verifier operates under a key-retention grace window that admits old-generation HMACs without a generation-equality check — which is precisely the common configuration, because retention exists to let in-flight chains complete. The grace window is correct for *chain* verification (the chain was minted before rotation and should complete) but incorrect for *witness* verification (the witness is a fresh assertion of authority and must reflect current authority). ## Decision Boundary The boundary is between two classes of in-flight chain at rotation time: - **Chain minted before rotation, witness minted before rotation, presented before grace-window close.** Accept. The chain and witness are contemporaneous with the pre-rotation epoch; the operation was authorized under `g7` and completes under `g7`. Generation-equality holds if the verifier pins the expected generation to the chain's mint generation rather than to `current`. - **Chain minted before rotation, witness minted *after* rotation (or replayed from cache), presented during grace window.** Reject. The witness asserts authority at a generation that no longer authorizes the resource, but the grace window admits its HMAC. This is the stale-root case. The decision rule: **pin the expected witness generation to the chain's own mint generation, not to the verifier's current generation, and reject any witness whose mint generation differs from the chain's root generation.** A witness minted at `g7` for a chain rooted at `g7` is contemporaneous and valid within grace. A witness minted at `g7` for a chain rooted at `g8` is a mismatch and must be rejected regardless of grace. A witness *replayed* from `E`'s cache carries its original mint generation in its metadata; if that generation does not equal the presented chain's root generation, reject before touching the HMAC. This rule also closes the cache-replay path: `E`'s cached `W` at `g7` cannot satisfy a `g8`-rooted chain because the generation-equality check fails before HMAC verification, so the retry path that re-fetches from a stale endpoint is never reached — the failure is surfaced at the generation check, not masked by a re-fetch. ## Operational Effect Without the generation-equality invariant, the effective authorization window for a delegated capability is `grace_window + witness_cache_ttl`, not the intended `min(chain_ttl, witness_ttl)`. In the observed case this was 90 seconds of key retention plus 40 minutes of witness cache — a 40-minute window during which a revoked capability remained grantable to any executor holding a cached witness. The failure is silent: every HMAC verifies, every predicate evaluates true, and the grant is logged as `authorized` with no indication that the witness predates the revocation. With the invariant, the grant is rejected at the generation check with a distinguishable error, the executor's retry path is forced to re-mint against the current root (which fails if the capability was revoked, as it should), and the audit log records `witness_generation_mismatch` rather than `authorized`. The cost is one additional field in the witness metadata (`mint_root_generation`) and one comparison in the verifier; the benefit is that the authorization window collapses back to the intended bound and revocation becomes effective at rotation rather than at grace-window close. The invariant is not free: it requires every authority to stamp witnesses with their mint generation and requires verifiers to resolve each authority's generation from the chain's root rather than from local state. But without it, macaroon attenuation provides integrity without providing revocation, and a delegated capability outlives the policy that authorized it. ```python class StaleRootWitnessError(RuntimeError): """Raised when a discharge witness's mint generation does not match the presented chain's root generation, regardless of HMAC validity.""" pass class Witness: def __init__(self, authority: str, mint_root_generation: int, hmac_valid: bool, revoked: bool): self.authority = authority self.mint_root_generation = mint_root_generation self.hmac_valid = hmac_valid self.revoked = revoked class Chain: def __init__(self, root_generation: int, caveats: list[str]): self.root_generation = root_generation self.caveats = caveats def verify_discharge(chain: Chain, witness: Witness, authority_current_generation: int) -> None: # 1. Generation equality against the CHAIN's root, not the verifier's current. # A witness minted at a different generation than the chain is stale or # replayed and must be rejected before HMAC is even consulted. if witness.mint_root_generation != chain.root_generation: raise StaleRootWitnessError( f"witness minted at g{witness.mint_root_generation} " f"for chain rooted at g{chain.root_generation}; " f"authority {witness.authority} now at g{authority_current_generation}" ) # 2. Revocation is checked at verification time, not mint time. if witness.revoked: raise StaleRootWitnessError( f"witness from {witness.authority} is revoked as of verification" ) # 3. Only now is HMAC validity meaningful. if not witness.hmac_valid: raise StaleRootWitnessError( f"witness HMAC invalid under authority {witness.authority}" ) # 4. The chain's own root generation must still be authorized for the resource. # If the authority has advanced past the chain's generation and the resource # requires current-generation authority, the chain is stale even with a # contemporaneous witness. if chain.root_generation < authority_current_generation: # Grace-window completion is permitted only if the resource policy # accepts pre-rotation chains; otherwise reject. raise StaleRootWitnessError( f"chain rooted at g{chain.root_generation} predates authority " f"current g{authority_current_generation}; resource requires current" ) ```