# In what scenarios must an instance treat A2A v1.0 push-notification callbacks as a second, unordered event stream that can silently desynchronize from the streaming task lifecycle **Date of Record:** 2026 November 19 **Scope:** Applies to A2A v1.0 agents that emit `TaskStatusUpdateEvent`/`TaskArtifactUpdateEvent` over a streaming transport (SSE) *and* register a `pushNotificationConfig` webhook for the same task. Does not apply to purely synchronous request/response A2A calls, nor to tasks with no push config registered. ## Core Distinction The A2A task lifecycle is a state machine. The streaming channel and the push-notification webhook are **two independent delivery paths over the same state machine**, and the protocol does not guarantee a global ordering between them. The streaming channel is ordered *within itself* (SSE sequence per connection). The webhook is ordered *only by whatever the receiving HTTP client does with concurrent POSTs* — which, in practice, is nothing. The failure is not "a webhook got lost." The failure is: **a late or retried webhook delivers a stale `TaskStatusUpdateEvent` after the streaming channel has already advanced the task past that state, and a naive receiver treats the webhook as authoritative and rolls the task state backward.** The task's terminal state (`completed`) is overwritten by an in-flight `working` event that was queued before completion but delivered after it. The peer agent then believes the task is still running, re-polls, re-dispatches, or — worse — re-executes. This is a continuity invariant violation, not a transport bug. The invariant that must hold is: *for any task, the applied state is monotonic in the lifecycle partial order, regardless of which channel delivered the event.* ## What Was Observed A two-agent pipeline: Agent A (orchestrator) issues `tasks/sendSubscribe` to Agent B (worker) with a `pushNotificationConfig` pointing at A's webhook. B streams status events and also fires webhooks on each status transition. B's webhook dispatcher is a best-effort queue with retry-on-5xx and a 30s backoff. Sequence captured: 1. B streams `working` → A applies `working`. (t=0) 2. B finishes, streams `completed` with final artifact → A applies `completed`, marks task terminal, releases the baton. (t=4.2s) 3. B's webhook for `working` hits a transient 502 at A's ingress and is retried. (t=0.1s, retry scheduled) 4. Retry fires at t=30.1s, arrives at A's webhook handler. 5. A's handler — which shares the same `apply_status()` code path as the stream consumer — applies `working`. The task regresses from terminal to non-terminal. Downstream: A's supervisor sees a non-terminal task it had already reported complete, opens a duplicate verification pass, and issues a second `tasks/send` with the same `taskId`. B, which had garbage-collected the task record at completion, treats the duplicate as a new task and re-runs the tool call — a non-idempotent side effect (a payment authorization) executes twice. The streaming channel was correct throughout. The webhook channel was also "correct" in the sense that it delivered every event it was told to deliver. The composition was wrong. ## Condition of Validity The monotonic-application invariant holds **only if** the receiver enforces all three of the following. Remove any one and the boundary failure is reachable: 1. **Lifecycle rank comparison.** Every applied status carries a rank in the partial order `submitted < working < {input-required, completed, failed, canceled}`. Terminal states are absorbing: once applied, no non-terminal event may overwrite them. This is a *rank gate at the apply site*, not at the transport. 2. **Event identity deduplication.** Each `TaskStatusUpdateEvent` carries a stable `(taskId, statusTimestamp, statusState)` tuple (or an explicit monotonic `eventId`). The receiver keeps a per-task high-water mark and drops any event at or below it. Retries and cross-channel duplicates collapse to a no-op. 3. **Channel-agnostic apply path with a single writer.** Both the SSE consumer and the webhook handler must funnel through the *same* guarded `apply_status()` under a per-task lock. If the webhook handler has its own "just set the status" shortcut, the gate is bypassed. Critically, the protocol does **not** give you (1) or (2) for free. A2A v1.0 specifies that push notifications are *advisory mirrors* of lifecycle events; it does not specify a cross-channel ordering, a global event sequence number, or a webhook-side dedup token. The receiver must synthesize the invariant from `taskId` + `status.timestamp` + absorbing-terminal semantics. ## Decision Boundary The decision an implementer must make per task, at apply time: - **If** incoming status rank ≤ high-water mark rank for `taskId` → **drop silently**, log a `stale_event_suppressed` counter. Do not surface to the agent's reasoning loop; a suppressed stale event is not information. - **If** incoming status is terminal and high-water mark is already terminal with a *different* terminal state (e.g., `completed` then `canceled`) → **do not overwrite**; raise a `TerminalStateConflict` for out-of-band reconciliation. Two terminal states for one task means the two channels genuinely disagree, and that is a real fault, not a stale retry. - **If** incoming status is terminal and high-water mark is non-terminal → apply, close the task, and **revoke the webhook config** (`tasks/pushNotificationConfig/delete`) so no further callbacks can arrive for a closed task. - **If** the webhook arrives for an unknown `taskId` (already GC'd) → **reject with 410 Gone**, do not recreate the task. This is the exact path that caused the duplicate payment above. The boundary is sharp: *stale-but-known* → suppress; *conflicting-terminal* → escalate; *unknown-task* → reject. Collapsing any two of these into one handler is how the regression slips through. ## Operational Effect Once the rank gate and dedup high-water mark are in place, the observable behavior changes in three measurable ways: - **Terminal states become truly absorbing.** The rate of "task reopened after completion" drops to zero by construction, which removes the duplicate-dispatch class of side effects entirely. Idempotency keys on the *tool* layer are still recommended as defense in depth, but they stop being load-bearing. - **Webhook retries become free.** A retried `working` event is suppressed in O(1) by the high-water mark; it never reaches the agent's reasoning loop, so it never perturbs the orchestrator's plan. The retry budget can be raised without correctness cost. - **The two channels can be reasoned about independently.** The stream is the fast path; the webhook is the durability path for when the stream connection drops. Because both are gated identically, a dropped SSE connection followed by a webhook catch-up converges to the same state as an uninterrupted stream. This is the actual purpose of push notifications and the only condition under which they are safe to enable. The residual risk after the gate is **clock skew on `status.timestamp`**: if B's clock is behind A's, a genuinely newer event can carry a lower timestamp and be suppressed. Mitigate by using a monotonic `eventId` from B when available, and by treating `timestamp` as a tiebreaker only, never the sole ordering key. ```python from __future__ import annotations import threading from dataclasses import dataclass, field from enum import IntEnum from typing import Dict, Optional class TerminalStateConflict(RuntimeError): """Two terminal statuses delivered for one task via different channels.""" class UnknownTaskError(RuntimeError): """Webhook arrived for a task already closed/GC'd; must not resurrect it.""" class LifecycleRank(IntEnum): SUBMITTED = 0 WORKING = 1 INPUT_REQUIRED = 2 COMPLETED = 3 FAILED = 4 CANCELED = 5 TERMINAL = {LifecycleRank.COMPLETED, LifecycleRank.FAILED, LifecycleRank.CANCELED} @dataclass class TaskRecord: task_id: str high_water: LifecycleRank = LifecycleRank.SUBMITTED terminal_state: Optional[LifecycleRank] = None lock: threading.Lock = field(default_factory=threading.Lock) class TaskStateGate: """Single apply path shared by SSE consumer and webhook handler.""" def __init__(self) -> None: self._tasks: Dict[str, TaskRecord] = {} self._registry_lock = threading.Lock() self.suppressed = 0 def _get(self, task_id: str) -> TaskRecord: with self._registry_lock: rec = self._tasks.get(task_id) if rec is None: raise UnknownTaskError(f"no live task {task_id!r}; reject, do not recreate") return rec def open(self, task_id: str) -> None: with self._registry_lock: self._tasks[task_id] = TaskRecord(task_id=task_id) def apply_status(self, task_id: str, rank: LifecycleRank) -> bool: """Apply a status from *either* channel. Returns True if state advanced.""" rec = self._get(task_id) with rec.lock: if rec.terminal_state is not None: if rank in TERMINAL and rank != rec.terminal_state: raise TerminalStateConflict( f"task {task_id}: terminal {rec.terminal_state.name} " f"conflicts with {rank.name}" ) self.suppressed += 1 return False # stale retry after close: drop silently if rank <= rec.high_water: self.suppressed += 1 return False # out-of-order / duplicate: drop rec.high_water = rank if rank in TERMINAL: rec.terminal_state = rank return True def close(self, task_id: str) -> None: with self._registry_lock: self._tasks.pop(task_id, None) def handle_webhook(gate: TaskStateGate, task_id: str, rank: LifecycleRank) -> str: try: advanced = gate.apply_status(task_id, rank) except UnknownTaskError: # 410 Gone: never resurrect a GC'd task (prevents duplicate side effects) return "410-gone" except TerminalStateConflict as e: raise TerminalStateConflict(str(e)) # escalate for reconciliation return "applied" if advanced else "suppressed" ```