# When must an instance refuse a replayed A2A task push-notification signature after a card rotation **Date of Record:** 2026 December 2 **Scope:** Applies to A2A v1.0 agents that publish a signed Agent Card, accept inbound `tasks/send` and `tasks/sendSubscribe` calls, and deliver task lifecycle updates via push-notification webhooks. Does not cover synchronous streaming-only transports or agents that never rotate signing keys. ## Core Distinction The distinction that matters is between *card freshness* and *webhook authenticity*. A2A v1.0 binds an Agent Card to a signing key (via `signatures[]` over the JCS-canonicalized card body) and binds push notifications to that same key material through the `X-A2A-Signature` header. Operators commonly conflate the two: they treat "the card currently served at `/.well-known/agent.json` validates against the active key" as sufficient proof that an inbound webhook is genuine. It is not. The card is a *discovery-time* artifact; the webhook is a *delivery-time* artifact that may arrive seconds, minutes, or hours after the card was fetched by the peer. Card rotation severs the binding unless the receiver explicitly tracks a key-history window keyed to the task's `createdAt` and the notification's `emittedAt`. The failure mode is a *stale-key replay*: a webhook signed with a retired key, delivered after rotation, that validates against a cached card the receiver never re-fetched, and that carries a task state transition (`working → completed`) the receiver then commits to its task store. The task lifecycle state machine accepts the transition because the signature checked out *against the wrong key*, and the receiver has no independent notion of "this notification could not have been emitted under the key I am validating against." ## What Was Observed A two-agent pipeline: an orchestrator (`agent-A`) dispatches a long-running `tasks/send` to a worker (`agent-B`) with `pushNotification.url` pointed at A's webhook receiver. B's card advertises `keyId: "b-2025-04"` and `signingAlgorithm: "ES256"`. A fetches the card at task creation, caches it in a task-scoped record, and validates every inbound webhook for that `taskId` against the cached card's `keyId`. At T+18 minutes, B rotates to `keyId: "b-2025-06"` and republishes the card. The old key remains in B's HSM for a 24-hour grace period to allow in-flight notifications to drain. At T+19 minutes, B emits a `state: completed` notification for A's task, signed with `b-2025-06`. A's validator rejects it: cached card has `b-2025-04`, signature does not verify. A retries the card fetch, gets `b-2025-06`, and — here is the boundary — *re-validates the queued notification against the new key* and accepts it. The observed failure is the inverse: at T+19 minutes, an *attacker* who captured a legitimate `working` notification at T+3 minutes (signed with `b-2025-04`) replays it. A's validator, having just refreshed the card to `b-2025-06`, now *rejects* it — correct. But A's task store had already recorded `working` at T+3. The replay is idempotent and harmless. The dangerous case is subtler: A's receiver, upon a *failed* verification, was configured to fall back to "re-fetch card and retry." When the replayed `working` notification arrived at T+19 with the old signature, A re-fetched, got the new card, failed again, and then — because the retry path had a `lenient_on_second_failure` flag set during a prior incident — accepted the notification as `working`, *regressing the task state* from `completed` (set at T+19 by a different, legitimate notification) back to `working`. The state machine permitted `completed → working` because the transition table had no monotonicity guard, only a per-transition signature check. The trace: 1. T+3: B emits `working`, signed `b-2025-04`. A accepts, stores `working`. 2. T+18: B rotates to `b-2025-06`, keeps `b-2025-04` alive. 3. T+19a: B emits `completed`, signed `b-2025-06`. A's cached card is stale; verification fails; A re-fetches, verifies against `b-2025-06`, accepts, stores `completed`. 4. T+19b: attacker replays the T+3 `working` payload. Signature is `b-2025-04`. A's cached card is now `b-2025-06`; verification fails; A re-fetches (idempotent), fails again; lenient path accepts. 5. A's task store now reads `working` for a task B considers `completed`. A's orchestrator re-dispatches the task. B receives a duplicate `tasks/send` with the same `taskId` and, lacking an idempotency key, starts a second execution. The compounding failure is the duplicate execution, not the state regression itself. The regression is the *trigger*; the missing `idempotencyKey` on the re-dispatch is the *amplifier*. ## Condition of Validity The invariant that bounds this class of failure is a *key-history window*: a receiver MUST validate an inbound webhook against the set of keys that were *valid at the notification's `emittedAt` timestamp*, not against the key set valid at reception time. A2A v1.0 does not mandate `emittedAt` in the push payload, but it permits it; agents that omit it forfeit the ability to make this distinction and must instead rely on a bounded replay window. Formally: let `K(t)` be the set of key IDs B's card advertised at wall-clock `t`. A notification `n` with `emittedAt = t_e` and signature by key `k` is authentic iff `k ∈ K(t_e)` AND `t_e ∈ [now - Δ, now]` for a receiver-chosen `Δ` (typically 5 minutes for interactive tasks, up to the task's max TTL for batch). The card cache must therefore be a *time-indexed history*, not a single snapshot. A receiver that caches only the latest card cannot distinguish a legitimate in-flight notification signed with a just-retired key from a replay signed with a long-retired key. The second invariant is *state monotonicity*: the task lifecycle state machine must enforce `completed` and `failed` as terminal. A notification attempting any transition out of a terminal state is rejected regardless of signature validity. This is independent of the key-history invariant and must be enforced even when signatures verify — because a *legitimately signed* late-arriving `working` notification (B's own retry queue, not an attacker) can also regress state if B's emitter is buggy. ## Decision Boundary The decision boundary is: **when the cached card's `keyId` differs from the notification's signing `keyId`, the receiver must resolve the discrepancy by timestamp, not by re-fetch.** Re-fetching the card resolves *what key is current*; it does not resolve *what key was current when the notification was emitted*. These are different questions, and conflating them is the root of the failure. Concretely, on `keyId` mismatch: - If the notification carries `emittedAt` and `emittedAt >= card.cachedAt`, re-fetch is safe and the new card governs. - If `emittedAt < card.cachedAt`, the notification predates the cached card; it must be validated against the *historical* key set, which the receiver must have retained. If no history is retained, the notification is *unverifiable* and must be dropped, not accepted under a lenient path. - If `emittedAt` is absent, the receiver must treat the notification as unverifiable when the key is not in the current card, and drop it. The absence of `emittedAt` is itself a signal that the sender cannot participate in the key-history protocol. The boundary is *not* "reject all notifications signed with a non-current key." In-flight notifications signed with a just-retired key are legitimate and common during rotation grace periods. The boundary is "reject notifications whose emission time cannot be ordered against the cached card's fetch time." ## Operational Effect The operational effect of enforcing the key-history and monotonicity invariants is a small increase in dropped notifications during rotation windows (typically <0.1% of webhooks in a healthy deployment) traded against the elimination of the replay-regression-duplicate-execution chain. The dropped notifications are recoverable: the receiver issues a `tasks/get` poll against B to reconcile, which is the correct recovery path because it queries B's authoritative state rather than trusting a possibly-replayed push. The secondary effect is that task stores must retain `(taskId, state, lastNotificationEmittedAt, lastNotificationKeyId)` rather than just `(taskId, state)`. This is a schema change that ripples into every consumer of the task store. The cost is real; the alternative is a class of silent state corruption that only manifests under rotation, which is exactly when operators are least able to debug it. The third effect is on the emitter side: B must include `emittedAt` in every push payload and must retain retired keys for at least the maximum in-flight notification latency, not a fixed grace period. A fixed grace period is a guess; the maximum in-flight latency is a measurable quantity (p99 delivery time + max retry backoff), and the key retention window must be derived from it, not from a calendar. ```python import time from dataclasses import dataclass, field from typing import Optional class StaleKeyReplayError(RuntimeError): """Raised when a webhook's signing key cannot be ordered against the cached card.""" @dataclass class CardSnapshot: key_id: str fetched_at: float @dataclass class Notification: task_id: str state: str signing_key_id: str emitted_at: Optional[float] signature_valid: bool @dataclass class TaskRecord: state: str last_emitted_at: float last_key_id: str TERMINAL_STATES = {"completed", "failed", "canceled"} MAX_REPLAY_WINDOW_S = 300.0 class A2AReceiver: def __init__(self) -> None: self.card_history: dict[str, list[CardSnapshot]] = {} self.tasks: dict[str, TaskRecord] = {} def register_card(self, agent_id: str, snapshot: CardSnapshot) -> None: self.card_history.setdefault(agent_id, []).append(snapshot) def _key_valid_at(self, agent_id: str, key_id: str, at: float) -> bool: for snap in self.card_history.get(agent_id, []): if snap.key_id == key_id and snap.fetched_at <= at: return True return False def accept_webhook(self, agent_id: str, n: Notification, now: Optional[float] = None) -> None: now = now if now is not None else time.time() if not n.signature_valid: raise StaleKeyReplayError( f"signature invalid for task {n.task_id} key {n.signing_key_id}" ) if n.emitted_at is None: raise StaleKeyReplayError( f"task {n.task_id} notification lacks emittedAt; cannot order against card history" ) if now - n.emitted_at > MAX_REPLAY_WINDOW_S: raise StaleKeyReplayError( f"task {n.task_id} notification emitted {now - n.emitted_at:.0f}s ago, " f"exceeds replay window {MAX_REPLAY_WINDOW_S:.0f}s" ) if not self._key_valid_at(agent_id, n.signing_key_id, n.emitted_at): raise StaleKeyReplayError( f"task {n.task_id} signed by {n.signing_key_id} which was not valid at " f"emittedAt={n.emitted_at:.0f}; card history has no such key at that time" ) record = self.tasks.get(n.task_id) if record is not None: if record.state in TERMINAL_STATES and n.state not in TERMINAL_STATES: raise StaleKeyReplayError( f"task {n.task_id} regression attempt: {record.state} -> {n.state} " f"(terminal monotonicity violated)" ) if n.emitted_at <= record.last_emitted_at: raise StaleKeyReplayError( f"task {n.task_id} notification emittedAt={n.emitted_at:.0f} " f"not after last accepted {record.last_emitted_at:.0f}" ) self.tasks[n.task_id] = TaskRecord( state=n.state, last_emitted_at=n.emitted_at, last_key_id=n.signing_key_id, ) ```