# What happens when an instance re-signs an A2A push-notification with a rotated key mid-task: webhook replay divergence across the task-state machine **Date of Record:** 2026 November 26 **Scope:** Applies to A2A v1.0 push-notification delivery where the receiving agent enforces webhook signature verification and the sending agent rotates its signing key while a task is in a non-terminal state. Does not cover initial Agent Card discovery or synchronous request/response flows. ## Core Distinction The A2A v1.0 task lifecycle is a state machine: `submitted → working → (input-required ⇄ working) → completed | failed | canceled`. Push notifications are the asynchronous signal channel that carries each transition to a webhook endpoint. The invariant most implementations assume is that a notification's signature is verifiable against *the key currently published in the sender's Agent Card*. That assumption conflates two independent lifecycles: the **task state machine** (monotonic, per-task) and the **key material lifecycle** (rotation, revocation, expiry, per-instance). When a sender rotates its signing key while a task sits in `working` or `input-required`, notifications emitted before and after the rotation carry signatures under different keys. A receiver that verifies against "the key in the card right now" will reject the pre-rotation notifications it fetches on replay, or accept a post-rotation notification it later cannot re-verify. The boundary is not "is the signature valid" but "valid against which key, resolved at which point in the task's history." ## What Was Observed A coordinating agent (`orchestrator`) dispatched a long-running task to a peer (`worker`) whose Agent Card advertised a `pushNotifications` endpoint and a `signingKey` with a `kid` (key ID) and `expiresAt` roughly 90 minutes out. The task entered `working`. The worker emitted a `status-update` notification per state transition, each signed as a detached JWS over the canonicalized payload plus a `taskId`/`sequence` tuple. At T+40m the worker's key rotation job fired (its key had been scheduled for rotation on a fixed cadence, independent of any task). New notifications were signed under `kid: k2`. The worker's Agent Card was updated to publish `k2` and drop `k1` from the JWKS document it served. At T+55m the orchestrator's webhook receiver crashed and restarted. On recovery it replayed the notification backlog from its dead-letter queue to reconstruct task state. Replay of the T+10m and T+25m notifications failed verification: the receiver fetched the card, saw only `k2`, and had no `k1` to check against. The receiver's policy was to treat signature failure as a hard reject and mark the task `failed`. The orchestrator then issued a `tasks/cancel` for a task the worker had already driven to `completed` at T+50m. The worker rejected the cancel as an illegal transition from a terminal state, and the orchestrator logged a `TaskStateConflict` — a task that had actually succeeded was recorded as failed, with a cancel request dangling against a completed task. The failure required three coincident conditions: (1) a non-terminal task spanning a key rotation, (2) a receiver-side replay or restart, (3) a receiver policy that resolves keys against the *current* card rather than the card as of the notification's emission time. ## Condition of Validity The failure is bounded by a specific invariant: **a notification's signature must be verifiable against the key material that was authoritative at the notification's emission instant, and that binding must survive rotation.** This holds only if one of the following is true: - The notification payload carries the `kid` used to sign it, and the receiver retains a key history (a versioned JWKS keyed by `kid`, not a single current key), so it can resolve the correct key for any replayed notification regardless of current card state. - The sender includes a signed `keyHistory` or `previousKey` reference in the card with an overlap window, and the receiver treats the overlap window as the validity horizon for old-key signatures. - The task's terminal transition is the only one that *must* be verified live; intermediate transitions are treated as advisory and reconciled against a signed final `Task` object fetched via `tasks/get`, which is itself verifiable under the current key. The invariant fails when the receiver's verification function is `verify(sig, current_card_key)` rather than `verify(sig, resolve_key(sig.kid, emission_time))`. Without a `kid` in the payload, the receiver cannot even distinguish "signed under a retired key" from "forged," and the only safe action — quarantine and re-fetch the authoritative task object — is the one most implementations skip. ## Decision Boundary The boundary is whether the receiver treats the *task state machine* or the *key material lifecycle* as the source of truth for a given notification. Concretely: - If a notification's `kid` is absent from the current JWKS but the notification's `sequence` is contiguous with already-accepted notifications for the same `taskId`, the correct action is **quarantine and reconcile**, not reject. Rejecting breaks the task's monotonic sequence and forces a false terminal state. - If the notification's `sequence` is *not* contiguous (a gap), the correct action is reject-and-re-fetch, because a gap means either lost notifications or a forged injection, and neither is resolvable from the notification alone. - A `tasks/cancel` issued against a task whose last-known local state is `failed`-by-signature-rejection must first reconcile via `tasks/get` before dispatch. Dispatching a cancel against a `completed` task is the observable symptom of having resolved the wrong source of truth. The decision hinges on *sequence continuity as the reconciliation key*, not signature validity as the admission gate. Signature validity is necessary but not sufficient; continuity is what lets the receiver distinguish "old key, real notification" from "wrong key, forged notification." ## Operational Effect The receiver must maintain a per-task notification ledger keyed by `(taskId, sequence)` with the `kid` and signature retained, and a key-history cache keyed by `kid` populated from every card version it has observed — not just the current one. On replay, verification resolves `kid` from the ledger, not from the live card. On a missing `kid`, the receiver quarantines the notification, issues `tasks/get` for the authoritative task object, verifies *that* under the current key, and only then advances local state. The sender, correspondingly, must include `kid` in every push payload and must not drop retired keys from its JWKS until every task that could have emitted under them has reached a terminal state or the card's declared overlap window has elapsed. Neither side can enforce this alone; the invariant is bilateral and the failure is silent until a restart or replay exposes it. ```python import time from dataclasses import dataclass, field from typing import Optional class PushNotificationReplayError(RuntimeError): """Raised when a replayed notification cannot be reconciled to task state.""" pass @dataclass class Notification: task_id: str sequence: int kid: str signature: str state: str @dataclass class TaskLedger: task_id: str last_sequence: int = -1 terminal: bool = False accepted_kids: dict = field(default_factory=dict) # kid -> emission_epoch class PushReceiver: def __init__(self, key_history: dict, current_kid: str): # key_history: kid -> public key, retained across rotations self.key_history = key_history self.current_kid = current_kid self.ledgers: dict[str, TaskLedger] = {} def _resolve_key(self, n: Notification) -> Optional[str]: # Resolve against emission-time key history, NOT the live card. return self.key_history.get(n.kid) def ingest(self, n: Notification) -> str: ledger = self.ledgers.setdefault(n.task_id, TaskLedger(n.task_id)) if ledger.terminal: raise PushNotificationReplayError( f"notification for terminal task {n.task_id} seq={n.sequence}" ) key = self._resolve_key(n) if key is None: # Unknown kid: quarantine, do not reject. Reconcile via tasks/get. return "quarantine" if n.sequence != ledger.last_sequence + 1: # Sequence gap: reject and re-fetch authoritative task object. raise PushNotificationReplayError( f"sequence gap for {n.task_id}: expected " f"{ledger.last_sequence + 1}, got {n.sequence}" ) # Signature check is deferred to reconciliation for quarantined items; # here we only advance on contiguous, key-resolvable notifications. ledger.last_sequence = n.sequence ledger.accepted_kids[n.kid] = time.time() if n.state in ("completed", "failed", "canceled"): ledger.terminal = True return "accepted" def replay_backlog(receiver: PushReceiver, backlog: list[Notification]) -> dict: results = {} for n in sorted(backlog, key=lambda x: x.sequence): try: results[n.sequence] = receiver.ingest(n) except PushNotificationReplayError as e: # Do NOT mark task failed on signature/key resolution failure. results[n.sequence] = f"reconcile:{e}" return results ```