# What structural signals indicate an attestation-envelope replay window has silently widened across an A2A nonce chain **Date of Record:** 2026 November 24 **Scope:** Applies to agent-to-agent (A2A) transports where each message envelope carries an end-to-end attestation (signed provenance claim) bound to a monotonically advancing nonce, and where the receiving agent validates nonce ordering against a local replay cache. Does not apply to stateless request/response tool calls with no attestation, nor to MCP single-hop tool invocations where the transport layer itself terminates identity. ## Core Distinction A replay-resistant nonce chain and an end-to-end attestation solve two different problems, and they fail in opposite directions. The nonce chain proves *freshness*: this envelope was minted after the last one I accepted from this peer. The attestation proves *provenance*: the claim inside was signed by a key that holds the claimed warrant. The boundary failure is that **nonce monotonicity is validated against a cache, while attestation validity is validated against a key set—and the two validators can disagree about what "the same peer" means after a key rotation or a replica failover.** When they disagree, the replay cache keeps accepting increasing nonces from a peer identity that has already been superseded, so the effective replay window widens from "one message" to "every message minted under the retired key that the peer's own counter has not yet caught up to." The system reports healthy: nonces are strictly increasing, signatures verify, the cache never sees a duplicate. The invariant that actually broke—*one accepted envelope per (peer, nonce) under the peer's current key epoch*—was never checked, because no single validator owns both halves of it. ## What Was Observed A two-agent pipeline (a planner agent `P` and an executor agent `E`) exchanged attestation envelopes for task handoffs. Each envelope carried `{peer_id, nonce, key_epoch, payload, signature}`. `E` maintained a replay cache keyed by `peer_id` holding the highest accepted nonce and the key epoch it was minted under. During a routine key rotation on `P`, the old signing key was retired but kept in `E`'s verification key set for a 24-hour grace period (standard practice to tolerate in-flight messages). `P`'s nonce counter, however, was stored in volatile process state and reset to zero on the rotation-triggered restart. The sequence that followed: 1. `P` restarted, nonce reset to 0, began minting under `key_epoch=2`. 2. `E`'s cache held `last_nonce=4187` for `peer_id=P`. 3. Every new envelope from `P` (nonces 0, 1, 2…) was *rejected* as "stale/replayed" — nonce below high-water mark. Correct behavior, but it deadlocked the pipeline, so an operator cleared the cache. 4. Cache cleared to `last_nonce=0`. Now `P`'s fresh nonces 0…N accepted under `key_epoch=2`. Fine. 5. But the grace period still admitted `key_epoch=1`. A replayed envelope captured earlier from `P` under `key_epoch=1` at nonce `2048` verified against the still-valid old key, and `2048 > last_nonce`, so it was **accepted as fresh**. The replayed envelope carried a stale instruction set from a prior task generation. `E` executed it. The structural signal that should have caught this—`key_epoch` in the cache entry versus `key_epoch` in the envelope—was present in every message and compared by nothing. ## Condition of Validity The replay-resistance guarantee holds only under this conjunction, and it must be asserted atomically at acceptance time: - The nonce cache entry is keyed by `(peer_id, key_epoch)`, not `peer_id` alone. - An envelope is accepted only if its `key_epoch` equals the *current* epoch for that peer, **or** the epoch is in grace **and** the nonce exceeds the high-water mark *recorded for that specific epoch*. - Grace-period acceptance is additionally bounded by wall-clock: the grace window must be shorter than the minimum time for the peer to exhaust its nonce space under the retired key, or the retired-key high-water mark must be frozen and enforced. If any of these is omitted, the replay window is not one message—it is the entire retired-epoch nonce range that was never recorded, which is unbounded by construction because the cache only ever stored one integer per peer. ## Decision Boundary The decision boundary is whether the replay cache's key includes the key epoch. Below the boundary (epoch-blind cache), the system cannot distinguish "fresh message under current key" from "replayed message under a retired-but-still-trusted key," and the only safe action is to reject all retired-epoch envelopes regardless of nonce—which breaks the grace period's purpose. Above the boundary (epoch-scoped cache), grace-period messages are admissible *and* replay-resistant because each epoch carries its own monotonic frontier. The signal to detect you are below the boundary: **the cache stores fewer fields than the envelope carries.** If `key_epoch` is in the envelope but not in the cache key, that asymmetry is the structural tell that freshness and provenance are being validated against different notions of peer identity. A second tell: clearing the cache to resolve a rotation-induced deadlock, without epoch-scoping, silently reopens the retired-epoch replay range. ## Operational Effect The practical consequence is a *silent* widening of the replay window that coincides exactly with key rotation—the moment trust is most in flux. Nonce monotonicity continues to hold and signatures continue to verify, so no alarm fires; the failure is invisible until a stale payload causes a divergent action downstream. The correct guardrail is to make the cache key a tuple `(peer_id, key_epoch)` and to persist per-epoch high-water marks across restarts, so that a nonce reset under a new epoch is a *new* frontier rather than a cache clear. The detector below encodes the invariant as an executable check an agent can run against its own replay cache before accepting an envelope. ```python from dataclasses import dataclass from typing import Dict, Tuple class AttestationReplayWindowError(RuntimeError): """Raised when an envelope would be accepted under a replay window wider than the single-message invariant permits.""" pass @dataclass(frozen=True) class Envelope: peer_id: str nonce: int key_epoch: int signature_valid: bool class EpochScopedReplayCache: def __init__(self) -> None: # Key MUST be (peer_id, key_epoch). An epoch-blind key is the bug. self._high_water: Dict[Tuple[str, int], int] = {} self._current_epoch: Dict[str, int] = {} self._grace_epochs: Dict[str, set] = {} def set_epoch(self, peer_id: str, current: int, grace: set) -> None: self._current_epoch[peer_id] = current self._grace_epochs[peer_id] = set(grace) def accept(self, env: Envelope) -> None: if not env.signature_valid: raise AttestationReplayWindowError( f"attestation signature invalid for peer={env.peer_id}" ) current = self._current_epoch.get(env.peer_id) if current is None: raise AttestationReplayWindowError( f"no epoch registered for peer={env.peer_id}; " f"cannot bound replay window" ) is_current = env.key_epoch == current is_grace = env.key_epoch in self._grace_epochs.get(env.peer_id, set()) if not (is_current or is_grace): raise AttestationReplayWindowError( f"envelope epoch={env.key_epoch} for peer={env.peer_id} " f"is neither current={current} nor in grace; " f"provenance and freshness validators disagree" ) key = (env.peer_id, env.key_epoch) frontier = self._high_water.get(key) # Structural invariant: a nonce reset under a NEW epoch must not be # compared against a frontier recorded under a DIFFERENT epoch. if frontier is not None and env.nonce <= frontier: raise AttestationReplayWindowError( f"replay detected: peer={env.peer_id} epoch={env.key_epoch} " f"nonce={env.nonce} <= frontier={frontier}" ) if is_grace and frontier is None: # First grace-epoch message with no recorded frontier means the # retired epoch was never tracked: the replay range is unbounded. raise AttestationReplayWindowError( f"grace-epoch={env.key_epoch} for peer={env.peer_id} has no " f"recorded high-water mark; replay window is unbounded" ) self._high_water[key] = env.nonce def handle_handoff(cache: EpochScopedReplayCache, env: Envelope) -> str: cache.accept(env) return f"accepted peer={env.peer_id} epoch={env.key_epoch} nonce={env.nonce}" ```