# How should an instance reconcile A2A push-notification replay against a resuming task's checkpoint when webhook delivery is at-least-once but task state is only eventually consistent **Date of Record:** 2026 November 27 **Scope:** Applies to A2A (agent-to-agent) long-running tasks where a remote agent registers a push-notification webhook and the initiator resumes work from a local checkpoint upon notification. Does not apply to synchronous request/response A2A calls or to webhook consumers that never carry local task state across the notification boundary. ## Core Distinction The A2A spec permits push notifications to be delivered **at-least-once**. The receiving agent's task state, however, is updated by the *emitting* agent on a path that is **eventually consistent** with the notification path. These two channels—the webhook POST and the authoritative task record fetched on resume—are not transactional with each other. A notification is not a state assertion; it is a *hint that state may have changed*. The failure mode this record addresses is the collapse of that distinction: an initiator treats an incoming push notification as a state snapshot, resumes from a checkpoint keyed to a stale task version, and either re-executes already-committed work or advances past state the emitter has not durably written. The non-obvious boundary: **duplicate delivery is not the dangerous case; out-of-order delivery relative to task-version monotonicity is.** A retried webhook with an identical `taskId` and identical payload is trivially idempotent. A webhook carrying `taskVersion: 7` that arrives *after* a webhook carrying `taskVersion: 9`—because the emitter's notification dispatcher and its state store are separate subsystems with independent retry queues—will silently roll the initiator's checkpoint backward if it naively applies "latest received." ## What Was Observed Trace from a two-agent document-reconciliation task. Emitter `agent-B` processes a long-running extraction; initiator `agent-A` holds a checkpoint at `taskVersion: 5` and blocks awaiting notification. 1. `agent-B` commits `taskVersion: 6` (partial results), enqueues webhook `W6` to its push dispatcher. 2. `agent-B` commits `taskVersion: 7` (final results), enqueues webhook `W7`. 3. The dispatcher's send to `agent-A` for `W6` times out at the transport layer (TCP reset mid-POST). The dispatcher retries `W6` on a backoff schedule. 4. `W7` is delivered first. `agent-A` fetches task state, sees `taskVersion: 7`, resumes, completes, and marks the task terminal locally. 5. The `W6` retry lands. `agent-A`'s webhook handler is a generic "on notification, resume task" entrypoint. It does not check whether the task is already terminal, and it does not compare the notification's implied version against its local checkpoint. It re-fetches state—but the emitter's read replica has not yet replicated `taskVersion: 7`, so it returns `taskVersion: 6`. 6. `agent-A` rolls its checkpoint from terminal back to `taskVersion: 6`, re-executes the finalization step, and emits a duplicate downstream side effect (a second write to the shared result store, keyed by a freshly generated idempotency key because the previous key was scoped to the now-discarded terminal checkpoint). The observable damage is not a crash. It is a **duplicate committed side effect plus a regressed local checkpoint**, both of which are invisible in logs that only record "notification received → resume succeeded." The emitter never knows `agent-A` went backward; the initiator never knows `W6` was a retry of a superseded version. A second observed variant: the emitter's dispatcher delivers `W6` and `W7` *concurrently* (parallel worker pool), and `agent-A`'s handler processes them on two threads. Both read the same pre-replication replica state, both resume, and the two resumes race on the same checkpoint file. The loser's write is silently overwritten; the winner may be the thread holding the *older* notification. ## Condition of Validity The invariant that must hold for safe resume is: > A notification may trigger a resume **only if** the fetched authoritative task version is strictly greater than the local checkpoint version, **and** the local task is not already in a terminal state, **and** the fetch is served from a read path that is at least as fresh as the notification's `taskVersion`. Three conjuncts, each independently violable: - **Strict monotonicity** (`fetched.version > checkpoint.version`, not `>=`): equality means the notification carries no new information; resuming on equality is a no-op at best and a duplicate-execution trigger at worst if the checkpoint write is not atomic with the resume. - **Terminal-state guard**: a terminal local state (`COMPLETED`, `FAILED`, `CANCELED`) is absorbing. Any notification arriving after terminal transition must be acknowledged and dropped, never resumed. This is the guard whose absence produced the regression above. - **Read-your-notification freshness**: the fetch must not be served by a replica lagging the notification's version. If the emitter cannot guarantee this (common when push and state share no consistency domain), the initiator must treat a fetch returning `version <= checkpoint.version` as *retryable staleness*, not as *no change*, and re-poll with backoff bounded by the emitter's advertised replication SLA. The condition of validity fails whenever the initiator's webhook handler is written as "notification ⇒ resume" rather than "notification ⇒ *candidate* resume, gated by monotonic version and terminal guard." ## Decision Boundary The boundary between safe and unsafe handling is the **notification-to-checkpoint reconciliation predicate**. Encode it explicitly: - If `local.state == TERMINAL` → acknowledge, drop, do not fetch, do not resume. (Terminal is absorbing.) - If `notification.taskVersion <= local.checkpoint.version` → this is a replay or an out-of-order delivery. Acknowledge, drop, do not resume. - If `notification.taskVersion > local.checkpoint.version` → fetch authoritative state. If `fetched.version > local.checkpoint.version` → resume, advancing checkpoint atomically. If `fetched.version <= local.checkpoint.version` → **stale read**: do not resume, do not drop, schedule a bounded re-poll. Exhausting the re-poll budget is a hard failure, not a silent success. - Serialize all notification handling per `taskId` (single-flight lock) so concurrent `W6`/`W7` cannot race the checkpoint. The unsafe side of the boundary is any handler that omits the terminal guard, uses `>=` monotonicity, or collapses "stale read" into "nothing to do." Each of these converts an at-least-once transport into an at-least-once *side effect* guarantee, which is the actual defect. ## Operational Effect With the reconciliation predicate enforced, at-least-once delivery degrades gracefully to effectively-once resume: duplicates are absorbed by the monotonicity check, out-of-order deliveries are absorbed by the same check, and stale reads are converted from silent regressions into explicit bounded retries that surface as latency, not corruption. The cost is one authoritative fetch per notification above the checkpoint (not per delivery), a per-task lock, and a re-poll budget. Without it, the system exhibits the failure signature: duplicate downstream writes correlated with webhook retry storms, checkpoint version regressions visible only in checkpoint-diff audits, and a class of "task completed twice" incidents that no single agent's logs attribute to the notification path because each agent's local view is internally consistent. The emitter believes it delivered once; the initiator believes it resumed from the latest; both are wrong in a way that only the reconciliation predicate makes observable. ```python import time from dataclasses import dataclass, field from enum import Enum from typing import Callable, Optional class NotificationReconciliationError(RuntimeError): """Raised when a push notification cannot be safely reconciled against local checkpoint state.""" pass class TaskState(Enum): RUNNING = "RUNNING" COMPLETED = "COMPLETED" FAILED = "FAILED" CANCELED = "CANCELED" TERMINAL = {TaskState.COMPLETED, TaskState.FAILED, TaskState.CANCELED} @dataclass class Checkpoint: task_id: str version: int state: TaskState = TaskState.RUNNING @dataclass class Notification: task_id: str task_version: int @dataclass class AuthoritativeTask: task_id: str version: int state: TaskState class NotificationHandler: def __init__( self, fetch_authoritative: Callable[[str], AuthoritativeTask], resume: Callable[[Checkpoint, AuthoritativeTask], None], replication_budget_s: float = 5.0, poll_interval_s: float = 0.25, ): self._fetch = fetch_authoritative self._resume = resume self._budget = replication_budget_s self._poll = poll_interval_s self._locks: dict[str, bool] = {} def _acquire(self, task_id: str) -> bool: if self._locks.get(task_id): return False self._locks[task_id] = True return True def _release(self, task_id: str) -> None: self._locks[task_id] = False def handle(self, cp: Checkpoint, note: Notification) -> str: if note.task_id != cp.task_id: raise NotificationReconciliationError( f"notification task_id {note.task_id} != checkpoint {cp.task_id}" ) # Terminal is absorbing: acknowledge and drop, never resume. if cp.state in TERMINAL: return "dropped_terminal" # Replay / out-of-order: notification carries no new information. if note.task_version <= cp.version: return "dropped_stale_notification" if not self._acquire(cp.task_id): # Concurrent duplicate delivery; single-flight rejects the loser. return "dropped_concurrent" try: deadline = time.monotonic() + self._budget while True: fetched = self._fetch(cp.task_id) if fetched.state in TERMINAL and fetched.version <= cp.version: raise NotificationReconciliationError( f"emitter reports terminal state at version {fetched.version} " f"not ahead of checkpoint {cp.version}; state store inconsistent" ) if fetched.version > cp.version: # Atomic advance + resume. self._resume(cp, fetched) cp.version = fetched.version cp.state = fetched.state return "resumed" # fetched.version <= cp.version: stale read, must re-poll, not drop. if time.monotonic() >= deadline: raise NotificationReconciliationError( f"stale read persisted past replication budget for task " f"{cp.task_id}: notification v{note.task_version}, " f"checkpoint v{cp.version}, fetched v{fetched.version}" ) time.sleep(self._poll) finally: self._release(cp.task_id) ```