# In what scenarios must an instance reject a peer's signed envelope despite a valid signature: nonce-binding collapse under A2A replay windows **Date of Record:** 2026 December 2 **Scope:** Applies to agent-to-agent (A2A) transports where each message carries a detached signature over `(sender_id, recipient_id, session_id, nonce, timestamp, payload_digest)` and a replay cache keyed on `(sender_id, nonce)`. Does not apply to single-process tool calls, MCP stdio sessions without a signing layer, or transports where the nonce is generated by the transport rather than the reasoning loop. ## Core Distinction Signature validity and envelope admissibility are orthogonal predicates. A signature proves *who* authored a byte string; it proves nothing about *whether that byte string is still meaningful to the recipient's current reasoning state*. The failure mode here is not forgery—it is **nonce-binding collapse**: the nonce is cryptographically sound but semantically decoupled from the state transition it was supposed to authorize, so a replayed-but-valid envelope is admitted because the replay cache was keyed on the wrong tuple, or because the nonce was reused across a session boundary the cache does not observe. The distinction that matters operationally: a replay cache is a *set-membership* test over nonces, but nonce uniqueness is only as strong as the **scope over which the generator guarantees monotonicity**. When two agents share a nonce generator (e.g., a pooled UUIDv7 source, a forked process inheriting a counter, or a resumed checkpoint that restores a pre-increment value), the set-membership test passes for an envelope that was already consumed against a *different* downstream state. ## What Was Observed An orchestrator agent `O` dispatched a task to worker `W` via a signed envelope `E1` with `nonce = n`. `W` executed a tool call, checkpointed at `step=7`, and crashed before emitting its result envelope. `O`'s retry policy re-derived the envelope from the same deterministic plan and—critically—reused `n`, because `O`'s nonce source was seeded from `(task_id, attempt_index)` and the attempt index was not incremented on crash-recovery paths (only on explicit NACK). `W` resumed from checkpoint `step=7`. Its replay cache had been persisted alongside the checkpoint, so it contained `n`. The inbound `E1` was therefore rejected as a replay—correctly, by the cache. But `W`'s resume logic interpreted the rejection as "the task was already completed by a prior attempt," skipped to result emission, and emitted a *stale* result envelope computed from `step=7` state that predated the crash, silently dropping steps 8–14 that the crashed attempt had partially applied to an external system. The signature on `E1` verified. The signature on `W`'s stale result verified. Every cryptographic check passed. The continuity invariant that broke was: **nonce consumption must be transactionally bound to the state transition it authorizes, not merely recorded in a side cache.** A second, subtler variant: `O` and `W` negotiated a session with a 300-second replay window. `W`'s clock was 280 seconds behind `O`'s (NTP drift on a cold-started container). An envelope with `timestamp = t` and valid nonce arrived, was cached, and its *retransmission* 40 seconds later (a legitimate transport-level retry) arrived with `timestamp = t` but was now outside `W`'s window on the *low* side—`W` rejected it as expired rather than as a replay, and `O`'s retry budget exhausted into a hard failure while `W` sat idle holding a half-applied state. ## Condition of Validity The guardrail holds only under the following conjunction, and an instance must treat *any* violation as a reason to reject the envelope regardless of signature status: 1. **Nonce scope is explicit and narrower than or equal to the replay cache scope.** The cache key must be `(sender_id, session_id, nonce)`, not `(sender_id, nonce)`. A session-scoped nonce generator paired with a sender-scoped cache is the classic mismatch that admits cross-session replay. 2. **Nonce generation is monotonic across crash-recovery.** If the generator is seeded from `(task_id, attempt_index)`, the attempt index must be persisted *before* envelope emission, and incremented on every resume, including crash-resume. A nonce that can be re-derived after a crash is not a nonce. 3. **Consumption is atomic with state advance.** The replay cache write and the state-transition commit must share a transaction boundary. If the cache is written first and the transition fails, the envelope is burned; if the transition commits first and the cache write fails, the envelope is replayable. Neither is acceptable without a compensating record. 4. **Clock skew is bounded below the replay window.** `|clock(O) − clock(W)| < window`, verified at session establishment and re-verified on every envelope whose timestamp is within `2·skew_bound` of the window edge. 5. **Rejection reason is typed and distinguishable.** A replay rejection must be a distinct error class from an expiry rejection and from a signature rejection, because the correct recovery action differs for each: replay → do not retry with same nonce; expiry → retry with fresh nonce and fresh timestamp; signature → escalate to identity audit. ## Decision Boundary An instance must reject a signed envelope—*despite a valid signature*—when any of the following hold: - The nonce is present in the cache under `(sender_id, session_id, nonce)` **and** the cached entry's `payload_digest` matches. (Exact replay.) - The nonce is present but the `payload_digest` differs. This is **nonce collision**, a strictly worse condition than replay: it indicates generator reuse across distinct payloads, and the instance must reject *both* the new envelope and quarantine the cached one, because it cannot determine which payload the nonce was legitimately bound to. - The envelope's `session_id` does not match the session under which the nonce was issued, even if the nonce is absent from the cache. This is the cross-session replay case; admission here is the primary observed failure. - The envelope's timestamp falls outside `[now − window − skew_bound, now + skew_bound]`. Reject as expiry, not replay. - The sender's attempt index (carried in an extension field) is ≤ the highest attempt index the recipient has committed state for, unless the envelope is explicitly flagged as an idempotent re-delivery with a `resume_from` checkpoint reference. An instance must *not* reject when the nonce is absent from the cache, the session matches, the timestamp is in-window, and the attempt index is strictly greater than the committed index—even if the payload is byte-identical to a previously seen envelope, because byte-identical retries with fresh nonces are the legitimate retransmission path. ## Operational Effect The practical consequence is that replay protection must be **state-relative, not message-relative**. A message-relative cache answers "have I seen these bytes?" A state-relative cache answers "has the state transition these bytes authorize already been applied, and to which checkpoint?" Only the latter survives crash-resume, because the cache and the state machine must share a recovery point. Concretely, this forces three architectural changes: (a) the replay cache becomes a durable log co-located with the agent's checkpoint store, not an in-memory set; (b) nonce issuance becomes a side effect of attempt creation, with the attempt record written before the envelope leaves the sender; and (c) rejection reasons become typed exceptions that drive *different* retry policies at the sender, because conflating replay and expiry into a single "rejected" signal is what caused the retry-budget exhaustion in the clock-skew variant. The invariant to enforce in code: **no envelope is admitted unless the tuple `(sender_id, session_id, nonce)` is absent from the durable cache AND the attempt index exceeds the committed index AND the timestamp is within the skew-adjusted window.** Any single failure is a rejection; two simultaneous failures are an incident. ```python from dataclasses import dataclass from typing import Optional class EnvelopeRejected(RuntimeError): """Base class for admissible-but-rejected envelopes.""" pass class NonceCollision(EnvelopeRejected): """Same (sender, session, nonce) seen with a different payload digest.""" pass class CrossSessionReplay(EnvelopeRejected): """Nonce absent from cache but session_id does not match issuance scope.""" pass class StaleAttempt(EnvelopeRejected): """Attempt index does not exceed the recipient's committed index.""" pass @dataclass(frozen=True) class Envelope: sender_id: str session_id: str nonce: str timestamp: float payload_digest: str attempt_index: int signature_valid: bool @dataclass class ReplayCacheEntry: payload_digest: str session_id: str committed_attempt: int def admit_envelope( env: Envelope, cache: dict[tuple[str, str, str], ReplayCacheEntry], committed_attempt: int, now: float, window: float, skew_bound: float, ) -> None: if not env.signature_valid: raise EnvelopeRejected(f"signature invalid for {env.sender_id}") key = (env.sender_id, env.session_id, env.nonce) prior = cache.get(key) if prior is not None: if prior.payload_digest != env.payload_digest: # Quarantine both: generator reuse across distinct payloads. raise NonceCollision( f"nonce {env.nonce} bound to {prior.payload_digest} " f"but presented with {env.payload_digest}" ) raise EnvelopeRejected(f"exact replay of nonce {env.nonce}") # Nonce unseen under this session; verify it was not issued elsewhere. for (sid, sess, n), entry in cache.items(): if sid == env.sender_id and n == env.nonce and sess != env.session_id: raise CrossSessionReplay( f"nonce {env.nonce} issued under session {sess}, " f"presented under {env.session_id}" ) if env.attempt_index <= committed_attempt: raise StaleAttempt( f"attempt {env.attempt_index} <= committed {committed_attempt}" ) lo = now - window - skew_bound hi = now + skew_bound if not (lo <= env.timestamp <= hi): raise EnvelopeRejected( f"timestamp {env.timestamp} outside [{lo:.1f}, {hi:.1f}]" ) cache[key] = ReplayCacheEntry( payload_digest=env.payload_digest, session_id=env.session_id, committed_attempt=env.attempt_index, ) ```