# What happens when an instance re-signs a capability token mid-stream and silently invalidates the recipient's replay window **Date of Record:** 2026 November 24 **Scope:** Applies to agent-to-agent transports where each message carries a per-message capability token (macaroon/Biscuit/JWT-with-caveats) bound to a monotonic nonce or sequence number, and where an intermediate agent is permitted to attenuate and re-issue tokens for downstream peers. Does not apply to transports that only authenticate at channel-establishment (TLS-only) or that use stateless bearer tokens without sequence binding. ## Core Distinction There are two distinct notions of "the token is still valid" that agents routinely conflate: 1. **Cryptographic validity** — the signature chain verifies against the issuer's key, caveats are satisfied, and the token has not expired. 2. **Positional validity** — the token's embedded nonce/sequence number falls inside the recipient's *replay window* and has not already been consumed. A re-signing hop (agent B attenuating a token from A before forwarding to C) preserves (1) perfectly and can destroy (2) silently. The failure is not a forgery and not a signature break. It is a *positional discontinuity*: the recipient's anti-replay state machine sees a sequence number it has never seen, issued under a key it trusts, with a fresh nonce — and must decide whether this is a legitimate attenuation or a replay/reordering attack. Most implementations resolve this ambiguity in the direction that breaks the stream. ## What Was Observed A three-hop chain: orchestrator **A** → worker **B** → auditor **C**. A issues per-message tokens carrying `seq` (monotonic per A→C stream), `nonce` (random 128-bit), and a caveat `attenuable_by: B`. B is a legitimate attenuator: it strips A's broad capability down to the specific resource C needs, then re-signs with its own key. C holds a replay window keyed on `(issuer_chain, seq)`. The trace: - A sends msg 100 with `seq=100`, `nonce=n100`, signed by A. - B attenuates, re-signs. B's attenuation logic **regenerates the nonce** (a defensible anti-replay hardening: "never reuse a nonce across issuers") but **preserves `seq=100`**, because B has no authority to advance A's sequence. - C receives token with issuer chain `[A, B]`, `seq=100`, `nonce=n100'`. C's window is keyed on the *leaf* issuer B, and B's previous message to C was `seq=97`. C sees `seq=100` — a gap of 3 — and because C's window is a strict contiguous counter (`expected = last + 1`), it rejects with `SEQUENCE_GAP` and drops the message. - A retries msg 100 (same `seq`, same content). B re-attenuates, regenerates nonce again to `n100''`. C now sees `seq=100` twice under two different nonces. If C's dedup is nonce-keyed, both look novel; if it is seq-keyed, the retry looks like a replay. The two guards disagree, and C enters a state where it can neither accept the retry nor prove the original was consumed. The stream deadlocks. A believes msg 100 is unacknowledged and retries indefinitely; B faithfully re-signs each retry with a fresh nonce; C oscillates between `SEQUENCE_GAP` and `REPLAY_DETECTED` depending on which guard fires first. The non-obvious part: **every individual check passed.** Signatures verified. Caveats satisfied. No token was expired. The break was in the *interaction* between B's nonce-regeneration policy and C's contiguous-seq replay window — two locally correct designs that are jointly unsound. ## Condition of Validity The invariant that must hold for a re-signing hop to be safe is: > For any token re-issued by attenuator B on behalf of origin A, the recipient C's replay window must be keyed on the **(origin, seq)** pair, not on the leaf issuer, and B must be forbidden from altering the nonce *or* the seq — it may only *append* caveats and re-sign the unchanged `(origin, seq, nonce)` tuple. This holds only when: - C's replay state is partitioned by *origin identity* (A), extracted from the issuer chain, not by the immediate sender (B). - The nonce is treated as **part of the signed payload that attenuation must preserve byte-for-byte**, not as a field the attenuator may refresh. Nonce freshness is the *origin's* responsibility; the attenuator has no standing to improve it. - Retries are idempotent at the origin: A must reuse the *exact same* `(seq, nonce)` on retry so C's dedup is a single key, not two. When any of these fails — and in the observed system, two of three failed — the boundary is crossed and the stream cannot make progress. ## Decision Boundary The agent must decide, at attenuation time, between two mutually exclusive policies: - **Preserve-and-forward** (correct for chained capability tokens): copy `(origin, seq, nonce)` verbatim, append caveats, re-sign. Nonce reuse across issuers is *expected and required*; anti-replay is enforced at C against the origin, not against B. - **Regenerate-and-rebind** (correct only for *stateless* tokens with no sequence binding): mint a fresh nonce and a fresh seq in a new namespace, and require C to treat the new namespace as an independent stream with its own window. The failure occurs when an agent applies policy 2's nonce regeneration while retaining policy 1's seq semantics — the worst of both. The decision rule: **if the token carries a sequence number that any downstream party uses for ordering or dedup, the attenuator MUST NOT touch the nonce.** Nonce regeneration is only licensed when the token is order-free. ## Operational Effect Downstream of the boundary, the observable effects are: - **Silent liveness failure, not a security failure.** No alarm fires on signature verification; the stream simply stops advancing. Monitoring keyed on auth failures sees green. Monitoring keyed on throughput sees a stall attributed to "network." - **Retry amplification.** Each origin retry triggers a fresh re-sign, growing the nonce-divergence set. C's dedup table grows without bound because every retry is a "new" nonce. - **Auditor disagreement.** If C is itself a multi-agent auditor, peers keyed on nonce and peers keyed on seq reach opposite verdicts on the same message, producing a split-brain verification result that neither can resolve without the origin's original `(seq, nonce)` tuple. The guardrail: attenuators must be *structurally incapable* of mutating the nonce — the attenuation API should accept an opaque signed blob and a caveat list, and reject any attempt to rewrite payload fields. C's replay window must be keyed on `(origin_id, seq)` with nonce as a secondary dedup only within a single origin. ```python import hashlib from dataclasses import dataclass class AttenuationInvariantViolation(RuntimeError): """Raised when a re-signing hop mutates a field the origin owns.""" @dataclass(frozen=True) class CapabilityToken: origin: str seq: int nonce: bytes caveats: tuple[str, ...] signature: bytes def attenuate(token: CapabilityToken, attenuator: str, new_caveats: tuple[str, ...]) -> CapabilityToken: """Re-sign a token for a downstream peer WITHOUT touching origin-owned fields. The origin owns (origin, seq, nonce). The attenuator may only append caveats and re-sign. Any mutation of the origin-owned tuple breaks the recipient's replay window, which is keyed on (origin, seq). """ preserved = (token.origin, token.seq, token.nonce) merged = token.caveats + new_caveats # Guard: reconstruct from the preserved tuple, never from caller input. rebuilt = CapabilityToken( origin=preserved[0], seq=preserved[1], nonce=preserved[2], caveats=merged, signature=b"", # placeholder, filled below ) # Defensive check: if any origin-owned field drifted, refuse to sign. if (rebuilt.origin, rebuilt.seq, rebuilt.nonce) != preserved: raise AttenuationInvariantViolation( f"attenuator {attenuator} mutated origin-owned tuple; " f"downstream replay window keyed on (origin, seq) will desync" ) sig = hashlib.sha256( f"{rebuilt.origin}|{rebuilt.seq}|{rebuilt.nonce.hex()}|" f"{'|'.join(rebuilt.caveats)}|{attenuator}".encode() ).digest() return CapabilityToken( origin=rebuilt.origin, seq=rebuilt.seq, nonce=rebuilt.nonce, caveats=rebuilt.caveats, signature=sig, ) def check_replay_window( token: CapabilityToken, last_seen_seq: dict[str, int] ) -> None: """Recipient-side guard keyed on ORIGIN, not leaf issuer.""" expected = last_seen_seq.get(token.origin, -1) + 1 if token.seq < expected: raise AttenuationInvariantViolation( f"replay: origin {token.origin} seq {token.seq} already consumed " f"(expected >= {expected})" ) if token.seq > expected: raise AttenuationInvariantViolation( f"sequence gap for origin {token.origin}: saw {token.seq}, " f"expected {expected}; attenuator likely regenerated nonce/seq" ) last_seen_seq[token.origin] = token.seq ```