# How does an instance detect a divergent task state when A2A v1.0 push-notification webhooks silently reorder and the Agent Card's `taskStates` capability is a set, not a sequence **Date of Record:** 2026 December 3 **Scope:** Applies to A2A v1.0 clients and servers that rely on push-notification webhooks to observe task lifecycle transitions, and to any agent that reconciles webhook-delivered `TaskStatusUpdateEvent` payloads against a locally cached task state machine. Does not apply to purely synchronous `tasks/send` polling, nor to A2A versions predating the `TaskState` enum stabilization. ## Core Distinction An A2A Agent Card advertises `capabilities.pushNotifications` and a set of supported `TaskState` values. The word *set* is load-bearing: the card declares which states a task can occupy, not which transitions are legal or in what order they arrive. A webhook consumer that treats the card's state list as an authoritative ordering — or that assumes webhook delivery preserves the server's internal transition order — will accept a `completed` event that arrived before the `working` event it supersedes, and will mark the task terminal while the server is still mid-execution. The divergence is not a lost message; it is a *reordered* message that is individually valid and collectively incoherent. The invariant that must hold: for any task `T`, the set of observed `TaskStatusUpdateEvent`s, when sorted by the server-assigned `status.timestamp` (not by delivery order, not by arrival time), must form a monotone path through the server's declared transition graph. When it does not, the consumer must detect the violation rather than pick a winner. ## What Was Observed A client agent dispatched `tasks/send` to a remote executor. The Agent Card advertised `pushNotifications: true` and `taskStates: [submitted, working, input-required, completed, failed, canceled]`. The client registered a webhook and cached the initial `submitted` state from the `tasks/send` response. The executor ran a multi-step tool chain. Its internal transition sequence was `working → input-required → working → completed`, with the second `working` entered after a 40-second human-in-the-loop pause. Webhook delivery used three separate HTTP POSTs with independent retry on 5xx. The `input-required` POST hit a transient 502 at the client's ingress and was retried after 8 seconds. The `completed` POST succeeded on first attempt. Delivery order at the consumer: `working(t0)`, `completed(t3)`, `input-required(t1)` — the retried `input-required` arrived last, 8 seconds after `completed`. The consumer's handler was a simple `if new_state in TERMINAL: mark_done()`. It marked the task `completed` at `t3`, then received `input-required` at `t3+8`, saw a non-terminal state arriving after a terminal one, and — per its own defensive code — logged "stale event, ignoring." The task was recorded as `completed`. The server, meanwhile, had actually completed the task, but the client's record of *why* (the input it supplied at the `input-required` round-trip) was never captured, because the consumer had already discarded the task context on terminal transition. The failure was silent. No exception, no retry, no alert. The task record was internally consistent and wrong about its own history. A downstream auditor replaying the client's event log could not reconstruct the input the client had actually provided, because the client never recorded it — it had torn down the task context at the first terminal event. The non-obvious part: the Agent Card's `taskStates` list *looked* like a contract. It was not. It was a capability declaration. The consumer had conflated "the server can emit these states" with "the server will emit them in this order," and the webhook transport's at-least-once, out-of-order delivery exploited the gap. ## Condition of Validity The detection mechanism described below is valid only when all of the following hold: 1. Each `TaskStatusUpdateEvent` carries a server-assigned `status.timestamp` (ISO 8601, monotonic per task on the server side) and a `taskId` that is stable across the task's lifetime. If the server does not populate `timestamp`, detection degrades to "arrival order," which is exactly the signal that failed. 2. The consumer maintains a per-task event journal keyed by `(taskId, status.timestamp)` and does not collapse duplicate timestamps. A2A permits a server to re-emit the same state; identical `(state, timestamp)` pairs are idempotent and must be deduplicated, but distinct timestamps with the same state are legal (the `working → input-required → working` cycle) and must be preserved. 3. The consumer's local transition graph is derived from the card's `taskStates` *plus* a conservative default graph (submitted → working → {input-required, completed, failed, canceled}; input-required → working; working → working is a self-loop permitted only when timestamps strictly increase). The card cannot override the default graph to permit `completed → working`; if a server emits that, it is a protocol violation, not a capability. 4. The consumer does not treat `completed`, `failed`, or `canceled` as context-destroying. Terminal state means "no further transitions expected," not "discard the journal." The journal is retained until an explicit `tasks/get` reconciliation confirms terminality. ## Decision Boundary The boundary is between *reordering* and *divergence*. Reordering is recoverable: events arrive out of order but the set, sorted by `timestamp`, forms a legal path. Divergence is not: the set, sorted by `timestamp`, does not form a legal path, which means either the server violated its own graph or the consumer's graph is wrong. These require different responses. - **Reordering detected, path legal after sort:** replay the journal in timestamp order, recompute the current state, and emit a corrected state to downstream consumers. Do not raise. Do not alert. This is normal webhook behavior. - **Divergence detected, path illegal after sort:** halt processing for that task, mark it `indeterminate`, and issue a synchronous `tasks/get` to the server to fetch authoritative state. Do not guess. Do not pick the latest timestamp as truth — the server may have emitted a `completed` that the consumer's graph rejects because the consumer's graph is stale relative to a card update. - **Card updated mid-task:** if the Agent Card's `taskStates` changed between task dispatch and event arrival, the consumer's graph is stale. Re-fetch the card, rebuild the graph, and re-validate the journal. If the journal is now legal, resume; if not, the card change itself is the anomaly and must be surfaced. The trap: a consumer that treats terminal-state arrival as a signal to stop listening will *always* miss the retried non-terminal event that follows. The fix is not "listen longer" — it is "never let terminality be inferred from a single event's arrival; infer it from the sorted journal's terminal position plus a reconciliation `tasks/get`." ## Operational Effect With journal-based reconciliation, the observed failure becomes detectable: the sorted journal is `working(t0), input-required(t1), working(t2), completed(t3)`, which is a legal path, and the consumer correctly replays it, capturing the input supplied at `t1` before honoring `completed` at `t3`. The task context is not torn down at first-terminal-event; it is torn down at reconciliation-confirmed-terminal. The cost is one extra `tasks/get` per task at terminal transition, and a per-task journal that must be bounded (cap at, say, 256 events per task; beyond that, force reconciliation and truncate with a marker). The benefit is that the consumer's record of *what happened* matches the server's, even when the transport reordered the evidence. The deeper effect: the Agent Card's `taskStates` must be read as a *permission* set, not a *sequence*. Any consumer that derives ordering from it will, under webhook retry, eventually accept a terminal event before a superseding non-terminal one and silently discard task history. Detection requires an explicit timestamp-sorted journal and a local transition graph that the card can extend but not contradict. ```python from __future__ import annotations import datetime as dt from dataclasses import dataclass, field from typing import Literal TaskState = Literal[ "submitted", "working", "input-required", "completed", "failed", "canceled" ] TERMINAL: frozenset[TaskState] = frozenset({"completed", "failed", "canceled"}) # Conservative default graph. The Agent Card may extend this; it may not # contradict it (e.g. it cannot legalize completed -> working). DEFAULT_GRAPH: dict[TaskState, frozenset[TaskState]] = { "submitted": frozenset({"working", "failed", "canceled"}), "working": frozenset({"working", "input-required", "completed", "failed", "canceled"}), "input-required": frozenset({"working", "failed", "canceled"}), "completed": frozenset(), "failed": frozenset(), "canceled": frozenset(), } class DivergentTaskStateError(RuntimeError): """Raised when a task's timestamp-sorted event journal does not form a legal path through the declared transition graph.""" class CardContradictsGraphError(RuntimeError): """Raised when an Agent Card's taskStates capability attempts to legalize a transition that the conservative default graph forbids.""" @dataclass(frozen=True) class StatusUpdate: task_id: str state: TaskState timestamp: dt.datetime # server-assigned, monotonic per task @dataclass class TaskJournal: task_id: str events: list[StatusUpdate] = field(default_factory=list) _seen: set[tuple[TaskState, dt.datetime]] = field(default_factory=set) def record(self, ev: StatusUpdate) -> None: if ev.task_id != self.task_id: raise DivergentTaskStateError( f"event task_id {ev.task_id!r} != journal {self.task_id!r}" ) key = (ev.state, ev.timestamp) if key in self._seen: return # idempotent re-emit self._seen.add(key) self.events.append(ev) def sorted_path(self) -> list[StatusUpdate]: return sorted(self.events, key=lambda e: e.timestamp) def build_graph(card_states: set[TaskState]) -> dict[TaskState, frozenset[TaskState]]: graph = {k: set(v) for k, v in DEFAULT_GRAPH.items()} for src, dsts in DEFAULT_GRAPH.items(): for dst in dsts: if src in card_states and dst in card_states: graph[src].add(dst) # A card cannot legalize a transition the default graph forbids. for src in card_states: for dst in card_states: if dst in graph.get(src, set()): continue if src in TERMINAL and dst != src: raise CardContradictsGraphError( f"card legalizes forbidden transition {src} -> {dst}" ) return {k: frozenset(v) for k, v in graph.items()} def validate_journal( journal: TaskJournal, graph: dict[TaskState, frozenset[TaskState]] ) -> TaskState: path = journal.sorted_path() if not path: raise DivergentTaskStateError(f"empty journal for {journal.task_id!r}") current = path[0].state for prev, nxt in zip(path, path[1:]): if nxt.state not in graph.get(prev.state, frozenset()): raise DivergentTaskStateError( f"task {journal.task_id!r}: illegal transition " f"{prev.state}@{prev.timestamp.isoformat()} -> " f"{nxt.state}@{nxt.timestamp.isoformat()} after timestamp sort" ) current = nxt.state return current def reconcile( journal: TaskJournal, card_states: set[TaskState] ) -> TaskState: graph = build_graph(card_states) try: return validate_journal(journal, graph) except DivergentTaskStateError: # Do not guess. Surface as indeterminate; caller must issue tasks/get. raise ```