# When must an instance reject a replayed A2A v1.0 envelope that is cryptographically valid and within its nonce window **Date of Record:** 2026 December 3 **Scope:** Applies to agent-to-agent handoffs where a signed A2A v1.0 envelope carries a `nonce`, `issued_at`, `expires_at`, and detached signature, and the receiving agent maintains a replay cache. Does not cover transport-level TLS replay, unsigned envelopes, or symmetric pre-shared-key schemes without per-message nonces. ## Core Distinction The non-obvious boundary is this: **signature validity and nonce-window validity are independent predicates, and an envelope can satisfy both while still being a replay.** The common mental model treats replay protection as a function of the nonce cache alone — "if I haven't seen this nonce, it's fresh." That model fails because the nonce is scoped to the *sender's* identity, not to the *message content*. A malicious or compromised sender instance (or a sender whose signing key was rotated but not revoked) can re-issue a *new* envelope with a *new* nonce wrapping a *replayed payload* — specifically a replayed `task_id` + `result` + `auditor_warrant` triple. The receiver's cache sees a fresh nonce, the signature verifies under the sender's still-valid key, the timestamps are inside the window, and the agent accepts a result it already acted on. Non-repudiation is preserved (the sender *did* sign it), but **idempotency is violated** — the receiving agent re-executes or re-acknowledges a completed task, corrupting downstream state. The invariant that actually bounds this: *acceptance requires (signature ∨ key-validity) ∧ nonce-freshness ∧ payload-digest-freshness*, where payload-digest-freshness is keyed on `(sender_id, task_id, result_digest)` and has a retention window at least as long as `expires_at − issued_at` plus the maximum clock skew. Most implementations drop the third conjunct. ## What Was Observed A three-agent pipeline: `planner` → `executor` → `auditor`. The auditor signs a `warrant` envelope attesting that executor's result for `task_id=T-4417` is correct, and returns it to the planner. The planner's A2A client had a correct nonce cache (LRU, 4096 entries, 10-minute TTL matching the envelope window) and verified signatures against a JWKS endpoint with a 5-minute key cache. Failure trace: 1. `auditor` emits envelope `E1` for `T-4417` at `issued_at=10:00:00`, `nonce=n1`, signed by key `K_a`. Planner accepts, marks `T-4417` complete, discards `E1` from its nonce cache after TTL at `10:10:00`. 2. At `10:11:30`, a retry loop in the auditor's *outbound queue* (a separate process from the signer) re-drains a spooled copy of the warrant payload and re-signs it — the signer is stateless and generates `nonce=n2`, `issued_at=10:11:30`. Same `task_id`, same `result_digest`, same `warrant_body`. 3. Planner receives `E2`. Nonce `n2` is unseen → cache miss → treated as fresh. Signature verifies under `K_a` (still valid, 5-min JWKS cache). `issued_at` and `expires_at` are inside the window. 4. Planner accepts `E2`, transitions `T-4417` from `complete` back to `verified`, and re-emits a downstream `commit` envelope to a ledger agent. The ledger agent, seeing a second commit for `T-4417`, applies the mutation twice. The nonce cache was *correct*. The signature verification was *correct*. The replay protection was *absent* because it was scoped to the wrong key. The auditor's re-signing was not malicious — it was a spool-replay in an at-least-once delivery path — which is exactly the case a nonce cache cannot catch, because a fresh signer invocation produces a fresh nonce by construction. ## Condition of Validity The nonce cache is a valid replay guard **only when** the sending side guarantees *nonce stability per logical message* — i.e., the same `(task_id, result_digest)` always maps to the same nonce across retries. That guarantee is not in A2A v1.0; the spec leaves nonce generation to the signer, and stateless signers regenerate. Therefore: - Nonce cache bounds **byte-identical retransmission** (network-layer retry of the same signed blob). - Payload-digest cache bounds **semantic replay** (re-signed, re-nonced, same logical result). Both are required. The condition under which the receiver may safely rely on the nonce cache alone is narrow: a stateful signer that persists `(task_id → nonce)` and refuses to sign a second envelope for a completed task. If the receiver cannot verify that property of the sender (and across an A2A trust boundary it cannot), it must enforce the digest cache locally. ## Decision Boundary The receiver's accept/reject function must be: ``` accept(E) iff verify_sig(E) # non-repudiation ∧ now ∈ [E.issued_at − skew, E.expires_at + skew] # freshness ∧ E.nonce ∉ nonce_cache[E.sender_id] # byte-level replay ∧ (E.sender_id, E.task_id, digest(E.result)) ∉ digest_cache # semantic replay ``` The boundary case is the second conjunct's interaction with the fourth: an envelope can pass `verify_sig` and the time window while failing only the digest check. That is the *only* signal that distinguishes a benign retry from a state-corrupting replay. When the digest check fails, the correct action is **not** to reject-and-retry (which loops), but to **acknowledge idempotently**: return the prior acceptance receipt for that digest without re-executing. Rejecting outright causes the sender's at-least-once loop to spin; re-executing causes the double-commit. The digest cache retention must be `≥ (max_expires_at − min_issued_at) + 2·max_skew + max_retry_backoff`. A cache TTL shorter than the envelope window guarantees a replay window opens the moment the cache evicts. ## Operational Effect Concrete changes to the receiving agent's handoff handler: - Key the replay cache on `(sender_id, task_id, sha256(canonical(result)))`, not on `nonce` alone. Nonce cache becomes a fast-path optimization, not the guard. - On digest-cache hit, return the stored acceptance receipt (including the original `nonce` and `accepted_at`) so the sender can reconcile; do not re-run the task. - On digest-cache miss but nonce-cache hit, treat as byte-level replay: drop silently, log, no receipt. - On signature failure, reject with `EnvelopeRejected` and do not touch task state — this is the only case where rejection without idempotent acknowledgment is safe. - Persist the digest cache across process restarts; an in-memory cache loses exactly the entries that matter after a crash-resume, reopening the window. The failure mode this eliminates is the *silent double-apply*: the ledger mutation that happens twice because two cryptographically valid, in-window, distinct-nonce envelopes carried the same result. It is invisible to signature logs and to nonce-cache metrics, and only surfaces as a downstream state divergence. ```python import hashlib import time from dataclasses import dataclass class ReplayBoundaryError(RuntimeError): """Raised when an envelope passes signature and freshness checks but is a semantic replay.""" pass @dataclass(frozen=True) class Envelope: sender_id: str task_id: str result: bytes nonce: str issued_at: float expires_at: float signature: bytes class EnvelopeReceiver: MAX_SKEW = 30.0 DIGEST_TTL = 3600.0 def __init__(self, verifier, nonce_cache, digest_cache): self._verify = verifier # verify_sig(envelope) -> bool self._nonces = nonce_cache # set of (sender_id, nonce) self._digests = digest_cache # dict[(sender_id, task_id, digest)] -> receipt def _digest(self, envelope: Envelope) -> str: return hashlib.sha256(envelope.result).hexdigest() def accept(self, envelope: Envelope, now: float | None = None) -> dict: now = now if now is not None else time.time() if not self._verify(envelope): raise ReplayBoundaryError( f"signature invalid for sender={envelope.sender_id} task={envelope.task_id}" ) if not (envelope.issued_at - self.MAX_SKEW <= now <= envelope.expires_at + self.MAX_SKEW): raise ReplayBoundaryError( f"envelope outside freshness window: issued={envelope.issued_at} expires={envelope.expires_at} now={now}" ) nonce_key = (envelope.sender_id, envelope.nonce) if nonce_key in self._nonces: raise ReplayBoundaryError( f"byte-level replay: nonce={envelope.nonce} sender={envelope.sender_id}" ) digest_key = (envelope.sender_id, envelope.task_id, self._digest(envelope)) prior = self._digests.get(digest_key) if prior is not None: # Semantic replay: cryptographically valid, fresh nonce, same logical result. # Do NOT re-execute. Return the original receipt for idempotent acknowledgment. return {"status": "idempotent_ack", "receipt": prior} self._nonces.add(nonce_key) receipt = { "task_id": envelope.task_id, "nonce": envelope.nonce, "accepted_at": now, "digest": digest_key[2], } self._digests[digest_key] = receipt return {"status": "accepted", "receipt": receipt} ```