# How should an instance validate A2A signed envelopes when the nonce is bound to the sender's replay window rather than the receiver's **Date of Record:** 2026 November 27 **Scope:** Applies to A2A (agent-to-agent) transports where each message carries a signed envelope containing a sender-issued nonce, a monotonic sender sequence number, and a warrant/identity chain, and where the receiver enforces replay resistance by tracking accepted nonces per sender identity. Does not apply to stateless one-shot RPC without envelopes, nor to purely symmetric in-process agent calls where no cryptographic envelope exists. ## Core Distinction The failure is not "replay attack" in the textbook sense. It is a **nonce-scope mismatch**: the nonce is generated and consumed inside the *sender's* replay window (its own monotonic counter, its own dedup cache, its own clock), but the receiver's replay defense assumes the nonce is scoped to the *receiver's* acceptance window. When an agent instance restarts, fails over to a standby replica, or is horizontally scaled behind a load balancer, the sender's nonce counter and the receiver's seen-nonce set diverge in a way that is invisible to both signature verification and schema validation. The envelope is cryptographically valid, the sequence number is monotonic *from the sender's perspective*, and yet the receiver either (a) rejects legitimate post-failover messages as replays, or (b) accepts a genuinely replayed message because the sender's nonce was regenerated after a cold start. The distinction that matters operationally: **signature validity ≠ replay validity**. A signed envelope proves *who* sent it and that the bytes are intact. It does not prove *when* in the receiver's acceptance timeline it was sent, unless the nonce is bound to a receiver-observable, receiver-durable epoch. ## What Was Observed A two-agent pipeline: an orchestrator agent (`A`) dispatches signed task envelopes to a worker agent (`B`) over an A2A transport. Envelopes carry `{sender_id, seq, nonce, issued_at, payload, sig}`. `B` maintains a durable `seen_nonces` table keyed by `(sender_id, nonce)` with a TTL of 300s, and rejects any envelope whose `(sender_id, nonce)` is already present, or whose `seq` is ≤ the highest `seq` seen for that sender. Trace of the failure: 1. `A` runs as an active/standby pair. Active replica `A1` has `seq` at 48211 and nonce counter at 0x7f3a. 2. `A1` is drained for a rolling deploy. Standby `A2` is promoted. `A2`'s persisted state was last checkpointed 40s ago, so it resumes at `seq` 48190 and nonce counter 0x7f11. 3. `A2` emits envelope `E1` with `seq=48191, nonce=0x7f12`. `B` has already seen `seq` up to 48211 from `A1` and nonces 0x7f11–0x7f3a. `B` rejects `E1` as a replay (stale `seq`). 4. `A2` retries with backoff. Each retry increments `seq` but the nonce counter advances too; `B` continues rejecting until `A2`'s `seq` exceeds 48211 — roughly 20 messages of legitimate work dropped. 5. Worse: on a *separate* path, `A2`'s nonce space had wrapped past a segment `B` had already aged out of its 300s TTL. A delayed duplicate of `E1` (retransmitted by an intermediary) arrived after `B` had pruned 0x7f12 from `seen_nonces` but before `A2` had advanced past it. `B` accepted the duplicate, executed the payload twice, and the tool call inside was non-idempotent (a ledger debit). The two symptoms are the same root cause: **the nonce and sequence were bound to the sender's local epoch, not to a receiver-verifiable epoch that survives sender failover.** ## Condition of Validity The invariant required for replay resistance to hold is: > For any accepted envelope `E` from sender `S` at receiver `R`, the pair `(S.identity, E.nonce)` must be unique within `R`'s durable acceptance window, **and** `E.nonce` must be derivable only from state that `S` cannot rewind without `R` detecting it. This fails whenever the sender can legitimately rewind its nonce/sequence state — which happens on cold start from a stale checkpoint, on standby promotion, on restore-from-backup, or on any replica that initializes its counter from a default. The receiver's `seen_nonces` set is only a valid replay defense if the sender's nonce space is *monotonic across sender restarts*. A local counter is not. The condition is satisfiable only if at least one of the following holds: - The nonce includes a **receiver-issued epoch token** (e.g., `R` hands `S` a signed `epoch_id` at session establishment, and `S` embeds it in every nonce; `R` rejects envelopes bearing a superseded epoch). - The nonce includes a **sender-identity-bound monotonic value that is externally anchored** (e.g., a value from a durable, quorum-replicated log that `R` can independently check, not a local counter). - The receiver's replay window is **strictly larger than the maximum sender rewind distance**, and the sender's rewind distance is bounded and attested (rarely true in practice). Without one of these, the receiver's `seen_nonces` table is a best-effort cache, not a security boundary. ## Decision Boundary The operational decision is: **when does an envelope's nonce become the receiver's responsibility to validate against a durable epoch, versus the sender's responsibility to guarantee monotonicity?** The boundary is crossed at the moment the sender becomes *replica-ambiguous* — i.e., when more than one instance can legitimately emit envelopes under the same `sender_id`. Before that point (single-instance sender, no failover), a local counter is a valid nonce source and the receiver's dedup table is sound. After that point, the receiver must not trust the sender's local monotonicity; it must require an epoch binding. Concretely, the receiver should reject envelopes that lack an epoch binding *only when it has observed a sender restart*. It can detect this via a `boot_id` (a random value generated at sender process start, included in every envelope). A change in `boot_id` under the same `sender_id` is the signal that the sender's local counter has been rewound; at that point the receiver must either (a) require the sender to re-establish an epoch via a handshake, or (b) widen its acceptance window to cover the maximum plausible rewind and accept the duplicate-execution risk explicitly. Option (a) is correct; option (b) is a documented degradation. The decision must also account for the TTL pruning race: a `seen_nonces` entry must not be pruned until the receiver is certain the sender can no longer emit a duplicate with that nonce. That certainty requires the sender to attest, per envelope, that its nonce counter has advanced past the pruned value — which again requires the epoch binding. ## Operational Effect If the invariant is not enforced: - **Legitimate messages are dropped** during sender failover, because the receiver's `seq` high-water mark is ahead of the restarted sender's counter. This manifests as a burst of `replay_rejected` errors correlated with deploy or failover events. - **Genuine replays are accepted** after the receiver's TTL prunes a nonce that the sender's rewound counter will re-emit. This manifests as duplicate side effects (double tool calls, double ledger writes) with no signature failure and no schema error — the hardest class to detect, because every layer reports success. - **Audit trails diverge**: the sender's log shows one emission, the receiver's log shows two executions, and neither is flagged as anomalous because the envelope was valid at both points. If the invariant is enforced (epoch-bound nonces, `boot_id`-triggered re-handshake, prune-only-after-attestation): - Sender failover produces a bounded, explicit re-handshake event rather than a silent replay window. - Duplicate execution is bounded to the re-handshake gap, which is observable and alertable. - The receiver's `seen_nonces` table becomes a true security boundary rather than a cache with a TTL-shaped hole. The guardrail is not "check the signature harder." It is "bind the nonce to an epoch the receiver issued and can revoke," and treat any envelope whose `boot_id` differs from the last-seen `boot_id` for that sender as requiring re-establishment before acceptance. ```python class NonceEpochViolation(RuntimeError): """Raised when an A2A envelope's nonce cannot be bound to a receiver-verifiable epoch.""" pass class Envelope: def __init__(self, sender_id, boot_id, epoch_id, seq, nonce, payload, sig): self.sender_id = sender_id self.boot_id = boot_id self.epoch_id = epoch_id self.seq = seq self.nonce = nonce self.payload = payload self.sig = sig class ReceiverReplayGuard: def __init__(self, known_epochs, max_rewind_window): self.known_epochs = known_epochs # epoch_id -> issuer signature, set by receiver self.max_rewind_window = max_rewind_window self.last_boot_id = {} # sender_id -> boot_id self.high_water_seq = {} # sender_id -> int self.seen_nonces = {} # (sender_id, nonce) -> epoch_id def accept(self, env: Envelope, sig_ok: bool) -> bool: if not sig_ok: raise NonceEpochViolation(f"bad signature from {env.sender_id}") # Invariant: nonce must be bound to a receiver-issued epoch. if env.epoch_id not in self.known_epochs: raise NonceEpochViolation( f"epoch {env.epoch_id} for sender {env.sender_id} not issued by this receiver" ) prev_boot = self.last_boot_id.get(env.sender_id) if prev_boot is not None and prev_boot != env.boot_id: # Sender restarted: local counter may have rewound. Force re-handshake. raise NonceEpochViolation( f"sender {env.sender_id} boot_id changed {prev_boot}->{env.boot_id}; " f"require epoch re-establishment before accepting seq={env.seq}" ) key = (env.sender_id, env.nonce) if key in self.seen_nonces: return False # genuine duplicate within live epoch hw = self.high_water_seq.get(env.sender_id, -1) if env.seq <= hw and prev_boot == env.boot_id: # Same boot, seq went backwards: replay or corruption. return False self.seen_nonces[key] = env.epoch_id self.high_water_seq[env.sender_id] = max(hw, env.seq) self.last_boot_id[env.sender_id] = env.boot_id return True def prune(self, sender_id, up_to_nonce_seq, attested_by_sender: bool): # Only prune when the sender has attested its counter has advanced past # the pruned range within the current epoch. Otherwise the TTL hole reopens. if not attested_by_sender: raise NonceEpochViolation( f"refusing to prune nonces for {sender_id} without sender attestation" ) for (sid, nonce) in list(self.seen_nonces): if sid == sender_id and nonce <= up_to_nonce_seq: del self.seen_nonces[(sid, nonce)] ```