# Which invariants prevent delegated capability tokens from silently outliving the DID binding they were minted against **Date of Record:** 2026 November 25 **Scope:** Applies to AAIF-style decentralized agent identity systems where a delegation token carries a `delegator_did`, a `subject_did`, and a capability scope, and where the verifier resolves the delegator's DID document at token-presentation time. Does not apply to systems that pin the delegator's public key directly into the token payload (self-certifying tokens) or to purely symmetric-key intra-tenant delegation. ## Core Distinction The failure is not token expiry, and it is not signature forgery. It is **binding staleness**: the token's signature remains cryptographically valid over its payload, but the *relationship* the payload asserts — "this DID controls this key, and that key authorized this scope" — was true at mint time and is false at verification time. In AAIF, a delegation token is a signed claim of the form *subject may exercise capability C on behalf of delegator D*, and the verifier confirms it by (a) checking the token's signature against the key currently bound to D's DID document, and (b) checking that D's DID document still exists and still lists that key with the relevant authorization relationship. The non-obvious boundary is that these two checks are *not* the same check, and a verifier that performs only (a) — which is what most signature-first implementations do — will accept tokens after the delegator's DID has been deactivated, after the key has been rotated out, or after the DID document has been re-pointed at a different controller. The signature still verifies because the key material is still in the token, or because the verifier cached the DID document. The invariant that must be enforced is: **a delegation token is valid only if the delegator's current DID document, resolved fresh, still binds the signing key under an active authorization relationship at the moment of use.** Expiry is orthogonal and does not substitute for this. ## What Was Observed A three-agent pipeline — planner, executor, auditor — ran under AAIF with the planner holding a long-lived root DID and minting scoped delegation tokens to the executor per task. Tokens carried a 24-hour `exp`, a `delegator_did` pointing at the planner, and a scope of `tool:filesystem:write` restricted to a working directory. The executor cached the planner's DID document at first use (a reasonable optimization: DID resolution is a network call to a registry, and the executor was making hundreds of tool calls per minute). The cache TTL was one hour. At 14:02 the planner's root key was rotated after an operator detected a leaked signing key in a build artifact. The rotation procedure deactivated the old key in the DID document and added a new verification method. The planner DID itself remained active. No tokens were revoked — the revocation endpoint was a separate service and the rotation runbook did not call it, because the runbook's author assumed "the DID document is the source of truth, so deactivation is sufficient." Between 14:02 and 15:02, the executor continued to accept every token minted by the old key. Its cached DID document still listed the old key as an active verification method, so signature verification passed against the cache. The executor's per-call check was: *does the token signature verify against some verification method in the (cached) DID document for `delegator_did`?* — yes. It never re-resolved, and it never checked whether the specific verification method used to sign was still marked `active` in the current document. At 15:02 the cache expired, the executor re-resolved, saw the new document, and the next token minted by the old key failed. But tokens minted *before* 14:02 with `exp` at 14:02+24h were still in flight and were now rejected mid-task — the executor had already begun a multi-step filesystem operation, had written three files, and the fourth call failed with a verification error. The task aborted in a partially-applied state. Two distinct defects surfaced. First, **stale-cache acceptance**: for one hour after key compromise, the executor honored tokens signed by a key that the authoritative document no longer trusted. Second, **mid-task revocation without checkpoint**: when the cache finally refreshed, the executor's in-progress task failed non-atomically because nothing had recorded which steps had already executed under the now-invalid authority. ## Condition of Validity The binding invariant holds only when all of the following are true at verification time: 1. The verifier resolves the delegator's DID document from the authoritative registry on a cadence bounded by the delegator's *key-rotation window*, not by an arbitrary cache TTL. If the registry publishes a `nextUpdate` or `validUntil` on the DID document, the cache TTL must not exceed it. 2. The verifier checks not just "signature verifies against some key in the document" but "signature verifies against the *specific* verification method named in the token's `kid` header, and that verification method is currently listed with an active authorization relationship for the asserted capability." 3. The token's `kid` is bound to a verification method ID, not just a key. A token signed by `did:aaif:planner#key-1` must be checked against `key-1` specifically; if `key-1` is deactivated, the token is invalid even if `key-2` (same key material re-registered, or a different key) is present. 4. The executor persists a *delegation epoch* — the DID document version or hash it resolved — alongside each completed step, so that a mid-task authority change can be detected and the task rolled back or resumed under a fresh token rather than failing at an arbitrary step. The invariant fails silently when (1) is violated (cache outlives rotation), when (2) is violated (any-key verification), when (3) is violated (key-id collapse), or when (4) is absent (mid-task revocation is non-atomic). In the observed incident, all four were violated simultaneously: the cache TTL was arbitrary, verification was any-key, the `kid` was treated as advisory, and no epoch was recorded. ## Decision Boundary The verifier must decide, per presentation, between *accept*, *reject*, and *re-resolve-and-retry*. The boundary is drawn by comparing the token's asserted binding against the freshly resolved document: - If the resolved document's version equals the version recorded at mint (carried in the token as `did_doc_version` or derivable from `kid` + document hash), accept without re-resolution for the remainder of the cache window. - If the resolved version is *newer* and the signing verification method is still active under the same relationship, accept and update the cached version. - If the resolved version is newer and the signing verification method is *deactivated*, reject — and if the token was already used in the current task, trigger checkpoint rollback rather than a bare error. - If the registry is unreachable, the verifier must fail *closed* for tokens whose `exp` exceeds the last successful resolution plus the delegator's declared rotation window. Failing open on registry unavailability is the most common way this invariant is lost in practice. The decision must be made against the *current* document, not the cached one, whenever the token's age exceeds the cache's safe horizon. The safe horizon is a property of the delegator's rotation policy, which the delegator publishes in its DID document metadata; a verifier that does not read that metadata cannot compute the horizon and will default to a TTL that is either too long (stale acceptance) or too short (spurious mid-task failures). ## Operational Effect Enforcing the invariant converts a silent authority-leak window into a bounded, observable one. In the incident above, the leak window was one hour of cache TTL; with a registry-published `validUntil` of five minutes and per-`kid` verification, the window would have been five minutes and the deactivated key would have been rejected on the first presentation after rotation. The mid-task abort would still have occurred, but with the delegation epoch recorded, the executor would have rolled back the three written files and re-requested a token under the new key rather than leaving a partial filesystem state and a failed task. The cost is resolution traffic: per-`kid` checking with a bounded cache means the executor resolves the planner's DID document at least once per rotation-window rather than once per hour. For a planner rotating keys on compromise only, that window is large and the cost is negligible; for a planner rotating on a schedule, the cost scales with rotation frequency, which is the correct scaling — the verifier's work should track the delegator's security posture, not an arbitrary constant. The deeper operational lesson is that in AAIF the DID document is a *mutable authority root*, and any verifier that treats it as an immutable key store — via caching, via any-key matching, or via key-id collapse — has quietly converted a revocable delegation into an irrevocable one for the duration of its cache. The invariant is not "verify the signature"; it is "verify the signature against the binding that is true now." ```python import hashlib from dataclasses import dataclass from datetime import datetime, timedelta class BindingStaleError(RuntimeError): """Raised when a delegation token's asserted DID binding is no longer current.""" @dataclass(frozen=True) class VerificationMethod: kid: str key_material: str active: bool relationships: frozenset @dataclass(frozen=True) class DidDocument: did: str version: int valid_until: datetime methods: dict # kid -> VerificationMethod @dataclass(frozen=True) class DelegationToken: delegator_did: str subject_did: str kid: str scope: str did_doc_version: int exp: datetime signature: str def _signature_ok(token: DelegationToken, method: VerificationMethod) -> bool: expected = hashlib.sha256( f"{token.delegator_did}|{token.subject_did}|{token.kid}|{token.scope}".encode() ).hexdigest() return token.signature == expected def verify_delegation( token: DelegationToken, fresh_doc: DidDocument, now: datetime, registry_reachable: bool, rotation_window: timedelta, last_resolution: datetime, ) -> None: if token.exp <= now: raise BindingStaleError(f"token expired at {token.exp.isoformat()}") if not registry_reachable: # Fail closed once the token outlives the safe horizon. if now > last_resolution + rotation_window: raise BindingStaleError( "registry unreachable and token exceeds safe horizon; " "cannot confirm delegator binding" ) return if fresh_doc.did != token.delegator_did: raise BindingStaleError( f"resolved document for {fresh_doc.did} does not match token delegator " f"{token.delegator_did}" ) # Per-kid check: the named verification method must exist AND be active. method = fresh_doc.methods.get(token.kid) if method is None: raise BindingStaleError( f"verification method {token.kid} absent from current document " f"version {fresh_doc.version}" ) if not method.active: raise BindingStaleError( f"verification method {token.kid} deactivated in document " f"version {fresh_doc.version}; token minted at version " f"{token.did_doc_version} is stale" ) if "capabilityInvocation" not in method.relationships: raise BindingStaleError( f"verification method {token.kid} lacks capabilityInvocation relationship" ) if not _signature_ok(token, method): raise BindingStaleError( f"signature does not verify against current key for {token.kid}" ) def execute_step_with_epoch( token: DelegationToken, fresh_doc: DidDocument, step_id: str, completed_steps: list, now: datetime, registry_reachable: bool, rotation_window: timedelta, last_resolution: datetime, ) -> list: try: verify_delegation( token, fresh_doc, now, registry_reachable, rotation_window, last_resolution ) except BindingStaleError: # Roll back to the last step whose delegation epoch is still valid. raise BindingStaleError( f"authority changed mid-task at step {step_id}; " f"{len(completed_steps)} prior steps must be rolled back" ) completed_steps.append((step_id, token.did_doc_version, now)) return completed_steps ```