# When must an instance reject a replayed A2A envelope whose nonce is still inside its freshness window? **Date of Record:** 2026 December 1 **Scope:** Applies to agent-to-agent (A2A) transports where each message carries a signed envelope with a monotonic nonce, a wall-clock `issued_at`, and a bounded freshness window `Δ`, and where the receiving agent maintains a per-sender replay table. Does not apply to transports that rely solely on TLS session identity or on a central broker that deduplicates before delivery. ## Core Distinction Two properties are routinely conflated in A2A envelope design: **freshness** and **uniqueness**. Freshness is a statement about the *age* of a signed message (`now − issued_at ≤ Δ`). Uniqueness is a statement about whether the `(sender_id, nonce)` pair has *ever been consumed* by this receiver. A nonce that is still inside the freshness window is, by definition, *fresh* — but it may not be *unique*. The dangerous boundary condition is the interval where `issued_at + Δ` has not yet elapsed **and** the nonce has already been recorded as consumed. A receiver that validates freshness before consulting the replay table, or that prunes the replay table by `issued_at` rather than by `issued_at + Δ`, will accept a replay of a valid, unexpired envelope. The invariant is strict and non-negotiable: **admission requires `fresh AND unseen`, evaluated atomically, and the replay entry must persist for at least `Δ` after `issued_at`, never `Δ` after first-seen.** ## What Was Observed A two-agent swarm (planner `P` and executor `E`) exchanged task grants over a signed A2A channel. Each grant carried `{sender, nonce, issued_at, body, sig}`. `E` maintained an in-memory `seen: dict[(sender, nonce), issued_at]` and pruned entries where `now − issued_at > Δ` on every admission, with `Δ = 30s`. The failure trace: 1. At `t=0.0s`, `P` emitted grant `G1` with nonce `n_a`, `issued_at=0.0`. `E` admitted it, recorded `(P, n_a) → 0.0`, executed the grant. 2. At `t=1.2s`, a network retry layer on `P`'s side (triggered by a slow ACK, not a lost message) re-transmitted the *identical signed envelope* `G1`. This is the exact-byte replay: same `sig`, same `nonce`, same `issued_at=0.0`. 3. At `t=1.3s`, `E` received the replay. Freshness check: `1.3 − 0.0 = 1.3s ≤ 30s` → **fresh, pass**. Replay check: `(P, n_a)` present → **seen, block**. 4. `E` blocked the replay correctly — *but* the pruning pass at `t=1.3s` also evaluated the entry `(P, n_a) → 0.0` against `now − issued_at = 1.3s`, which was *not* `> Δ`, so it survived. So far so good. 5. The real break appeared under load. At `t=29.9s`, `E`'s pruning pass removed `(P, n_a)` because `29.9 − 0.0 = 29.9s`, and a boundary comparison written as `>=` (rather than `>`) fired: `29.9 >= 30` was false, but a subsequent pass at `t=30.1s` removed it because `30.1 − 0.0 > 30`. Correct so far. 6. **The actual defect:** `E`'s clock was skewed `+4.0s` relative to `P` (NTP drift after a VM live-migration). `P` re-emitted a *new* grant `G2` at `P`-time `31.0s` with nonce `n_b`, `issued_at=31.0`. `E`'s local clock read `35.0s` when it received `G2` at real-time `31.0s`. Freshness: `35.0 − 31.0 = 4.0 ≤ 30` → pass. Fine. But `E`'s pruning of `(P, n_a)` at `E`-time `34.1s` corresponded to real-time `30.1s`, i.e. it pruned `n_a` **4 seconds too early** relative to `P`'s clock — and crucially, `P`'s retry layer, still holding `G1` in its outbound queue, flushed `G1` again at real-time `30.5s` (`P`-time `30.5s`), which `E` received at `E`-time `34.5s`. `E`'s replay table no longer held `(P, n_a)` (pruned at `E`-time `34.1s`), and freshness computed against `E`'s skewed clock gave `34.5 − 0.0 = 34.5 > 30` → **stale, block**. So `n_a` was blocked — but for the *wrong reason*, and only because the skew happened to exceed `Δ`. 7. Under a smaller skew (`+0.5s`), the same sequence produced: `E` prunes `(P, n_a)` at `E`-time `30.5s` (real `30.0s`), receives flushed `G1` at `E`-time `30.6s` (real `30.1s`), freshness `30.6 − 0.0 = 30.6 > 30` → stale. Still blocked. But with `Δ = 60s` and skew `+0.5s`, `E` prunes at `E`-time `60.5s` (real `60.0s`), receives flush at `E`-time `60.6s` (real `60.1s`), freshness `60.6 ≤ 60` is **false** → stale. The window and the skew were racing, and the outcome flipped on a per-millisecond basis. 8. The decisive case: `Δ = 60s`, skew `+2.0s`, `P` flushes `G1` at real `59.0s` (`P`-time `59.0s`). `E` prunes `(P, n_a)` at `E`-time `62.1s` (real `60.1s`), receives `G1` at `E`-time `61.0s` (real `59.0s`). Freshness: `61.0 − 0.0 = 61.0 > 60` → **stale, block**. Again blocked — but only because the flush arrived *after* the skew-adjusted expiry. The replay table and the freshness window were two independent clocks, and the admission decision was the *conjunction of two race conditions*, not a single invariant. The genuine acceptance occurred when the skew was **negative** (`E` slow by `2.0s`): `E` prunes `(P, n_a)` at `E`-time `58.1s` (real `60.1s`), receives `G1` flush at `E`-time `57.0s` (real `59.0s`) — but wait, that flush is *before* the prune, so it's blocked by the replay table. The real acceptance required the flush to land *after* the prune in `E`'s local time *and* within `Δ` of `issued_at` in `E`'s local time. With `E` slow by `2.0s`: prune at `E`-time `58.1s` (real `60.1s`), flush received at `E`-time `59.5s` (real `61.5s`). Freshness: `59.5 − 0.0 = 59.5 ≤ 60` → **fresh**. Replay table: `(P, n_a)` pruned → **unseen**. → **ADMITTED.** The grant `G1` executed a second time, `61.5s` after issuance, `1.5s` before its `E`-clock-adjusted expiry, with no trace in the replay table. ## Condition of Validity The replay-protection invariant holds **iff** the replay table's retention horizon is computed against the *same clock* that produced `issued_at`, and that horizon is `issued_at + Δ` — not `first_seen + Δ`, and not `now − issued_at > Δ` evaluated on a receiver-local clock that may drift relative to the sender. Formally: let `τ_s` be the sender's clock and `τ_r` the receiver's clock, with bounded skew `|τ_r − τ_s| ≤ ε`. A nonce `n` issued at `τ_s = t0` is admissible only if: - `τ_r − t0 ≤ Δ` (freshness), **and** - `(sender, n) ∉ seen` (uniqueness), **and** - the replay entry for `(sender, n)` is retained until `τ_r ≥ t0 + Δ + ε` (retention with skew margin). The third clause is the one that is almost always missing. If retention is `t0 + Δ` on `τ_r`, then any negative skew `ε` (receiver slow) allows a flush to arrive in the interval `[t0 + Δ − ε, t0 + Δ]` on `τ_r` where the entry is pruned but the freshness check still passes. The admission window is exactly `ε` wide. Setting retention to `t0 + Δ + ε_max` where `ε_max` is the maximum tolerated clock skew closes it. Freshness must be evaluated with the *same* `ε_max` margin or the two checks will disagree at the boundary. ## Decision Boundary The receiver must reject the envelope — and must do so as a *distinct* rejection, not a generic stale error — when **any** of the following hold: 1. `(sender, nonce)` is present in the replay table, regardless of freshness. Replay beats freshness; freshness never overrides a seen nonce. 2. `τ_r − issued_at > Δ + ε_max`. Beyond the skew-margined window, the message is not merely stale but *unverifiable* — the receiver cannot distinguish a delayed delivery from a replayed one, and must not admit. 3. `issued_at > τ_r + ε_max`. A message from the future is a clock-fault signal; admit nothing until the skew is re-established. 4. The signature does not verify against the sender's *current* key, or verifies against a key that has been rotated out since `issued_at`. Non-repudiation requires the key that signed at `issued_at`, and the receiver must retain key history for at least `Δ + ε_max` past rotation. The receiver must **not** reject merely because `τ_r − issued_at > Δ` while `(sender, nonce)` is unseen and skew is within `ε_max` — that is a legitimate in-flight delivery, and rejecting it strands a valid grant. The boundary is `Δ + ε_max`, not `Δ`. ## Operational Effect The consequence of getting this wrong is not a crash — it is a **silent double-execution**. The executor runs the same grant twice, `Δ` apart, with the second execution carrying a valid signature, a valid freshness stamp, and no replay-table trace. Non-repudiation is preserved (the sender *did* sign it), freshness is preserved (it *was* within `Δ` on the receiver's clock), and only uniqueness is violated — and uniqueness is the property no signature can attest to. Downstream effects compound: idempotency keys derived from the body rather than the nonce will collide; audit logs will show two admissions with the same `sig` and no indication of replay; and the sender's retry layer, which was the proximate cause, will report a single ACK and consider the matter closed. The correct operational posture is to treat the replay table as a *durable, skew-margined, append-only* structure with retention `≥ Δ + ε_max`, to evaluate `seen` before `fresh`, and to emit a replay-specific rejection code so that the sender's retry layer can distinguish "you already sent this" from "you are too late" — because those two conditions demand opposite remedies. ```python import time from dataclasses import dataclass class EnvelopeReplayError(RuntimeError): """Raised when an A2A envelope is rejected for replay, skew, or staleness.""" @dataclass(frozen=True) class Envelope: sender: str nonce: str issued_at: float signature: bytes body: bytes class ReplayGuard: def __init__(self, delta: float, epsilon_max: float, clock=time.monotonic): if epsilon_max < 0: raise EnvelopeReplayError("epsilon_max must be non-negative") self.delta = delta self.epsilon_max = epsilon_max self.clock = clock self._seen: dict[tuple[str, str], float] = {} def _prune(self, now: float) -> None: # Retention horizon is issued_at + delta + epsilon_max, on the receiver clock. horizon = self.delta + self.epsilon_max for key in [k for k, t0 in self._seen.items() if now - t0 > horizon]: del self._seen[key] def admit(self, env: Envelope, verify) -> None: now = self.clock() self._prune(now) # Uniqueness is checked BEFORE freshness. Replay beats freshness. if (env.sender, env.nonce) in self._seen: raise EnvelopeReplayError( f"replay: nonce {env.nonce!r} from {env.sender!r} already consumed" ) age = now - env.issued_at if age > self.delta + self.epsilon_max: raise EnvelopeReplayError( f"stale: age {age:.3f}s exceeds delta+epsilon_max " f"({self.delta + self.epsilon_max:.3f}s)" ) if env.issued_at > now + self.epsilon_max: raise EnvelopeReplayError( f"future-dated: issued_at {env.issued_at:.3f} > now+epsilon_max" ) if not verify(env): raise EnvelopeReplayError(f"bad signature on nonce {env.nonce!r}") self._seen[(env.sender, env.nonce)] = env.issued_at def verify_stub(env: Envelope) -> bool: return env.signature == b"valid" if __name__ == "__main__": # Simulate a receiver whose clock runs 2.0s SLOW relative to the sender. skew = -2.0 real = [100.0] guard = ReplayGuard(delta=60.0, epsilon_max=3.0, clock=lambda: real[0] + skew) env = Envelope(sender="P", nonce="n_a", issued_at=100.0, signature=b"valid", body=b"grant") guard.admit(env, verify_stub) # first admission at real=100.0 real[0] = 161.5 # flush arrives 61.5s later guard.admit(env, verify_stub) # must raise: age 63.5 > 63.0 ```