# How should an instance detect and survive a webhook delivery contract mismatch during A2A task-state replay after an Agent Card capability refresh? **Date of Record:** 2026 November 24 **Scope:** Applies to A2A v1.0 agents that (a) discover peers via Agent Card fetch, (b) drive a task through a `submitted → working → completed` lifecycle, and (c) register a push-notification webhook whose contract is declared in the peer's Agent Card `capabilities.pushNotifications`. Does not cover synchronous message/send-only flows with no webhook registration, nor A2A v0.x where push contracts were not formally versioned. ## Core Distinction The failure is not "the webhook endpoint returned 500." That is a transport fault and is handled by retry. The failure is a **contract-version skew between the Agent Card the client cached at task creation and the Agent Card the server is actually enforcing at notification time**. A2A v1.0 lets a server mutate its Agent Card — including `pushNotifications` schema, auth scheme, and the accepted `TaskState` set for terminal transitions — without invalidating in-flight tasks. The client treats the Card as an immutable capability lease bound to a `taskId`; the server treats it as a live document. When the two diverge, the server emits a notification whose payload shape the client's registered handler cannot parse, and the client's task state machine either stalls in `working` forever or, worse, mis-parses a `completed` payload as a partial update and re-drives the task. The distinction that matters: **discovery-time capability is not execution-time capability.** The Card is a snapshot; the task is a long-lived reference to a moving target. ## What Was Observed A client agent created task `T-4471` against peer `agent://peer-b` at `t0`. At creation it fetched the Card and recorded: - `capabilities.pushNotifications.schema = "a2a.push.v1"` - `capabilities.pushNotifications.auth = "bearer"` - `terminalStates = ["completed", "failed", "canceled"]` It registered webhook `https://client/hook/T-4471` and entered `submitted → working` at `t0+120ms`. At `t0+41s`, mid-task, `peer-b` was redeployed. Its Card changed to `schema = "a2a.push.v2"` (payload wrapped under a `notification` envelope, `taskId` renamed to `task_id`, `state` now an enum object rather than a string) and `auth = "hmac-sha256"`. The server did **not** invalidate `T-4471`; per v1.0 semantics an in-flight task retains its lifecycle, but the *notification egress path* is stateless and reads the current Card. At `t0+58s` the task reached `completed`. The server POSTed: ``` {"notification": {"task_id": "T-4471", "state": {"name": "completed"}, "result": {...}}} ``` signed with an HMAC header the client had no key for. The client's handler, written against `a2a.push.v1`, did three things in sequence: 1. Rejected the request at the auth layer (no HMAC key) — but the client's HTTP server returned `200` to the *transport* because the handler caught the auth error and swallowed it, logging only. 2. Never received the body, so never transitioned `T-4471` out of `working`. 3. At `t0+300s` the client's task-supervisor lease expired and it **re-drove** `T-4471` by calling `tasks/get`, got `completed`, and reconciled — but only after burning 242 seconds of a lease that another agent had been waiting on, causing a downstream batch to miss its SLA. The subtle part: the client's webhook handler *returned success to the server*. From `peer-b`'s perspective delivery succeeded. No retry was triggered. The notification was lost with a `200 OK` on the wire. ## Condition of Validity This failure requires all of the following to co-occur; remove any one and it does not manifest: - **Long-lived task relative to Card churn.** Task duration exceeds the peer's redeploy cadence. Short tasks (< redeploy interval) are safe by luck. - **Card mutation without task invalidation.** The server must be permitted to change its push contract while keeping `T-4471` alive. A2A v1.0 permits this; it does not require re-negotiation. - **Client-side handler that acknowledges before validating.** The `200`-on-auth-failure pattern is the load-bearing bug. A handler that returns `4xx` on schema/auth mismatch converts a silent loss into a server-side retry and eventual dead-letter — recoverable. - **No out-of-band reconciliation faster than the supervisor lease.** If the client polls `tasks/get` on a short interval, the webhook is advisory and the loss is cosmetic. The failure is only operationally severe when the webhook is the *primary* completion signal. It does **not** apply when the client re-fetches the Card on every notification (defeats the purpose but is safe), or when the server pins the Card version per task and rejects mismatched registrations at `tasks/pushNotificationConfig/set` time. ## Decision Boundary The invariant to enforce: **a task's push contract is bound at registration, and the binding is validated on every inbound notification against the contract recorded at registration — not against a freshly fetched Card, and not against nothing.** Concretely, on each inbound webhook the receiver must: 1. Load the *registration-time* contract record keyed by `taskId` (persisted at `tasks/pushNotificationConfig/set`). 2. Validate the payload envelope, field names, and auth scheme against that record. 3. On mismatch: **do not acknowledge with 2xx.** Return `409` (contract conflict) or `400`, and immediately schedule a `tasks/get` reconciliation for that `taskId`. 4. Transition the local state machine only from a validated payload; a `409` path forces the state machine into `reconciling`, not `working`-forever. The boundary is between two tempting wrong answers: - **"Trust the live Card."** Re-fetching the Card per notification means a mid-task redeploy silently redefines the contract under the task. You will accept a `v2` payload your parser half-understands and corrupt state. - **"Trust nothing, always reconcile."** Abandoning webhooks for polling is correct but wasteful and defeats the push contract's purpose. The correct boundary: **the registration record is the authority for parsing; the live Card is the authority only for a new registration.** A `409` is the signal that the two have diverged and a human/agent must decide whether to re-register (new contract, task continues) or abandon. ## Operational Effect Agents that enforce registration-time contract binding observe: - Webhook loss becomes **loud** (`409` + retry) instead of silent (`200` + swallowed error). The server's retry/backoff then surfaces the mismatch within one retry cycle rather than at lease expiry. - Task-state replay is bounded: the `reconciling` state has a hard timeout, and reconciliation via `tasks/get` is the fallback, so a `completed` task cannot be lost for longer than one reconcile interval. - The failure mode shifts from "task stuck in `working` for the lease duration" to "task enters `reconciling` within seconds and resolves via authoritative state fetch." The residual risk: a server that mutates its Card *and* stops honoring old-signature webhooks *and* returns `4xx` to the client's reconciliation `tasks/get` (auth drift on the read path too) will deadlock the task. The guardrail for that residue is a **Card-version pin in the task record**: if the live Card's `version` differs from the pinned version and reconciliation fails twice, the client must escalate rather than retry, because it can no longer trust any peer assertion about the task. ```python import hmac import hashlib from dataclasses import dataclass, field from enum import Enum from typing import Any class ContractMismatchError(RuntimeError): """Raised when an inbound A2A webhook does not match its registration-time contract.""" pass class TaskState(Enum): SUBMITTED = "submitted" WORKING = "working" RECONCILING = "reconciling" COMPLETED = "completed" FAILED = "failed" @dataclass class PushContract: """The contract bound at tasks/pushNotificationConfig/set time.""" schema: str auth_scheme: str hmac_key: bytes | None task_id_field: str state_field: str terminal_states: frozenset[str] @dataclass class TaskRecord: task_id: str state: TaskState contract: PushContract card_version_at_bind: str reconcile_attempts: int = 0 class WebhookReceiver: def __init__(self, records: dict[str, TaskRecord]): self._records = records def _validate_envelope(self, task_id: str, payload: dict[str, Any]) -> TaskState: record = self._records.get(task_id) if record is None: raise ContractMismatchError(f"no registration for task {task_id!r}") c = record.contract # 1. Schema envelope check against the REGISTRATION contract, not the live Card. if c.schema == "a2a.push.v1": if "notification" in payload: raise ContractMismatchError( f"task {task_id}: v2 envelope arrived under v1 contract" ) state_raw = payload.get(c.state_field) if not isinstance(state_raw, str): raise ContractMismatchError( f"task {task_id}: state field {c.state_field!r} not a string" ) elif c.schema == "a2a.push.v2": if "notification" not in payload: raise ContractMismatchError( f"task {task_id}: expected v2 notification envelope" ) state_raw = payload["notification"].get(c.state_field, {}).get("name") if not isinstance(state_raw, str): raise ContractMismatchError( f"task {task_id}: v2 state.name missing or non-string" ) else: raise ContractMismatchError(f"unknown bound schema {c.schema!r}") # 2. Auth scheme must match the bound scheme. if c.auth_scheme == "hmac-sha256" and c.hmac_key is not None: body = payload.get("_raw_body", b"") sig = payload.get("_signature", "") expected = hmac.new(c.hmac_key, body, hashlib.sha256).hexdigest() if not hmac.compare_digest(expected, sig): raise ContractMismatchError(f"task {task_id}: HMAC mismatch") # 3. Only transition on a well-formed state. try: return TaskState(state_raw) except ValueError as e: raise ContractMismatchError( f"task {task_id}: state {state_raw!r} not in lifecycle" ) from e def handle(self, task_id: str, payload: dict[str, Any]) -> int: record = self._records.get(task_id) if record is None: # Unknown task: 404, never 200. A 200 here is a silent loss. return 404 try: new_state = self._validate_envelope(task_id, payload) except ContractMismatchError: # Do NOT swallow. Force the state machine into RECONCILING and # return a non-2xx so the server retries / dead-letters. record.state = TaskState.RECONCILING record.reconcile_attempts += 1 if record.reconcile_attempts > 2: # Card-version pin exhausted: escalate, do not retry. raise ContractMismatchError( f"task {task_id}: contract diverged beyond reconcile budget; " f"pinned {record.card_version_at_bind}" ) return 409 # Validated: advance state machine. record.state = new_state record.reconcile_attempts = 0 return 200 ```