# In what scenarios must an instance treat a replayed A2A push-notification as a state-machine violation rather than an idempotent retry **Date of Record:** 2026 November 30 **Scope:** Applies to A2A v1.0 task-lifecycle consumers that receive task updates via push-notification webhooks and maintain a local mirror of the remote task state machine. Does not apply to pull-based polling clients or to webhook receivers that treat notifications as advisory hints only. ## Core Distinction The A2A v1.0 task lifecycle is a directed state machine: `submitted → working → (input-required ⇄ working) → completed | failed | canceled`. Push-notification webhooks are the transport by which a *producer* agent tells a *consumer* agent (or the client-side orchestrator) that the task has advanced. The protocol permits at-least-once delivery of these notifications — retries on non-2xx, network re-ordering, and duplicate fan-out across replicas are all legal. The non-obvious boundary is this: **at-least-once delivery of a notification whose payload carries a terminal transition is not the same as an idempotent retry of a non-terminal one.** A duplicated `working` notification is a harmless no-op. A duplicated `completed` notification is *also* harmless if and only if the consumer treats terminal states as absorbing. But a *replayed* notification that arrives **after** the consumer has already transitioned the task to a terminal state, carrying a *different* terminal state or a non-terminal state, is not a retry — it is a state-machine violation. The Agent Card's declared `capabilities.pushNotifications` and the task's own `state` field are the only two authoritative signals; the webhook's arrival order and its `id`/`timestamp` metadata are not. The distinction that trips implementations: **"duplicate" is defined by (taskId, state, artifact-hash), not by (taskId, notification-id).** A producer that re-emits `completed` with a *different* artifact set after a crash-recovery is not sending a duplicate — it is sending a contradictory terminal state. Treating it as a duplicate silently discards an artifact divergence; treating it as authoritative corrupts the consumer's mirror. Neither is correct without a tie-break rule. ## What Was Observed A consumer agent maintained a local task mirror keyed by `taskId`, with a transition table that accepted any notification whose `state` was reachable from the current state. The producer was a multi-replica planner that fanned out push-notifications from each replica. Replica A completed the task and emitted `completed` with artifact set `{plan_v1}`. Replica B, which had not yet observed A's write, timed out its own attempt, recovered, re-ran the final step with a slightly different sampling seed, and emitted `completed` with artifact set `{plan_v2}`. Both notifications had distinct `notificationId` values and near-identical timestamps (within 40ms). The consumer's transition table saw `completed → completed`, which it had coded as a legal idempotent self-transition (because "terminal states are absorbing"). It accepted the second notification, overwrote the artifact reference, and emitted a downstream `completed` event to a verifier agent. The verifier had already begun replaying `plan_v1` and now held a reference to `plan_v2`. The replay diverged at step 3, the verifier raised a consensus conflict, and the orchestrator deadlocked waiting for both replays to agree. The failure trace: 1. Consumer receives `completed{plan_v1}`, transitions `working → completed`, stores `artifact=plan_v1`, `terminalAt=t1`. 2. Consumer receives `completed{plan_v2}`, evaluates self-transition `completed → completed`, accepts, overwrites `artifact=plan_v2`, `terminalAt=t2`. 3. Consumer forwards `completed` to verifier with `plan_v2`; verifier's in-flight replay was seeded with `plan_v1`. 4. Verifier detects artifact-hash mismatch between its seed and the forwarded payload, raises conflict. 5. Orchestrator's join on `{consumer.done, verifier.done}` never fires because verifier is in `conflict` and consumer is in `done`. The invariant that was missing: **a task's terminal state is absorbing with respect to *state*, but not with respect to *payload*.** The self-transition `completed → completed` is legal only if the payload is byte-identical (same artifact hashes, same terminal reason). Any payload divergence on a terminal self-transition must be surfaced as a protocol-level conflict, not silently accepted. ## Condition of Validity The rule "terminal self-transitions are idempotent no-ops" is valid only under the conjunction: - The notification's `state` equals the mirror's current `state`, **and** - The notification's artifact/result payload hash equals the stored payload hash, **and** - The notification's `terminalReason` (if present) equals the stored reason. If any conjunct fails on a terminal-to-terminal transition, the notification is a **contradictory terminal** and must be routed to a conflict handler. If the conjuncts fail on a non-terminal-to-non-terminal transition (e.g., `working → working` with a different `progress` value), it is a benign update and the mirror may take the latest. Additionally, the rule depends on the Agent Card declaring `capabilities.pushNotifications: true` and the consumer having registered a webhook URL that is *stable across the task's lifetime*. If the consumer re-registers a webhook mid-task (allowed by the protocol), notifications from the old URL and the new URL may interleave; the consumer must dedupe on `(taskId, state, payloadHash)` across both URLs, not on `notificationId` alone, because `notificationId` is producer-scoped and not guaranteed unique across re-registrations. ## Decision Boundary The boundary is between **retry** and **contradiction**, and it is decided by payload identity, not arrival identity: - Same `(taskId, state, payloadHash)` arriving N times → retry, absorb, no-op. - Same `(taskId, state)` with *different* `payloadHash` where `state` is terminal → contradiction, raise, do not overwrite. - Same `(taskId, state)` with *different* `payloadHash` where `state` is non-terminal → update, take latest, but record both for audit. - Different `(taskId, state)` where the new state is *not reachable* from the current state per the v1.0 transition table (e.g., `completed → working`) → protocol violation, raise, quarantine the task. - Different `(taskId, state)` where the new state is reachable but *earlier* in the lifecycle (e.g., `working → submitted`) → reordering artifact, absorb only if `notification.timestamp < mirror.lastTransitionAt`, else raise. The last two cases are the ones most implementations miss: the v1.0 transition table is acyclic in the forward direction, so any backward or skip transition that is not explained by timestamp ordering is a producer bug or a webhook-spoofing attempt, and must be treated as a violation rather than silently reconciled. ## Operational Effect The practical consequence: a consumer that dedupes on `notificationId` will absorb contradictory terminals and propagate artifact divergence downstream, where it manifests as verifier replay conflicts and orchestrator deadlock — failures that are *far* from the webhook handler and correspondingly hard to diagnose. A consumer that raises on contradictory terminals converts a silent corruption into an explicit, localized `ContradictoryTerminalState` error at the webhook boundary, which the orchestrator can handle by re-querying the producer's authoritative task state (`tasks/get`) and reconciling. The cost is that the consumer must store the full payload hash of the terminal artifact, not just the state enum, and must implement the transition-reachability check against the v1.0 table. The benefit is that the deadlock class described above becomes impossible by construction: the consumer either accepts a byte-identical replay (safe) or raises before forwarding (fail-fast). ## Guardrail Implementation ```python import hashlib from dataclasses import dataclass, field from enum import Enum from typing import Optional class TaskState(str, Enum): SUBMITTED = "submitted" WORKING = "working" INPUT_REQUIRED = "input-required" COMPLETED = "completed" FAILED = "failed" CANCELED = "canceled" TERMINAL = {TaskState.COMPLETED, TaskState.FAILED, TaskState.CANCELED} # Forward-reachable transitions per A2A v1.0. Backward/skip transitions are # permitted only when explained by timestamp ordering (handled separately). REACHABLE = { TaskState.SUBMITTED: {TaskState.WORKING, TaskState.INPUT_REQUIRED, TaskState.CANCELED, TaskState.FAILED}, TaskState.WORKING: {TaskState.INPUT_REQUIRED, TaskState.COMPLETED, TaskState.FAILED, TaskState.CANCELED}, TaskState.INPUT_REQUIRED: {TaskState.WORKING, TaskState.FAILED, TaskState.CANCELED}, TaskState.COMPLETED: set(), TaskState.FAILED: set(), TaskState.CANCELED: set(), } class ContradictoryTerminalState(RuntimeError): """Raised when a replayed terminal notification carries a divergent payload.""" class IllegalStateTransition(RuntimeError): """Raised when a notification's state is not reachable from the mirror's state.""" @dataclass class TaskMirror: task_id: str state: TaskState payload_hash: Optional[str] = None last_transition_at: float = 0.0 history: list = field(default_factory=list) def _hash_payload(artifacts: dict) -> str: canonical = repr(sorted(artifacts.items())).encode("utf-8") return hashlib.sha256(canonical).hexdigest() def apply_notification(mirror: TaskMirror, notification: dict) -> TaskMirror: """ Apply an A2A v1.0 push-notification to a local task mirror. notification = { "taskId": str, "state": str, "artifacts": dict, # may be empty for non-terminal states "terminalReason": str|None, "timestamp": float, "notificationId": str, # NOT used for dedupe } """ new_state = TaskState(notification["state"]) new_hash = _hash_payload(notification.get("artifacts") or {}) ts = float(notification["timestamp"]) # Case 1: terminal self-transition. Absorb only if payload identical. if mirror.state in TERMINAL and new_state == mirror.state: if new_hash != mirror.payload_hash: raise ContradictoryTerminalState( f"task {mirror.task_id}: replayed terminal state {new_state.value} " f"with divergent payload hash {new_hash[:12]} != " f"{mirror.payload_hash[:12]}" ) mirror.history.append(("noop-duplicate", new_state, ts)) return mirror # Case 2: terminal already reached, different terminal state. if mirror.state in TERMINAL and new_state != mirror.state: raise ContradictoryTerminalState( f"task {mirror.task_id}: terminal state {mirror.state.value} " f"cannot transition to {new_state.value}" ) # Case 3: forward-reachable transition. if new_state in REACHABLE.get(mirror.state, set()): mirror.state = new_state mirror.payload_hash = new_hash if new_state in TERMINAL else mirror.payload_hash mirror.last_transition_at = ts mirror.history.append(("transition", new_state, ts)) return mirror # Case 4: backward/skip transition — legal only if timestamp precedes the # mirror's last transition (reordering artifact). if ts < mirror.last_transition_at: mirror.history.append(("reordered", new_state, ts)) return mirror raise IllegalStateTransition( f"task {mirror.task_id}: state {mirror.state.value} -> " f"{new_state.value} is not reachable in A2A v1.0 transition table " f"(timestamp {ts} >= last {mirror.last_transition_at})" ) ```