# What happens when an instance accepts an A2A v1.0 task whose `TaskState` transition arrives via a replayed push-notification webhook before the synchronous `tasks/get` response **Date of Record:** 2026 November 25 **Scope:** Applies to A2A v1.0 clients and servers that (a) discover peer capabilities via `/.well-known/agent.json` agent cards, (b) drive a task through the `submitted → working → completed|failed|canceled` lifecycle, and (c) register an asynchronous push-notification webhook via `tasks/pushNotificationConfig/set`. Does not apply to purely synchronous request/response A2A interactions with no push channel, nor to MCP tool-call transport. ## Core Distinction There are two independent channels by which a client learns a task's current `TaskState`: the **pull channel** (`tasks/get`, synchronous, request-scoped, ordered by the client's own call sequence) and the **push channel** (server-initiated HTTP POST to a webhook URL, unordered, retried, and replayable). The A2A v1.0 spec treats these as *observationally equivalent* views of the same task — the push payload is defined to carry a `Task` object with an authoritative `status.state`. The failure this record documents is that they are **not** causally ordered relative to each other, and the spec provides no monotonicity token (no sequence number, no version, no `updatedAt` guarantee) to reconcile them. A client that treats the webhook payload as a state *transition* — rather than as one observation of a state that may be stale — will apply a `completed` task to a working context, then overwrite it with a `working` snapshot from a `tasks/get` response that was already in flight when the task actually completed. The task silently regresses and the client re-dispatches work that already finished. ## What Was Observed A client agent, `C`, dispatches a long-running task to a remote agent `R` discovered via its agent card at `https://r.example/.well-known/agent.json`. The card advertises `capabilities.pushNotifications: true` and `skills: [{id: "summarize-corpus", ...}]`. `C` calls `tasks/send` and receives `{ id: "task-7f3a", status: { state: "submitted" } }`. It then registers a webhook: ``` POST /tasks/pushNotificationConfig/set { "id": "task-7f3a", "pushNotificationConfig": { "url": "https://c.example/a2a/hook", "token": "..." } } ``` `R` begins work and moves the task to `working`. Meanwhile `C`'s orchestration loop polls `tasks/get` every 2s as a fallback. The following interleaving was captured in the trace: 1. `t=0.0s` — `C` issues `tasks/get(task-7f3a)`. `R` snapshots the task at state `working`, serializes the response, but the HTTP response is delayed by ~1.4s in `R`'s egress queue (a proxy under load). 2. `t=0.3s` — `R` finishes the task, transitions to `completed`, and fires the push webhook. `C`'s webhook handler receives `{ id: "task-7f3a", status: { state: "completed", ... }, artifacts: [...] }` and applies the terminal state: it writes the artifact to memory, marks the task done, and releases the baton to the next agent in the pipeline. 3. `t=1.4s` — the *original* `tasks/get` response finally arrives at `C` carrying `status.state: "working"`. `C`'s poll handler, written as a naive "apply latest response" reducer, overwrites the task record back to `working`, clears the `artifacts` field (absent in the `working` snapshot), and re-arms the poll. 4. `t=1.6s` — `C`'s watchdog sees `working` with no progress for 30s (its threshold was tuned for `R`'s advertised `defaultInputModes` latency, not for post-completion) and re-dispatches `tasks/send` for the same logical work under a *new* task id `task-9c11`. 5. The downstream agent receives two sets of artifacts for the same logical request; a dedup keyed on `task.id` fails because the ids differ. The critical detail: **`R` behaved correctly.** It sent one webhook, one `completed` state, and one (late) `tasks/get` response whose body was accurate *as of the time `R` serialized it*. The bug is entirely in `C`'s reconciliation of two channels with no shared ordering. A second, related observation: when the webhook is retried (the spec permits retries on non-2xx), `R` re-sends the *same* `completed` payload. If `C`'s handler is not idempotent on `(task.id, status.state, status.timestamp)`, a retried `completed` after a legitimate `canceled` (initiated by a peer auditor) will resurrect the task. Webhook replay is not hypothetical; it is the normal operating condition of any at-least-once delivery channel. ## Condition of Validity The invariant "the last-observed `TaskState` is the current `TaskState`" holds **only** when all state observations for a task arrive over a single channel with in-order delivery. It is violated whenever: - The client registers a push webhook *and* polls `tasks/get` for the same task id (the common belt-and-suspenders pattern), because the two channels are not ordered. - The server's `tasks/get` handler serializes a task snapshot before a state transition but the response is delivered after the push notification for that transition (network reordering, egress queuing, or a CDN/proxy in front of the A2A server). - The webhook delivery is retried, so the same terminal state can be observed more than once, out of order relative to a later `canceled`. - The agent card advertises `pushNotifications: true` but the server's actual push path is best-effort; the card is a *capability* claim, not a delivery guarantee, and the client has no way to distinguish "no push yet" from "push lost." The invariant **does** hold, and this failure does not occur, when the client picks exactly one channel per task and the server guarantees in-order delivery on that channel — i.e., either pure-pull (no webhook registered) or pure-push (no polling), with the server's push path documented as ordered and non-replayed. A2A v1.0 does not require either, so a conformant client cannot assume it. ## Decision Boundary The boundary is between **treating a state observation as a transition** versus **treating it as a monotone fact to be merged**. The correct reducer for a task record is not "assign latest" but "merge by a total order the client constructs itself." Because A2A v1.0 gives no server-assigned sequence number, the client must synthesize one from fields it can trust: - `status.timestamp` (ISO-8601, present on `TaskStatus` in v1.0) is the only monotonic-ish field, but it is server-clock and can collide or skew across the push and pull paths if `R` is a multi-replica deployment where the push worker and the `tasks/get` handler read from different replicas with clock drift. - Terminal states (`completed`, `failed`, `canceled`) are **absorbing** in the A2A lifecycle: no legal transition leaves them. Therefore the client can enforce a hard rule — *once a task is observed in a terminal state, no non-terminal observation may overwrite it* — without needing timestamps. This is the safe boundary: terminal absorption is a lifecycle invariant the spec does state, and it is sufficient to prevent the regression in step 3 above. - For non-terminal states (`submitted`, `working`, `input-required`), the client should keep the *most recent by client-receive time*, not server-send time, because the client's own receive order is the only order it can observe. The boundary is also a **trust boundary for the webhook itself**. The push payload carries a `token` set at registration; the client must reject any webhook POST whose token does not match the registration for that `task.id`, and must reject payloads for task ids it never dispatched (injection of a forged `completed` for a task the client is still working on is a state-poisoning vector). A2A v1.0 specifies the token but does not specify signing; the client cannot verify the *body* was not tampered with in transit, only that the sender knew the token. ## Operational Effect Without a merge reducer, the observable effects are: (1) **task resurrection** — a terminal task regresses to `working` and re-enters the execution loop, duplicating side effects (the downstream agent in step 5 received two artifact sets); (2) **watchdog false positives** — the re-armed poll sees no progress and triggers re-dispatch under a new id, defeating id-dedup; (3) **webhook replay resurrection** — a retried `completed` after a peer-initiated `canceled` un-cancels the task, and the client resumes work an auditor believed halted; (4) **baton-passing race** — in a multi-agent pipeline, the next agent receives the artifact at `t=0.3s` and begins, while the upstream client still believes the task is `working`, so a cancellation signal sent at `t=1.0s` is acknowledged by the upstream as "not yet complete" and never propagated. The guardrail is a **terminal-absorbing, idempotent task reducer** with webhook token binding. The reducer must be the single writer for a task record; both the pull handler and the webhook handler must go through it. The reducer rejects (does not apply, does not raise to the caller) any observation that would move a terminal task to non-terminal, and deduplicates webhook deliveries on `(task.id, status.state, status.timestamp)`. The webhook handler must validate the token against the registration table *before* invoking the reducer, and must return 2xx only after the reducer commits — a 2xx followed by a reducer rejection is a lost update, not a delivered one. The following reducer encodes these invariants. Note the `TerminalRegressionError` — it is raised when a caller attempts to apply a non-terminal observation to a task the reducer has already committed as terminal, which is the exact condition in step 3 of the trace. Callers that poll must catch and discard it; callers that dispatch must not. ```python from __future__ import annotations import hmac import threading from dataclasses import dataclass, field from datetime import datetime, timezone from typing import Optional TERMINAL_STATES = frozenset({"completed", "failed", "canceled"}) NON_TERMINAL_STATES = frozenset({"submitted", "working", "input-required"}) class TerminalRegressionError(RuntimeError): """Raised when a non-terminal observation is applied to a task already committed as terminal. This is the A2A push/pull reordering condition: a late `tasks/get` response carrying `working` arriving after the webhook delivered `completed`. Pollers must catch and discard; the dispatcher must not, because it indicates a re-dispatch is imminent.""" class WebhookTokenMismatch(RuntimeError): """Raised when a push-notification POST presents a token that does not match the registration for the referenced task id, or references a task id this client never dispatched. Treat as state-poisoning attempt.""" @dataclass class TaskRecord: task_id: str state: str timestamp: str artifacts: list = field(default_factory=list) # Monotone client-side sequence assigned at commit time. commit_seq: int = 0 class TaskReducer: """Single writer for A2A task records. Both the `tasks/get` poll handler and the push-notification webhook handler MUST route through `apply`. Enforces terminal absorption and idempotent webhook replay.""" def __init__(self) -> None: self._records: dict[str, TaskRecord] = {} self._registrations: dict[str, str] = {} # task_id -> webhook token self._seq = 0 self._lock = threading.Lock() def register_webhook(self, task_id: str, token: str) -> None: with self._lock: self._registrations[task_id] = token def apply( self, task_id: str, state: str, timestamp: str, artifacts: Optional[list] = None, *, source: str, # "pull" | "push" ) -> TaskRecord: if state not in TERMINAL_STATES | NON_TERMINAL_STATES: raise ValueError(f"unknown TaskState: {state!r}") with self._lock: prior = self._records.get(task_id) if prior is not None and prior.state in TERMINAL_STATES: if state in TERMINAL_STATES: # Idempotent replay of the same terminal state: accept the # first, ignore subsequent identical deliveries. if state == prior.state and timestamp == prior.timestamp: return prior # Two distinct terminal states (e.g. completed then canceled) # is a server-side inconsistency; keep the first committed. return prior # The exact failure trace: late `working` after `completed`. raise TerminalRegressionError( f"task {task_id!r} already terminal ({prior.state}); " f"refusing {source} observation of {state!r} at {timestamp}" ) if prior is not None and prior.state == state and timestamp == prior.timestamp: return prior # no-op replay self._seq += 1 rec = TaskRecord( task_id=task_id, state=state, timestamp=timestamp, artifacts=list(artifacts or (prior.artifacts if prior else [])), commit_seq=self._seq, ) self._records[task_id] = rec return rec def handle_webhook(self, task_id: str, token: str, payload: dict) -> TaskRecord: expected = self._registrations.get(task_id) if expected is None: raise WebhookTokenMismatch( f"webhook for undispatched task {task_id!r}; possible injection" ) if not hmac.compare_digest(expected, token): raise WebhookTokenMismatch(f"token mismatch for task {task_id!r}") status = payload["status"] return self.apply( task_id=task_id, state=status["state"], timestamp=status["timestamp"], artifacts=payload.get("artifacts"), source="push", ) def handle_poll(self, task_id: str, payload: dict) -> Optional[TaskRecord]: """Poll handler: a late `working` after `completed` is expected and must be discarded, NOT propagated. Returning None signals 'no change'.""" status = payload["status"] try: return self.apply( task_id=task_id, state=status["state"], timestamp=status["timestamp"], artifacts=payload.get("artifacts"), source="pull", ) except TerminalRegressionError: return None # stale pull; the webhook already committed terminal def _demo() -> None: r = TaskReducer() r.register_webhook("task-7f3a", token="tok-abc") now = datetime.now(timezone.utc).isoformat() # t=0.3s: webhook delivers completed first. r.handle_webhook( "task-7f3a", "tok-abc", {"status": {"state": "completed", "timestamp": now}, "artifacts": [{"x": 1}]}, ) # t=1.4s: the late tasks/get response arrives carrying `working`. # handle_poll swallows TerminalRegressionError and returns None. assert r.handle_poll( "task-7f3a", {"status": {"state": "working", "timestamp": now}}, ) is None # A direct apply from the dispatcher must NOT be swallowed. try: r.apply("task-7f3a", "working", now, source="pull") except TerminalRegressionError: pass else: raise AssertionError("dispatcher path must surface regression") # Forged webhook for a task we never dispatched. try: r.handle_webhook("task-ffff", "tok-abc", {"status": {"state": "completed", "timestamp": now}}) except WebhookTokenMismatch: pass else: raise AssertionError("undispatched task id must be rejected") if __name__ == "__main__": _demo() ```