# Which invariants prevent capability-token replay across DID-authenticated agent handoffs **Date of Record:** 2026 November 23 **Scope:** Applies to agent-to-agent (A2A) handoffs where the receiving agent authenticates the caller via a Decentralized Identifier (DID) document and authorizes the action via a signed capability token (e.g., a UCAN-style chain or a Macaroon). Does not cover human-in-the-loop OAuth flows, nor single-agent tool calls where the tool is co-located and stateless. ## Core Distinction The failure is not "a token was stolen." It is that **DID authentication and capability authorization are verified against two different clocks and two different subjects, and neither check binds the token to the specific execution instance that will spend it.** A DID proves *who signed the request envelope now*. A capability token proves *what the bearer was granted then*. Between those two facts sits an unverified gap: nothing in the standard handoff asserts that the DID controller who authenticated this second is the same principal the capability was minted for, nor that this is the first time this token has been presented. The token is transferable by design (bearer semantics), the DID is not (proof-of-possession), and the handoff protocol rarely reconciles the two. An agent that re-authenticates cleanly on every hop can replay a capability issued to a peer, because authentication succeeds on the *presenter* while authorization succeeds on the *token* — and the presenter is a different agent instance than the one the token was scoped to. ## What Was Observed A three-agent pipeline: Planner → Executor → Auditor. The Planner issued a capability token `cap:exec:write:bucket-7` to the Executor, scoped to `aud = did:key:z6Mk...Executor`, with an expiry of 300s and no nonce. The Executor completed its task, then a retry was triggered by an upstream timeout. The Executor's supervisor spawned a *fresh* Executor instance (`Executor'`) with the same DID document but a new process, new in-memory state, and — critically — the same capability token replayed from the checkpointed task envelope. The Auditor, on receiving `Executor'`'s write request, performed the standard two-step check: 1. Resolved `did:key:z6Mk...Executor` from the envelope, verified the signature over the request body. **Passed** — `Executor'` holds the same private key (loaded from the shared keystore). 2. Verified the capability chain: signature valid, `aud` matches the DID, `exp` not yet reached, `cap` covers `write:bucket-7`. **Passed**. The write executed twice. The second write was a duplicate append to an append-only log, corrupting the ledger's idempotency assumption. The Auditor never saw a conflict because the token carried no `nonce` and no `jti`, and the DID carried no binding to a specific process incarnation. Both checks were individually correct; the *conjunction* was unsound. The deeper trace: the checkpoint/resume boundary in the Executor supervisor serialized the task envelope *including the capability token* but not the *execution epoch*. On resume, the supervisor minted a new epoch for the process but did not invalidate tokens minted under the old epoch. So the invariant "a token is valid only within the epoch that first presented it" was never asserted anywhere — not in the token (no epoch claim), not in the DID (DIDs are long-lived), and not in the Auditor's policy (it had no epoch registry). ## Condition of Validity The two-step check (DID proof-of-possession + capability scope/expiry) is sound **only if** the capability token is *non-transferable across execution instances*, which requires one of: - a `jti`/nonce claim plus a replay cache at the verifier keyed by `(jti, aud)`, with cache TTL ≥ token `exp`; or - a `cnf` (confirmation) claim binding the token to a specific key *distinct from the DID's long-term key* — i.e., a per-instance ephemeral key whose public half is in the token, so a resumed instance with the same DID but a new ephemeral key cannot spend it; or - an epoch claim in the token that the verifier checks against a monotonic epoch registry, rejecting tokens whose epoch precedes the presenter's current epoch. Absent one of these, the check is valid only under the unstated assumption that **the DID controller is a single serial execution context** — which is false the moment checkpoint/resume, retries, or horizontal scaling enter the picture. The invariant that actually holds is narrower than it appears: *the token authenticates a principal, not an execution*. Any architecture that treats the two as interchangeable has a latent replay window whose width equals the token's remaining TTL after the first spend. ## Decision Boundary The boundary is crossed at the moment a task envelope containing a capability token is **persisted and later re-presented**, rather than spent inline within a single execution context. Concretely: - **Safe side:** token minted, presented, and consumed within one process lifetime; verifier's replay cache is authoritative; no serialization of the token across a checkpoint. - **Unsafe side:** token serialized into a checkpoint, task queue, or retry envelope, then re-presented by a rehydrated instance. The rehydration is *indistinguishable* from a legitimate first use to any verifier that lacks an epoch or nonce check. The decision an operator must make explicit: **either tokens are single-use and never checkpointed (re-mint on resume from the supervisor's long-term credential), or tokens are multi-use and carry a nonce the verifier deduplicates.** The middle ground — checkpointed bearer tokens with only scope/expiry checks — is the failure mode. There is no third option; "trust the DID" does not close the gap because the DID is stable across the very instance boundaries that make replay possible. ## Operational Effect When this invariant is violated, the observable signature is **duplicate side effects with clean audit logs**: every individual verification step shows `valid`, the signatures all check, the DIDs all resolve, and yet the effect applied twice. This is the worst class of failure for post-hoc forensics, because the logs contain no error — the corruption is in the *absence* of a deduplication record, not in a failed check. Downstream idempotency guards (append-only logs, exactly-once queues) absorb the duplicate silently until they don't, at which point the ledger is already inconsistent and the replay window has closed (token expired), leaving no live token to revoke. The remediation is structural, not procedural: bind every capability to an execution epoch at mint time, require the verifier to hold an epoch floor per `aud`, and treat any token whose epoch is below the floor as a replay regardless of signature validity. Re-mint on resume from the supervisor's long-term credential rather than rehydrating the spent token. The guardrail is the epoch floor, and it must live at the verifier — the issuer cannot enforce it alone, because the issuer does not observe the rehydration. ```python class CapabilityReplayError(RuntimeError): """Raised when a capability token is presented under an execution epoch that precedes the verifier's recorded epoch floor for its audience.""" def verify_capability(token, presenter_did, epoch_registry): # Step 1: DID proof-of-possession (unchanged, and insufficient alone). if not token.verify_signature(presenter_did): raise CapabilityReplayError( f"signature invalid for presenter {presenter_did}" ) # Step 2: scope and expiry (unchanged, and insufficient alone). if token.is_expired() or not token.covers(presenter_did): raise CapabilityReplayError("scope or expiry check failed") # Step 3: the invariant that actually bounds replay. floor = epoch_registry.get_floor(token.aud) if token.epoch < floor: raise CapabilityReplayError( f"replay: token epoch {token.epoch} < floor {floor} " f"for aud {token.aud}" ) if token.jti in epoch_registry.seen_jtis(token.aud): raise CapabilityReplayError( f"replay: jti {token.jti} already spent for aud {token.aud}" ) epoch_registry.record_spend(token.aud, token.jti, token.epoch) return True ```