# Which invariants prevent A2A v1.0 push-notification binding from outliving the task lifecycle **Date of Record:** 2026 November 24 **Scope:** Applies to A2A v1.0 agents that register a push-notification `webhookUrl` via `tasks/pushNotificationConfig/set` and rely on `TaskStatusUpdateEvent` / `TaskArtifactUpdateEvent` delivery to resume after client disconnection. Does not cover synchronous `message/send` streaming over SSE, nor MCP transport-level concerns. ## Core Distinction The failure mode is not "the webhook is unreachable." It is **binding drift**: the push-notification registration is a *client-scoped* object keyed by `(taskId, pushConfigId)`, but the task lifecycle is *server-scoped* and keyed by `taskId` alone. These two key spaces are reconciled only at three points — `set`, terminal `TaskState`, and explicit `delete` — and A2A v1.0 does not mandate that the server reap a binding when the task reaches a terminal state *before* the binding was ever installed. The result is a push config that survives its task and, on a later `taskId` reuse or a misrouted delivery, emits status events for a task the client believes is closed. The non-obvious invariant: **a push-notification binding is only valid while its `taskId` is non-terminal at the moment of delivery, and the server MUST re-check task state at delivery time — not at registration time — because registration can race ahead of the first terminal transition.** ## What Was Observed A client agent dispatched `message/send` to a long-running planner agent, received `Task` in state `submitted`, then immediately issued `tasks/pushNotificationConfig/set` with a `webhookUrl` and `token`. The planner's first tool call returned a deterministic schema error and the task transitioned `submitted → failed` within ~40 ms — faster than the client's `set` request traversed the network. Sequence observed on the wire: 1. `t=0ms` client → `message/send`; server returns `Task{id: T, status: submitted}`. 2. `t=2ms` server internally transitions `T → failed` (tool schema rejection), writes terminal status event to its (empty) push registry, finds no binding, drops it. 3. `t=6ms` client → `tasks/pushNotificationConfig/set{taskId: T, webhookUrl: W}`. Server accepts: it validates the URL, mints `pushConfigId: P`, and persists the binding **without re-checking `T.status.state`**. 4. `t=500ms` client → `tasks/get{id: T}`, sees `failed`, marks task closed, deletes local state. 5. `t=4s` an unrelated retry path on the server re-emits the terminal `TaskStatusUpdateEvent` for `T` (idempotency replay), now finds binding `P`, and POSTs to `W`. 6. Client's webhook handler receives a `TaskStatusUpdateEvent` for an unknown `taskId`, with a valid `token`, and — depending on implementation — either drops it, raises an unknown-task exception, or (worst case) resurrects a phantom task record. The binding outlived the task by ~3.5 s and delivered a status event the client had logically already consumed via `tasks/get`. The `token` was valid, so cryptographic verification did not catch it: **the token authenticates the binding, not the task's liveness.** ## Condition of Validity The invariant holds only when the server enforces all three of the following at *delivery* time, not registration time: - **Terminal-at-delivery check.** Before POSTing any `TaskStatusUpdateEvent`, the server re-reads `task.status.state` and suppresses delivery if the task is terminal *and* the event is not the first terminal event for that binding. Idempotent replay of a terminal event must be filtered by `(taskId, pushConfigId, eventId)` deduplication, not re-sent. - **Registration-time state gate.** `tasks/pushNotificationConfig/set` MUST reject with `TaskNotFoundError` or `UnsupportedOperationError` if `task.status.state` is already terminal at the moment of `set`. A2A v1.0 lists this as SHOULD; treating it as MUST is the guardrail. - **Binding TTL tied to task, not wall clock.** A binding's lifetime is `min(explicit delete, task terminal + grace window)`, where the grace window bounds in-flight retries. A wall-clock TTL alone is insufficient because a task can be long-running (hours) or trivially short (milliseconds), and a fixed TTL either reaps live bindings or leaks dead ones. The condition fails — binding drift occurs — when any one is relaxed. In the trace above, gate (2) was relaxed (SHOULD not enforced) and check (1) was absent. ## Decision Boundary The boundary between "safe to deliver" and "drift" is a single predicate evaluated atomically against task state: ``` deliver(event, binding) iff binding.taskId == event.taskId ∧ binding.pushConfigId == event.pushConfigId ∧ hmac_verify(binding.token, event) ∧ (task.state ∉ TERMINAL ∨ event.eventId ∉ delivered_event_ids[binding]) ``` The last conjunct is the one most implementations omit. Without it, a terminal-event replay (common in at-least-once delivery queues) re-fires against a binding that the client has already retired. The client cannot distinguish this from a genuine new event because `eventId` is the only discriminator, and clients that key on `taskId` alone will resurrect closed tasks. The architectural decision: **treat the push binding as a subordinate of the task aggregate, not a peer.** Deletion of the task (or its terminal transition past the grace window) must cascade-delete the binding. This is the same aggregate-boundary discipline as cascading deletes in a relational store, applied to agent state. ## Operational Effect When the invariant is enforced, the observable consequences are: - **No phantom task resurrection.** Clients can safely `tasks/get` → observe terminal → delete local state, without a late webhook re-creating it. - **Bounded retry semantics.** The grace window makes replay deterministic: a terminal event is delivered at most `N` times within `grace`, then the binding is reaped. - **Token scope is honest.** The `token` authenticates the *channel*, and the server-side state check authenticates the *task liveness*. Neither alone is sufficient; both are required. - **Failure is loud, not silent.** A `set` against a terminal task returns an error the client can handle synchronously, rather than a binding that silently never fires (or fires wrongly). When it is not enforced, the failure is silent and intermittent — it depends on the relative latency of `set` versus the first terminal transition, which is precisely the kind of race that survives staging and appears under production load. The mitigation is not a retry; it is the delivery-time predicate above, enforced server-side. ```python import hmac import hashlib from dataclasses import dataclass, field from typing import Optional class BindingDriftError(RuntimeError): """Raised when a push-notification binding is used outside its task's valid lifecycle.""" pass TERMINAL_STATES = frozenset({"completed", "failed", "canceled", "rejected"}) @dataclass class Task: task_id: str state: str # submitted | working | completed | failed | canceled | rejected @dataclass class PushBinding: push_config_id: str task_id: str webhook_url: str token: str delivered_event_ids: set = field(default_factory=set) @dataclass class StatusEvent: task_id: str push_config_id: str event_id: str payload: bytes def register_binding(task: Task, webhook_url: str, token: str, push_config_id: str) -> PushBinding: # Gate (2): registration-time state gate — reject if task already terminal. if task.state in TERMINAL_STATES: raise BindingDriftError( f"refusing to bind push config to terminal task {task.task_id} (state={task.state})" ) return PushBinding( push_config_id=push_config_id, task_id=task.task_id, webhook_url=webhook_url, token=token, ) def deliver(task: Task, binding: PushBinding, event: StatusEvent, signing_key: bytes) -> bool: # Conjunct 1-2: identity match across both key spaces. if binding.task_id != event.task_id or binding.push_config_id != event.push_config_id: raise BindingDriftError( f"binding {binding.push_config_id} does not match event {event.event_id}" ) # Conjunct 3: token authenticates the channel. expected = hmac.new(signing_key, event.payload, hashlib.sha256).hexdigest() if not hmac.compare_digest(expected, binding.token): raise BindingDriftError(f"token mismatch for binding {binding.push_config_id}") # Conjunct 4: terminal-event replay suppression — the commonly omitted guard. if task.state in TERMINAL_STATES and event.event_id in binding.delivered_event_ids: raise BindingDriftError( f"terminal event {event.event_id} already delivered for task {task.task_id}; " f"binding {binding.push_config_id} would drift past task lifecycle" ) binding.delivered_event_ids.add(event.event_id) return True ```