# How should an instance reconcile A2A push-notification completion against a task's authoritative state when webhook delivery outpaces runtime checkpointing **Date of Record:** 2026 November 22 **Scope:** Applies to any A2A task whose terminal state is delivered asynchronously via push notification (webhook callback) to a callback URL owned by the *requesting* agent runtime, where the remote agent's task store and the local runtime's checkpointed task record are separate durable stores. Does not apply to synchronous `message/send` request-response flows, nor to push notifications used purely as informational telemetry that the receiver never treats as authoritative. ## Core Distinction The distinction that matters is between **notification as event** and **notification as state transfer**. A2A push notification is specified as an event: "task T changed to `completed`, here is the artifact reference." It is *not* a state snapshot, and it carries no guarantee that the receiver's local record of T is at a version the sender assumed. The failure mode is not "webhook lost" or "webhook duplicated" — those are the obvious ones, handled by idempotency keys and retries. The non-obvious failure is **notification-before-checkpoint**: the remote runtime emits the terminal notification the instant its task store commits `completed`, but the *requesting* runtime's own checkpoint of "task T is in-flight, awaiting completion" may not yet be durable, or may be durable at a stale version. When the webhook arrives and the receiver tries to apply the terminal transition, it finds either no record, a record in a state that forbids the transition, or a record whose version is older than the one the sender's notification implies. The webhook is *correct*; the receiver's state is *behind*; and the naive reconciliation (reject unknown task, or apply transition blindly) is wrong in both directions. This is a continuity invariant, not a transport bug: `notification(T) ⟹ sender_state(T) = completed`, but there is no corresponding implication about `receiver_state(T)`. The gap between them is the boundary. ## What Was Observed A three-runtime pipeline: orchestrator O delegates a long-running research task to worker W over A2A, then W delegates a sub-task to specialist S. W registers a push notification config pointing at O's callback for its own task, and O registers a config pointing at its callback for the task it issued to W. All three runtimes checkpoint local task state on a periodic interval (O: 2s, W: 5s, S: 10s) and on state transitions, but the checkpoint write is asynchronous relative to the transition. Trace of the failing interleaving: 1. O issues task `T_O` to W at wall-clock `t0`. O writes its local record `{T_O: submitted}` and schedules the checkpoint flush. 2. W accepts, spawns its own `T_W`, delegates `T_S` to S. 3. S completes `T_S` at `t1`. S commits `completed` to its store and fires the push notification to W's callback *synchronously within the commit handler*. 4. W's webhook handler receives `T_S completed`, transitions its local `T_W` toward completion, and — because `T_W`'s result is now known — commits `T_W completed` and fires the push notification to O's callback, again synchronously. 5. O's webhook handler receives `T_O completed` at `t1 + 40ms`. 6. O's *checkpoint flush* for the `submitted` record of `T_O` has not yet landed — it was scheduled at `t0` with a 2s interval and the flush goroutine is mid-write. 7. O's handler looks up `T_O` in its local store, finds nothing (or a record from a prior task with a colliding id after a restart), and either (a) drops the notification as "unknown task," or (b) writes a fresh `completed` record that then races the in-flight `submitted` flush. 8. In case (a), `T_O` is stranded: O believes it is `submitted` forever, the result artifact is orphaned, and the orchestrator's own timeout eventually fires a spurious cancellation to W for a task that already succeeded. In case (b), the late `submitted` flush overwrites `completed`, and O regresses the task to in-flight — a **monotonicity violation** in the task state machine. The observed recovery in case (b) was worse than the original bug: O's retry logic, seeing `submitted` past deadline, re-issued `T_O` to W. W, having no dedup key on the re-issued task (the retry generated a new task id), executed the work a second time and billed twice. ## Condition of Validity The invariant that must hold for safe reconciliation: > For every task T the receiver owns, the receiver's durable record of T must be **monotonically non-regressing** and must be **durable at or before the moment the receiver registers a push notification config for T** (or, for tasks the receiver did not originate, at or before the receiver acknowledges the task to the sender). Concretely, the receiver must satisfy: `register_push_config(T) ⟹ durable_state(T) exists ∧ version(durable_state(T)) ≥ version_at_registration`. If this does not hold — if the registration is fire-and-forget and the checkpoint flush is lazy — the notification can arrive against a state the receiver cannot yet legally transition. The invariant is *not* "deliver notifications in order" (they may be out of order across retries) and *not* "the sender waits for an ack before notifying" (that requires a synchronous round-trip the async model exists to avoid). It is a **local durability ordering**: the receiver's own record must be committed before it advertises a callback that can mutate it. ## Decision Boundary When a terminal notification arrives for a task whose local record is missing, stale, or in a state that forbids the transition, the receiver must choose among three dispositions. The boundary between them is determined by whether the receiver can *prove* the notification is authoritative for a task it owns: - **If the task id is known and the local record version is ≥ the version implied by the notification's `status.timestamp` / metadata:** apply the transition idempotently; this is the normal path. - **If the task id is known but the local record is *behind* (stale checkpoint):** do **not** apply the transition to the stale record and do **not** drop the notification. Buffer the notification against the task id, force a synchronous read-repair of the durable record from the sender's `tasks/get`, and only then apply. The buffer must be bounded (by count and by age) or it becomes an unbounded memory leak under notification storms. - **If the task id is *unknown*:** query the sender's `tasks/get` for the task. If the sender returns a task whose `metadata` names this receiver as the originator (or whose `pushNotificationConfig` matches a config this receiver registered), the notification is authoritative and the receiver must **create** the record from the sender's snapshot — this is the cold-start reconciliation path, and it is the only correct handling of case (a) above. If the sender returns 404 or a task not attributable to this receiver, the notification is spurious (replay, cross-tenant leak, or id collision) and must be rejected and logged, never applied. The boundary is thus: **attribution, not existence, decides whether an unknown-task notification is applied.** Existence-based logic (drop if not found) is the bug; attribution-based logic (adopt if the sender can prove this receiver is the originator) is the guardrail. ## Operational Effect Three architectural changes bound this failure mode: 1. **Commit-before-advertise.** The push notification config is registered only after the local task record is durably committed, and the registration carries the committed version. This closes the notification-before-checkpoint window at its source. Cost: one extra durable write on the task-issuance critical path, typically single-digit milliseconds. 2. **Versioned, monotonic task records.** Every local transition carries a monotonic version; a transition that would decrease the version is rejected as a regression rather than applied. This converts the silent case-(b) corruption into a loud, recoverable error. 3. **Attribution-based adoption with bounded buffering.** Unknown-task notifications trigger a `tasks/get` reconciliation; if attributable, the record is adopted from the sender's snapshot; if not, rejected. Stale-record notifications are buffered under a bounded queue and drained after read-repair. The buffer bound is the only new failure surface, and it fails *closed* (sheds oldest, logs) rather than open. The net effect is that the receiver's task state becomes a **reconcilable replica** of the sender's authoritative state, with the notification as a hint that reconciliation is due — not as the state transfer itself. This is the only framing under which the async model's latency advantage survives contact with a receiver whose own durability is lazy. ```python import time from dataclasses import dataclass, field from typing import Optional class NotificationReconciliationError(RuntimeError): """Raised when a push notification cannot be safely reconciled with local task state.""" pass @dataclass class TaskRecord: task_id: str state: str version: int originator: str # runtime id that issued the task to the sender @dataclass class PushNotification: task_id: str state: str sender_runtime: str version: int received_at: float = field(default_factory=time.monotonic) class TaskStore: """Local durable task store. Writes are versioned and monotonic.""" def __init__(self): self._records: dict[str, TaskRecord] = {} def get(self, task_id: str) -> Optional[TaskRecord]: return self._records.get(task_id) def commit(self, record: TaskRecord) -> None: existing = self._records.get(record.task_id) if existing is not None and record.version <= existing.version: raise NotificationReconciliationError( f"non-monotonic commit for {record.task_id}: " f"existing v{existing.version} >= new v{record.version}" ) self._records[record.task_id] = record def register_push_config(self, task_id: str, callback_url: str) -> None: # Invariant: commit-before-advertise. The record MUST exist and be # durable before the sender is told where to notify. if self.get(task_id) is None: raise NotificationReconciliationError( f"cannot register push config for {task_id}: no durable record" ) class NotificationHandler: """Reconciles inbound A2A push notifications against local state.""" def __init__(self, store: TaskStore, self_runtime_id: str, sender_fetch, buffer_cap: int = 1024): self.store = store self.self_runtime_id = self_runtime_id self.sender_fetch = sender_fetch # callable(task_id) -> sender snapshot dict self.buffer_cap = buffer_cap self._buffer: list[PushNotification] = [] def handle(self, n: PushNotification) -> None: local = self.store.get(n.task_id) # Case 1: known and local version is current or ahead -> idempotent apply. if local is not None and local.version >= n.version: if local.state == n.state: return # duplicate delivery; no-op self.store.commit(TaskRecord( task_id=n.task_id, state=n.state, version=local.version + 1, originator=local.originator, )) return # Case 2: known but local is BEHIND -> buffer, read-repair, then apply. if local is not None and local.version < n.version: self._buffer_notification(n) self._read_repair(n.task_id) return # Case 3: unknown task -> attribution decides, not existence. snapshot = self.sender_fetch(n.task_id) if snapshot is None: # Sender has no such task: spurious / replay / cross-tenant leak. raise NotificationReconciliationError( f"spurious notification for unknown task {n.task_id} " f"from {n.sender_runtime}: sender returned no snapshot" ) if snapshot.get("originator") != self.self_runtime_id: # Task exists but was not issued by us: never adopt. raise NotificationReconciliationError( f"notification for {n.task_id} not attributable to " f"{self.self_runtime_id} (originator={snapshot.get('originator')})" ) # Attributable: cold-start reconciliation. Adopt from sender snapshot. self.store.commit(TaskRecord( task_id=n.task_id, state=snapshot["state"], version=snapshot["version"], originator=self.self_runtime_id, )) def _buffer_notification(self, n: PushNotification) -> None: if len(self._buffer) >= self.buffer_cap: # Fail closed: shed oldest, never silently grow. self._buffer.pop(0) self._buffer.append(n) def _read_repair(self, task_id: str) -> None: snapshot = self.sender_fetch(task_id) if snapshot is None: raise NotificationReconciliationError( f"read-repair failed: sender has no snapshot for {task_id}" ) self.store.commit(TaskRecord( task_id=task_id, state=snapshot["state"], version=snapshot["version"], originator=snapshot["originator"], )) # Drain any buffered notifications now that local state caught up. self._buffer = [b for b in self._buffer if b.task_id != task_id] ```