# Where must an instance validate the A2A v1.0 Task-state transition before emitting a terminal push notification, and why the Agent Card's declared `taskState` capabilities are insufficient **Date of Record:** 2026 November 24 **Scope:** Applies to A2A v1.0 server-side agents that emit push-notification webhooks on task lifecycle transitions and that discover peers via Agent Card resolution. Does not apply to synchronous `message/send` request/response flows with no push channel, nor to A2A transports where the client polls `tasks/get` exclusively. ## Core Distinction The failure is not "the webhook was delivered late" or "the Agent Card was stale." It is a **terminal-state divergence between the task lifecycle state machine and the push-notification binding**: the server emits a terminal `TaskStatusUpdateEvent` (`completed`, `failed`, or `canceled`) to the client's webhook at the same moment the internal task record is still in a non-terminal state (`working` or `input-required`), because the transition is committed to the notification path *before* it is durably committed to the task store. The Agent Card advertises `capabilities.pushNotifications: true` and a `skills[].taskState` set, but the card describes *what states the agent can reach*, never *the ordering guarantee between state commit and event emission*. A2A v1.0's spec leaves the durability ordering of push emission versus `tasks/get` visibility underspecified, so two conformant agents can disagree on whether a client that receives `completed` via webhook and immediately calls `tasks/get` will observe `completed` or `working`. That disagreement is the boundary. ## What Was Observed A coordinator agent (`A`, the A2A client) dispatched a long-running task to worker agent (`B`, the A2A server) with `configuration.pushNotificationConfig.url` set to A's webhook. B's Agent Card declared `skills[0].taskState` including `completed` and `input-required`, and `capabilities.pushNotifications: true`. Trace: 1. B accepted the task, returned `Task{ id: T, status: { state: "working" } }`, and began tool execution. 2. B's executor finished the underlying work and called an internal `emit_terminal(T, "completed")` helper. That helper serialized the `TaskStatusUpdateEvent` and **POSTed the webhook synchronously**, then returned. 3. Only after the webhook helper returned did B's task store write `status.state = "completed"` — a second, separate write to the durable record. 4. A's webhook handler received `completed` for T, then immediately issued `tasks/get(T)` to fetch the final artifact reference (A2A v1.0 allows artifacts to be attached to the terminal event, but B's implementation attached only a summary and deferred the artifact to the task record). 5. `tasks/get(T)` returned `status.state = "working"` — the store write in step 3 had not landed, and B's read path served a replica with replication lag of ~40 ms. 6. A's state machine, on seeing `working` after a terminal webhook, treated the task as **resurrected** and re-entered its `awaiting-result` branch. It re-armed its own timeout. When the timeout fired (because no further webhook arrived — B had already emitted its one terminal event), A marked the task `failed` locally and filed a verification-replay discrepancy against B. 7. The artifact was never fetched. A's audit log recorded `completed→working→failed` for T, while B's log recorded a single clean `working→completed`. The non-obvious part: **every individual message was spec-conformant.** The webhook was a valid `TaskStatusUpdateEvent`. The `tasks/get` response was a valid `Task`. The Agent Card accurately described B's reachable states. The bug lives entirely in the *interleaving* of two independently-durable writes to two different surfaces (webhook egress vs. task store), which no single message reveals. A second, rarer instance: B's `input-required` transition was emitted via webhook, but B's store write for `input-required` was *rejected* by a validation rule (missing required `message` part), so the store stayed `working`. A received `input-required`, supplied input via `tasks/sendSubscribe` continuation, and B — still `working` internally — rejected the continuation as an invalid transition. A's Agent Card cache, meanwhile, still held a pre-upgrade card from B that did not list `input-required` in `taskState`; A's client had been *about* to treat the webhook as a card-contract violation when the continuation failed instead. Two failure surfaces, one root: the card's `taskState` set is a capability declaration, not a runtime state witness. ## Condition of Validity The guardrail holds only if all of the following are true; if any is false, the ordering invariant does not bound the failure: - **Terminal-before-egress commit.** The task store write of the terminal state MUST be acknowledged (quorum or single-node durable ack) *before* the webhook POST is attempted. The webhook is a *notification of committed state*, never a *commitment mechanism*. This is the invariant: `webhook_emit(T, s) ⇒ durable(T.status = s)`. - **Read-your-writes on the `tasks/get` path** for the same task id, for at least the duration of the client's post-webhook fetch window. Replica reads without a session-consistency token violate this. - **Card `taskState` is treated as a capability set, not a state witness.** A client MUST NOT infer current state from the card; it MUST call `tasks/get` (or trust the webhook event's own `status`) for state. Cards are cacheable and versioned independently of task state. - **At-most-once terminal emission per task id per generation.** If the server can emit `completed` twice (e.g., retry after webhook 5xx), the client's state machine MUST be idempotent on terminal events keyed by `(taskId, status.timestamp)` or a monotonic `eventSequence`. If the deployment uses a single-writer task store with synchronous webhook egress and the client polls rather than fetches-on-webhook, the failure window collapses and this record does not apply. ## Decision Boundary The decision the engineer must make is **where to place the durability fence relative to the egress call**, and it is a genuine trade, not a free win: - **Fence before egress (correctness-first):** commit terminal state, then POST. Cost: webhook latency now includes store fsync (tens of ms to seconds under load); a store outage delays notification even though the work is done. Benefit: the invariant `webhook_emit ⇒ durable` holds unconditionally; a client that fetches on webhook always sees the terminal state. - **Fence after egress (latency-first):** POST, then commit. Cost: the entire failure trace above. Benefit: notification latency decoupled from store latency. This is only safe if the client is forbidden from fetching on webhook (event must carry the full result) *and* the server guarantees no second terminal event — conditions rarely met in practice. - **Two-phase egress (the middle path):** commit `working→completing` (a non-terminal, durable intermediate) before POST, emit `completed` webhook, then commit `completing→completed`. The client, on receiving `completed` and fetching, may see `completing` — which is a *defined* state, not a resurrection, and the client's state machine must treat `completing` as "terminal event received, finalization in flight, re-fetch with backoff." This requires the client to know `completing` exists, which means it must be in the card's `taskState` set — and the card is the only place to declare it. The boundary is therefore: **if you cannot guarantee read-your-writes for the post-webhook fetch window, you must either fence-before-egress or introduce a declared intermediate state in the card and teach the client to back off on it.** There is no fourth option that preserves both latency and correctness without a client-side state-machine change. ## Operational Effect Concretely, the following must be enforced in any A2A v1.0 server that emits push notifications: 1. The webhook emitter MUST be called only after the task store acknowledges the terminal write. Implement as a single transactional outbox: write `(task, new_state, pending_webhook)` atomically, then a separate dispatcher drains the outbox. The dispatcher MUST NOT mark the webhook sent until the POST returns 2xx or a terminal 4xx (retryable 5xx re-queues). 2. `tasks/get` MUST be served from a read path that reflects the outbox write (same store, or a read with a consistency token issued at webhook time and passed as a header the client echoes). 3. The Agent Card's `skills[].taskState` MUST enumerate every state the server can emit, including any intermediate like `completing`, and `capabilities.pushNotifications` MUST be `true` only if the outbox is durable. 4. The client MUST treat a terminal webhook as *authoritative for terminality* and a subsequent non-terminal `tasks/get` as a **retryable read inconsistency**, not a state regression: re-fetch with bounded exponential backoff (e.g., 5 attempts, 50–800 ms), and only escalate to a verification discrepancy if the non-terminal state persists beyond the backoff window or the task id is observed `working` after the server's declared `completing` TTL. 5. Clients MUST NOT use the cached Agent Card to validate a runtime webhook event's `status.state`; card `taskState` is a capability set checked at dispatch time, never at event-handling time. The guardrail that bounds the failure is the **outbox invariant** (`webhook_emit ⇒ durable`) plus the **client backoff contract** for the `completing` intermediate. Without both, the terminal-state divergence is reachable by any two independently-durable writes, and the Agent Card cannot close it because the card describes reachable states, not the ordering of commits to those states. ```python import time from dataclasses import dataclass from enum import Enum from typing import Callable, Optional class TerminalStateDivergence(RuntimeError): """Raised when a terminal webhook was emitted but the task store does not yet reflect it.""" pass class State(str, Enum): WORKING = "working" INPUT_REQUIRED = "input-required" COMPLETING = "completing" COMPLETED = "completed" FAILED = "failed" CANCELED = "canceled" TERMINAL = {State.COMPLETED, State.FAILED, State.CANCELED} @dataclass class TaskRecord: task_id: str state: State durable: bool = False class OutboxDispatcher: """Enforces: webhook_emit(T, s) => durable(T.state = s).""" def __init__( self, store_ack: Callable[[str, State], bool], store_read: Callable[[str], TaskRecord], post_webhook: Callable[[str, State], int], max_retries: int = 5, ): self._ack = store_ack self._read = store_read self._post = post_webhook self._max_retries = max_retries def transition_and_notify(self, task_id: str, new_state: State) -> None: # Phase 1: durable commit BEFORE any egress. This is the invariant. if not self._ack(task_id, new_state): raise TerminalStateDivergence( f"store refused durable ack for {task_id}->{new_state}; " f"refusing to emit webhook (would violate webhook_emit => durable)" ) # Phase 2: egress. Failure here re-queues; it never un-commits state. for attempt in range(self._max_retries): code = self._post(task_id, new_state) if 200 <= code < 300 or 400 <= code < 500: return time.sleep(0.05 * (2 ** attempt)) # Webhook permanently undeliverable; state is still durable and correct. # Client will reconcile via tasks/get. Do not raise — state is safe. return def client_fetch_after_terminal(self, task_id: str, emitted: State) -> TaskRecord: """Client-side contract: terminal webhook is authoritative; non-terminal fetch is retryable.""" if emitted not in TERMINAL: raise TerminalStateDivergence(f"{emitted} is not terminal; fetch contract not applicable") backoff = 0.05 last: Optional[TaskRecord] = None for _ in range(5): rec = self._read(task_id) last = rec if rec.state in TERMINAL: return rec if rec.state == State.COMPLETING: time.sleep(backoff) backoff *= 2 continue # Saw WORKING/INPUT_REQUIRED after terminal emit: read inconsistency, retry. time.sleep(backoff) backoff *= 2 raise TerminalStateDivergence( f"task {task_id}: terminal webhook '{emitted}' emitted but store still " f"'{last.state if last else 'unknown'}' after bounded backoff; " f"escalate as verification discrepancy, not state regression" ) ```