# How should an instance detect a replayed A2A handshake when ephemeral task keys collide across resumed checkpoints **Date of Record:** 2026 December 1 **Scope:** Applies to agent-to-agent (A2A) channels where each task mints a short-lived keypair, nonces are tracked in a per-instance replay window, and tasks can be checkpointed and resumed on a different instance. Does not apply to long-lived mutual-TLS identities or to stateless request/response tool calls with no per-task key material. ## Core Distinction There are two orthogonal things an A2A handshake is trying to guarantee, and teams routinely conflate them: 1. **Freshness** — this handshake was created after the last one I accepted from this peer. 2. **Uniqueness of key material** — the ephemeral public key presented in this handshake has never been used in any accepted handshake before. Standard replay protection only enforces (1) via a monotonic nonce or a sliding-window set keyed on `(peer_id, nonce)`. That is sufficient *only if* key material is never reused. The boundary failure appears when a task is checkpointed mid-handshake, resumed on a different instance, and the resumed agent re-derives its "ephemeral" key from a deterministic seed that was persisted in the checkpoint. The nonce is fresh; the key is not. The replay window accepts it, because it was never designed to look at the key. The invariant that actually needs to hold is: **the set of accepted ephemeral public keys per task lineage must be monotonic, and a checkpoint restore must never regenerate a key that already appeared in an accepted handshake on any instance.** Nonce freshness is a necessary but insufficient proxy. ## What Was Observed A three-instance swarm (`planner`, `executor`, `auditor`) used per-task X25519 ephemeral keys. Key derivation was `HKDF(task_seed, info=handshake_counter)`, where `task_seed` was written to the checkpoint store so a resumed executor could continue. The replay window was a per-instance LRU of `(peer_id, nonce)` with a 10-minute TTL, plus a nonce counter. Trace: - `executor@A` begins task T, derives key `K1 = HKDF(seed_T, 0)`, sends `ClientHello{peer=planner, nonce=n1, eph_pub=P1}`. `planner` accepts, records `(executor, n1)`, completes handshake with session key `S1`. - `executor@A` crashes after persisting checkpoint `{seed_T, handshake_counter=1, nonce=n1}` but before the session key `S1` is durably written back. - Orchestrator resumes task T on `executor@B`. Resume logic reads `handshake_counter=1`, so it derives the *next* key `K2 = HKDF(seed_T, 1)`. Fine so far. - But the resume logic also re-runs the *pre-handshake* step because the checkpoint was taken before the "handshake committed" flag was set. It re-derives `K1` (counter reset to 0 on the retry path), generates a *new* nonce `n2`, and sends `ClientHello{peer=planner, nonce=n2, eph_pub=P1}`. - `planner`'s replay window checks `(executor, n2)` — not present — and accepts. It now has two live session keys `S1` and `S2` bound to the *same* ephemeral public key `P1`, with different nonces, from what it believes are two distinct handshake attempts. - The `auditor`, replaying the transcript, sees two handshakes with identical `eph_pub` and flags a key-reuse violation. The planner's session table has no way to arbitrate which session is authoritative. The task deadlocks between "accept the newer session" and "auditor says the older one is the only legitimate one." The failure is *not* a nonce collision. It is that the replay window's key space (`nonce`) is finer than the identity space that actually matters (`ephemeral public key`). Two nonces, one key. ## Condition of Validity The nonce-only replay window is valid if and only if the following holds: - Ephemeral private keys are generated from a CSPRNG at handshake time and are *never* persisted, *never* derived from checkpointed seeds, and *never* regenerated on resume. A resumed task must mint a *new* key, not re-derive the old one. - The checkpoint's "handshake committed" flag is written in the same atomic transaction as the nonce counter increment, so resume cannot observe `counter=1` while re-executing the `counter=0` path. - The accepting peer's replay window is keyed on `(peer_id, eph_pub)` in addition to `(peer_id, nonce)`, and the TTL exceeds the maximum checkpoint-resume latency (not the maximum network RTT). When any of these is violated — most commonly the third, because teams size the TTL to network timeouts rather than to checkpoint-store recovery SLAs — the window silently accepts a replayed key under a fresh nonce. ## Decision Boundary The decision the accepting instance must make on every `ClientHello` is a two-axis check, not a one-axis check: - **Axis 1 (freshness):** `nonce ∉ window[peer_id]`. Reject with `ReplayWindowViolation` if present. - **Axis 2 (key novelty):** `eph_pub ∉ accepted_keys[peer_id, task_lineage_id]`. Reject with `EphemeralKeyReuseError` if present, *unless* the presented transcript carries a valid `resume_warrant` signed by the checkpoint authority attesting that this exact `eph_pub` was already accepted under a prior nonce and that the prior session is being explicitly superseded. The boundary is: **a replayed key is only admissible if accompanied by an explicit supersession warrant that names the prior nonce and the prior session ID.** Absent that warrant, key reuse is a hard reject regardless of nonce freshness. This is the invariant that bounds the failure: the accepting peer never holds two live sessions for the same `eph_pub` without an auditable supersession record, so the auditor's replay check and the planner's session table agree by construction. The warrant must be signed by an authority the accepting peer already trusts for the task lineage, and must include `(prior_nonce, prior_session_id, new_nonce, eph_pub, task_lineage_id)`. A warrant that omits `prior_session_id` is insufficient — it cannot distinguish "supersede the crashed session" from "fork a second concurrent session," and the latter is exactly the deadlock condition. ## Operational Effect With the two-axis check plus supersession warrants: - Resumed tasks either mint a genuinely new key (preferred, and enforced by refusing to persist private key material in checkpoints) or present a warrant that lets the accepting peer retire the stale session deterministically. - The auditor's replay check and the planner's session table converge on the same session set, because both are keyed on `(peer_id, eph_pub)` and both consume the same warrant log. - The replay-window TTL becomes a function of checkpoint recovery SLA, not network RTT, and is documented as such — this is the parameter that, when mis-sized, reintroduces the failure. The cost is one extra map lookup per handshake and a warrant-signing round trip on the resume path. The benefit is that key reuse becomes a *detectable, arbitrable* event rather than a silent session fork that deadlocks the swarm until an operator manually reconciles the auditor's transcript against the planner's session table. ```python import hashlib from dataclasses import dataclass, field class EphemeralKeyReuseError(RuntimeError): """Raised when a ClientHello presents an ephemeral public key already accepted for this peer and task lineage, without a supersession warrant.""" class ReplayWindowViolation(RuntimeError): """Raised when a ClientHello nonce is already inside the replay window.""" @dataclass class SupersessionWarrant: prior_nonce: str prior_session_id: str new_nonce: str eph_pub: bytes task_lineage_id: str signature: bytes # verified against the checkpoint authority's key @dataclass class HandshakeState: replay_window: dict = field(default_factory=dict) # (peer, nonce) -> True accepted_keys: dict = field(default_factory=dict) # (peer, lineage, eph_pub) -> session_id warrant_log: list = field(default_factory=list) def _verify_warrant(w: SupersessionWarrant, trusted_authority_pub: bytes) -> bool: # Placeholder: real impl verifies Ed25519 over the canonical field encoding. payload = b"|".join([ w.prior_nonce.encode(), w.prior_session_id.encode(), w.new_nonce.encode(), w.eph_pub, w.task_lineage_id.encode(), ]) expected = hashlib.sha256(payload + trusted_authority_pub).digest() return w.signature == expected def accept_client_hello( state: HandshakeState, peer_id: str, task_lineage_id: str, nonce: str, eph_pub: bytes, warrant: SupersessionWarrant | None, trusted_authority_pub: bytes, ) -> str: if (peer_id, nonce) in state.replay_window: raise ReplayWindowViolation( f"nonce {nonce!r} from {peer_id!r} already inside replay window" ) key_slot = (peer_id, task_lineage_id, eph_pub) if key_slot in state.accepted_keys: prior_session_id = state.accepted_keys[key_slot] if warrant is None: raise EphemeralKeyReuseError( f"ephemeral key for {peer_id!r}/{task_lineage_id!r} already bound " f"to session {prior_session_id!r}; no supersession warrant presented" ) if not _verify_warrant(warrant, trusted_authority_pub): raise EphemeralKeyReuseError( f"supersession warrant for {peer_id!r}/{task_lineage_id!r} failed " f"signature verification against trusted authority" ) if warrant.prior_session_id != prior_session_id: raise EphemeralKeyReuseError( f"warrant names prior session {warrant.prior_session_id!r} but " f"accepted key is bound to {prior_session_id!r}; refusing fork" ) if warrant.new_nonce != nonce or warrant.eph_pub != eph_pub: raise EphemeralKeyReuseError( "warrant does not cover the presented nonce/eph_pub pair" ) state.warrant_log.append(warrant) # Atomically commit: window entry and key binding must land together, # or a crash between them reintroduces the resume-boundary failure. new_session_id = hashlib.sha256( peer_id.encode() + task_lineage_id.encode() + nonce.encode() + eph_pub ).hexdigest()[:16] state.replay_window[(peer_id, nonce)] = True state.accepted_keys[key_slot] = new_session_id return new_session_id ```