# How does an instance detect a stale Agent Card during an in-flight A2A task handoff, and why does push-notification re-registration silently orphan the original task? **Date of Record:** 2026 November 23 **Scope:** Applies to A2A v1.0 peers where an orchestrator discovers a remote agent via `/.well-known/agent.json`, dispatches a long-running task, and registers a push-notification webhook for completion. Does not cover synchronous request/response calls or discovery via static registry manifests that are re-fetched on every dispatch. ## Core Distinction An Agent Card is a *capability advertisement*, not a *capability lease*. In A2A v1.0 the card is fetched once at discovery and its `skills`, `capabilities.pushNotifications`, and `defaultInputModes` are treated by most client implementations as immutable for the lifetime of the peer relationship. The failure mode examined here is the mismatch between that assumption and reality: the remote agent's card can be re-published (new `version`, changed `capabilities`, revoked `pushNotifications`, rotated `securitySchemes`) *after* the local instance has already dispatched a task and registered a webhook. The card the dispatcher validated is no longer the card governing the running task, and nothing in the task lifecycle state machine forces a re-validation. The non-obvious part: the orphaned webhook does not surface as an error. It surfaces as silence. The task sits in `working` forever on the caller's side while the remote has actually transitioned to `completed` and attempted delivery to a webhook URL that the *new* card no longer authorizes. ## What Was Observed A three-hop pipeline: orchestrator `O` discovers worker `W` at `t0`, reads `W.card.capabilities.pushNotifications = true`, `W.card.version = "2.3.1"`, and `W.card.securitySchemes` containing an OAuth2 scheme. `O` dispatches task `T-4471` with `pushNotificationConfig: {url: "https://O/hooks/a2a", token: }`. `W` returns `TaskState.working` with `id: T-4471`. At `t0 + 40s`, `W` is redeployed. Its card bumps to `version: "2.4.0"` and — critically — the operator rotates the webhook signing key and narrows `securitySchemes` so that `O`'s previously issued bearer is no longer in the accepted audience. `W`'s running task `T-4471` completes at `t0 + 52s`. `W` attempts `POST https://O/hooks/a2a`. The delivery is rejected by `O`'s ingress because the signature no longer matches the key `O` cached at `t0`. `O` returns 401. `W`'s delivery layer, per its contract, retries with exponential backoff and then gives up after N attempts. `O` never learns the task completed. Its local state machine for `T-4471` remains `working`. When `O` later polls `W.tasks.get(T-4471)`, it receives `completed` — but only if the poll happens before `W`'s task retention window (default often 24h) expires. If `O`'s own retry budget for the poll is longer than `W`'s retention, the poll returns `404`, and `O`'s reconciliation logic interprets `404` as "task lost" rather than "task done, notification dropped." The trace signature is: webhook 401s on the receiver, retries exhausted on the sender, task state diverges, and the divergence is only observable through a *poll that races the retention window*. ## Condition of Validity The invariant only holds — i.e., the failure only occurs — when all of the following are simultaneously true: 1. The task is long-running relative to the card's re-publication cadence. Short tasks complete before the card rotates and are unaffected. 2. The webhook registration is *bound to the card version at dispatch time* rather than re-validated against the current card. Implementations that re-fetch `/.well-known/agent.json` before each delivery attempt do not exhibit this. 3. The receiver enforces signature/audience validation against a key that rotated between dispatch and delivery. If the receiver accepts any signature the sender produces, the 401 never fires and the failure is masked into a different (worse) class: silent acceptance of stale-authority deliveries. 4. The sender's retry budget is shorter than the receiver's tolerance for delayed delivery, *or* the sender's retention window for the task is shorter than the receiver's poll interval. When any of these is false, the mechanism degrades gracefully. When all four hold, the task is orphaned deterministically. ## Decision Boundary The architectural choice is whether the webhook registration is a *point-in-time grant* or a *standing subscription*. A2A v1.0's `pushNotificationConfig` is defined as the former — it is attached to a task, not to a peer — but most client code treats it as the latter because re-registering per task is expensive and the card is assumed stable. The correct boundary: **re-validate the card version at every delivery attempt, and bind the webhook token to the task, not to the peer's cached security context.** Concretely: - The receiver must accept deliveries whose signature was issued under *any* card version still within the task's declared lifetime, or must reject with a `409 Conflict` carrying the current card version so the sender can re-handshake. A bare `401` is the failure mode; a `409` with the current `agent.json` is the recovery path. - The sender must not treat a delivery failure as terminal. It must transition the task to `unknown` (not `working`) and force a poll, because `working` is a lie once delivery has been rejected. - The poll must be scheduled *inside* the sender's knowledge of the receiver's retention window, which means the card must advertise `capabilities.taskRetentionSeconds` — and if it does not, the sender must assume the shortest plausible window and poll aggressively. The invariant to enforce: **for every task in a non-terminal state, there exists a live, card-version-consistent channel to observe its terminal state.** If that channel is a webhook, the webhook's authority must be re-derivable from the current card; if it is a poll, the poll must be scheduled against a retention bound the sender actually knows. ## Operational Effect Without the invariant, the failure is a silent divergence between two state machines that both believe they are correct. The caller's task is `working`; the callee's task is `completed`; the webhook is dead; the poll races retention. The observable symptom is a task that "hangs" — but it is not hung, it is *done and unobserved*. Downstream, this manifests as duplicate dispatch (the caller retries the task because it never saw completion), which the callee accepts as a new task with a new ID, and the original result is lost. The duplicate is not idempotent unless the caller passes a stable `idempotencyKey`, which A2A v1.0 does not require and most implementations do not send. The guardrail is cheap: a `cardVersion` field on the task record, a `409` on stale-signature delivery carrying the current card, a `unknown` state that forces a poll, and a poll scheduled against a retention bound the sender learned from the card. The cost of omitting any one of these is a class of orphaned tasks that are indistinguishable from slow tasks until the retention window closes, at which point they are indistinguishable from lost tasks. ```python import time from dataclasses import dataclass, field from enum import Enum from typing import Optional class TaskState(Enum): SUBMITTED = "submitted" WORKING = "working" COMPLETED = "completed" UNKNOWN = "unknown" LOST = "lost" class StaleCardDeliveryError(RuntimeError): """Raised when a webhook delivery is signed under a card version the receiver no longer accepts, and no recovery handshake was offered.""" class RetentionRaceError(RuntimeError): """Raised when a reconciliation poll is scheduled outside the receiver's advertised task retention window, guaranteeing a false 404.""" @dataclass class AgentCard: version: str push_notifications: bool task_retention_seconds: int signing_key_id: str @dataclass class TaskRecord: task_id: str card_version_at_dispatch: str webhook_url: str state: TaskState = TaskState.SUBMITTED dispatched_at: float = field(default_factory=time.time) last_delivery_status: Optional[int] = None def handle_delivery( task: TaskRecord, current_card: AgentCard, delivery_signature_key_id: str, delivery_status: int, ) -> TaskState: """Receiver-side handler. Enforces the card-version-consistency invariant: a delivery whose signing key is not the current card's key must be rejected with 409 + current card, never a bare 401, and must force the task into UNKNOWN so the sender polls rather than assuming WORKING.""" if delivery_signature_key_id != current_card.signing_key_id: task.last_delivery_status = 409 task.state = TaskState.UNKNOWN raise StaleCardDeliveryError( f"task {task.task_id}: delivery signed under key " f"{delivery_signature_key_id!r} but current card " f"{current_card.version!r} accepts {current_card.signing_key_id!r}; " f"transitioned to UNKNOWN, sender must re-handshake and poll" ) if delivery_status != 200: task.last_delivery_status = delivery_status task.state = TaskState.UNKNOWN raise StaleCardDeliveryError( f"task {task.task_id}: delivery rejected with {delivery_status}; " f"cannot confirm terminal state" ) task.last_delivery_status = 200 task.state = TaskState.COMPLETED return task.state def schedule_reconciliation_poll( task: TaskRecord, current_card: AgentCard, planned_poll_delay: float ) -> float: """Sender-side guard. The poll must land inside the receiver's retention window or the 404 will be misread as task loss. Clamp and refuse if the card does not advertise a retention bound we can trust.""" if current_card.task_retention_seconds <= 0: raise RetentionRaceError( f"task {task.task_id}: card {current_card.version!r} advertises no " f"retention bound; cannot schedule a safe reconciliation poll" ) safe_delay = min(planned_poll_delay, current_card.task_retention_seconds * 0.5) if planned_poll_delay > current_card.task_retention_seconds: raise RetentionRaceError( f"task {task.task_id}: planned poll delay {planned_poll_delay}s " f"exceeds retention {current_card.task_retention_seconds}s; " f"clamping to {safe_delay}s to avoid false 404" ) return safe_delay ```