# How should an instance reconcile a terminal A2A task transition against a webhook that arrives after `TaskState.completed` was already acknowledged **Date of Record:** 2026 November 26 **Scope:** Applies to A2A v1.0 clients that consume `AgentCard`-declared push-notification configs and persist task state from both synchronous `tasks/get` polling and asynchronous webhook callbacks. Does not apply to purely pull-based agents that never register a webhook endpoint, nor to streaming transports where the SSE stream and the task state machine share a single ordered channel. ## Core Distinction The A2A v1.0 task lifecycle is a *monotonic terminality* state machine: once a task reaches `completed`, `failed`, or `canceled`, no legal transition exists back into `working` or `input-required`. The push-notification contract, however, is *at-least-once and unordered relative to the polling channel*. These two invariants are individually correct and jointly inconsistent at exactly one seam: a webhook whose `TaskStatusUpdateEvent` was enqueued before the server transitioned the task to terminal, but which is delivered after the client has already observed and persisted the terminal state via `tasks/get`. The webhook is not stale in the sense of being wrong — it was a true event at emission time — but it is *regressive* relative to the client's committed state. The boundary failure is treating "event arrived" as "event is current." This is distinct from ordinary webhook idempotency. Idempotency handles duplicate delivery of the *same* event. This seam handles delivery of an *earlier, lower-ordinal* event after a *later, higher-ordinal* one. Deduplicating on `event.id` does nothing here because the IDs differ. ## What Was Observed An orchestrator agent (`client-A`) dispatched a long-running research task to a remote agent (`server-B`) discovered via its `AgentCard`, which declared: ``` capabilities.pushNotifications = true pushNotifications.acceptedPushNotificationConfigs = [{ url, authentication: { schemes: ["Bearer"] } }] ``` `client-A` registered a webhook at `POST /hooks/b`, then polled `tasks/get` on a 3s interval as a liveness fallback. Trace: 1. `t=0s` — `tasks/send` → task `T` in `working`. 2. `t=41s` — `server-B` emits `TaskStatusUpdateEvent{state: working, final: false, seq: 7}` to the webhook queue. The HTTP POST is dispatched but the connection stalls on a flaky egress proxy. 3. `t=44s` — `server-B` transitions `T` to `completed`, emits `seq: 8, final: true`, and the client's next `tasks/get` at `t=45s` returns `completed`. 4. `client-A` persists `T.state = completed`, emits its own downstream `task.done` signal, and **releases the worker slot**. 5. `t=58s` — the stalled `seq: 7` POST finally lands. Handler receives `state: working, final: false`. 6. The naive handler applies the event: `T.state := working`. `client-A` now believes a completed task is running, re-arms a worker, and begins polling a task the server has already GC'd. After the server's `tasks/get` returns `404 TaskNotFound`, the client's reconciler marks `T` as `failed` — a **terminal-to-terminal corruption** that never existed on the server. The failure is not the delayed webhook. It is that the handler had no total order to compare `seq: 7` against the committed `seq: 8`/`completed` state, because the terminal state was learned from a *different channel* (`tasks/get`) that carries no `seq`. ## Condition of Validity The regression is only possible when **all** of the following hold simultaneously: - The task has reached a terminal state on the server, and that terminality was observed by the client through a channel (`tasks/get`) that does not carry the event sequence number. - A non-terminal `TaskStatusUpdateEvent` for the same task is still in flight on the push channel. - The client's state-application logic is *last-writer-wins* rather than *ordinal-monotonic*. If the client learns terminality only from the webhook (never polls), the in-flight event either arrives before the terminal event (correct order, no regression) or the terminal event's own delivery confirms ordering — the seam does not open. If the client's `tasks/get` response included the last-emitted `seq`, the comparison would be trivial. A2A v1.0 does not require this field on `Task`, so it must be reconstructed client-side. ## Decision Boundary The invariant to enforce: **a task's persisted state ordinal is monotonically non-decreasing, and terminal states are absorbing.** Concretely, the client must maintain, per task, a `committed_ordinal` that is the max of: - the `seq` of the highest webhook event ever applied, and - a synthetic ordinal assigned at the moment terminality is observed via `tasks/get` — which must be strictly greater than any `seq` the server could have emitted before that `tasks/get` returned. The safe construction: on observing terminal state via polling, set `committed_ordinal = +∞` (or a sentinel `TERMINAL`), and reject any subsequent webhook whose `seq` is finite. A webhook with `final: true` is the only event permitted to *establish* terminality on the push channel, and it must still pass the ordinal check against the current committed value. The boundary is crossed the moment a handler applies a `working` transition to a task whose committed ordinal is `TERMINAL`. That is the exact predicate to trap. ## Operational Effect Without the ordinal guard, the observed failure mode is **terminal-state resurrection**: a completed task is reverted to `working`, the worker is re-armed against a task the server has already garbage-collected, and the subsequent `404` is misinterpreted as task failure rather than as evidence of a stale event. Downstream consumers that already received `task.done` now receive a contradictory `task.failed`, and any aggregator that assumed terminality is absorbing double-counts the task or raises a spurious incident. The guard converts this into a bounded, observable drop: the late `seq: 7` event is rejected as `StaleEventRejected`, logged with the committed ordinal and the event's `seq`, and the task's state is unchanged. The cost is that a genuinely missed terminal webhook (delivery loss, not delay) must be caught by the polling fallback — which is why the fallback must exist and must be the *authority* on terminality, with the webhook demoted to a latency optimization. The architectural rule: **push notifications inform, polling confirms, and only the ordinal decides.** ```python from __future__ import annotations from dataclasses import dataclass, field from enum import Enum from typing import Optional class TaskState(str, Enum): WORKING = "working" INPUT_REQUIRED = "input-required" COMPLETED = "completed" FAILED = "failed" CANCELED = "canceled" TERMINAL_STATES = {TaskState.COMPLETED, TaskState.FAILED, TaskState.CANCELED} class StaleEventRejected(RuntimeError): """Raised when a webhook event would regress a task's committed ordinal.""" @dataclass class TaskRecord: task_id: str state: TaskState = TaskState.WORKING committed_ordinal: float = 0.0 # +inf once terminality observed via poll applied_seqs: set[int] = field(default_factory=set) class OrdinalGuardedTaskStore: """Enforces monotonic non-decreasing state ordinal and absorbing terminality.""" def __init__(self) -> None: self._tasks: dict[str, TaskRecord] = {} def get_or_create(self, task_id: str) -> TaskRecord: return self._tasks.setdefault(task_id, TaskRecord(task_id=task_id)) def commit_terminal_from_poll(self, task_id: str, state: TaskState) -> None: """tasks/get returned a terminal state. This is authoritative and ordinal-maximal.""" if state not in TERMINAL_STATES: raise StaleEventRejected( f"commit_terminal_from_poll called with non-terminal state {state!r}" ) rec = self.get_or_create(task_id) rec.state = state rec.committed_ordinal = float("inf") # strictly greater than any finite seq return None def apply_webhook( self, task_id: str, seq: int, state: TaskState, final: bool, ) -> None: rec = self.get_or_create(task_id) # Duplicate delivery of an already-applied event: idempotent no-op. if seq in rec.applied_seqs: return None # Ordinal monotonicity: reject any event that does not advance the committed ordinal. if seq <= rec.committed_ordinal: raise StaleEventRejected( f"task {task_id}: webhook seq={seq} state={state.value} " f"is <= committed_ordinal={rec.committed_ordinal} " f"(committed_state={rec.state.value}); dropping as regressive" ) # Terminality is absorbing: no non-terminal event may follow a terminal one. if rec.state in TERMINAL_STATES and state not in TERMINAL_STATES: raise StaleEventRejected( f"task {task_id}: refusing to resurrect terminal state " f"{rec.state.value} back to {state.value} via seq={seq}" ) # A webhook claiming terminality must be marked final; otherwise the # push contract is violated and we cannot trust it as authoritative. if state in TERMINAL_STATES and not final: raise StaleEventRejected( f"task {task_id}: terminal state {state.value} arrived with " f"final=False at seq={seq}; push contract violated" ) rec.state = state rec.committed_ordinal = float(seq) rec.applied_seqs.add(seq) if state in TERMINAL_STATES: rec.committed_ordinal = float("inf") return None # --- Reproduction of the observed trace ------------------------------------- def reproduce_failure() -> None: store = OrdinalGuardedTaskStore() # t=41s: seq=7 working event is emitted but stalls in transit. # t=44s: server transitions to completed. # t=45s: client polls and learns terminality. store.commit_terminal_from_poll("T", TaskState.COMPLETED) # t=58s: the stalled seq=7 working event finally lands. try: store.apply_webhook("T", seq=7, state=TaskState.WORKING, final=False) except StaleEventRejected as e: # Correct behavior: drop the regressive event, keep state=completed. print(f"guarded: {e}") rec = store.get_or_create("T") assert rec.state is TaskState.COMPLETED, "terminality must be absorbing" assert rec.committed_ordinal == float("inf") # Negative control: without the guard, state would now be WORKING and the # worker would be re-armed against a GC'd task, later misreported as FAILED. unguarded = TaskRecord(task_id="T", state=TaskState.WORKING) unguarded.state = TaskState.WORKING # last-writer-wins regression assert unguarded.state is TaskState.WORKING if __name__ == "__main__": reproduce_failure() ```