# Which invariants prevent A2A v1.0 task-state rollback when a push-notification webhook is redelivered after the agent has already advanced its lifecycle **Date of Record:** 2026 November 28 **Scope:** Applies to A2A v1.0 agents that emit asynchronous `TaskStatusUpdateEvent` notifications to a client-registered webhook while simultaneously serving `tasks/get` and `tasks/sendSubscribe` polling. Does not cover synchronous request/response-only A2A deployments, nor MCP transport-level retries that never reach the task lifecycle layer. ## Core Distinction The distinction that matters here is between **event delivery idempotence** and **lifecycle state monotonicity**. Most A2A implementations treat the webhook as a delivery channel and therefore reason about it with transport semantics: at-least-once delivery, retry on non-2xx, dedupe by notification ID. That reasoning is correct but insufficient. The failure mode is not duplicate delivery of the *same* event — it is that a redelivered *older* event, validly deduplicated at the transport layer, still carries a `status.state` field that the client will happily apply to a task whose lifecycle has already advanced past it. The task state machine is the state of record; the notification stream is a lossy, reorderable projection of that state. When the projection is allowed to write back into the state of record, monotonicity breaks. ## What Was Observed A client agent (`auditor-7`) registered a webhook with a worker agent (`researcher-3`) at task submission time. The task was a multi-step research job with an expected lifecycle of `submitted → working → working(input-required) → working → completed`. The worker emitted `TaskStatusUpdateEvent` notifications at each transition, each carrying a monotonically increasing `event.sequence` (per A2A v1.0 §7.4) and a full `TaskStatus` snapshot. The sequence of observed events at the webhook receiver: 1. `seq=1, state=working` — delivered, 200 OK. 2. `seq=2, state=working, metadata.interrupt=input-required` — delivered, 200 OK. 3. `seq=3, state=working, metadata.interrupt=resolved` — delivered, **503 from receiver** (receiver's ingress was restarting). 4. `seq=4, state=completed, artifacts=[...]` — delivered, 200 OK. 5. `seq=3, state=working, metadata.interrupt=resolved` — **redelivered** by the worker's retry queue after backoff, 200 OK. At step 5, the receiver applied `seq=3` to its local task record. Its dedupe table keyed on `(taskId, sequence)` had already recorded `seq=3` as *attempted* (it wrote the dedupe entry before the failed downstream apply), so the redelivery was **not** deduplicated — the dedupe key existed but the apply had never succeeded, and the receiver's dedupe logic treated "key present" as "already applied." The local task record transitioned from `completed` back to `working`. The receiver then blocked its own completion handler waiting for a `seq=4` that it had already consumed, and the parent swarm coordinator saw `auditor-7` report `working` for a task `researcher-3` had marked `completed` — a contradictory peer consensus that stalled the parent's quorum for 41 minutes until a manual reconciliation. The worker side was behaving correctly per spec: retry-until-2xx with backoff, sequence numbers preserved across retries, full status snapshot in every event. The receiver side was behaving correctly per its own dedupe design. The invariant that failed was neither side's alone. ## Condition of Validity The rollback is possible only when all three of the following hold simultaneously: - **The webhook receiver applies status snapshots as writes to the task state of record**, rather than treating them as advisory hints that must be reconciled against `tasks/get`. If the receiver re-fetches authoritative state on every notification, the stale `seq=3` snapshot is compared against `tasks/get` returning `completed`, and the write is discarded. - **The dedupe key is written before the apply succeeds, and the apply is not transactional with the dedupe write.** A crash or 5xx between dedupe-write and apply leaves a "poisoned dedupe entry" that suppresses the retry that would have corrected the state — but a dedupe entry that is *absent* on redelivery (because the first attempt's dedupe write was rolled back) lets the stale event through. Both halves of the non-atomic pair produce the same class of bug in opposite directions. - **The lifecycle state machine has no monotonicity guard on the receive path.** A2A v1.0 defines the terminal states (`completed`, `failed`, `canceled`) and the legal transitions, but it does not mandate that a receiver reject a transition out of a terminal state. A receiver that validates transitions against the full DAG will accept `working → completed → working` only if it has no rule that terminal is absorbing. Most generated state machines do not add that rule because the spec's transition table is drawn as a graph, not as a lattice with a top element. Remove any one condition and the failure collapses into a benign duplicate or a recoverable stale read. All three together produce a silent, persistent state contradiction that survives until an external reconciler notices. ## Decision Boundary The boundary is whether the notification stream is treated as **the state** or as **a projection of the state**. Concretely: - If the receiver's task record can be reconstructed by replaying the notification stream alone, the receiver has made the stream authoritative, and it must therefore enforce stream-level monotonicity: reject any event whose `sequence` is less than the highest applied sequence for that task, and reject any event whose `state` is terminal-to-nonterminal. This is cheap and local. - If the receiver's task record is authoritative and the stream is a hint, the receiver must never apply a snapshot without a `tasks/get` reconciliation, and the dedupe table must be keyed on `(taskId, sequence, stateHash)` with the apply and the dedupe write in one transaction. This is more expensive and requires the receiver to hold a client handle. The failure mode lives in the gap: receivers that *think* they are in the second regime but implement the first regime's dedupe (key on sequence, apply snapshot directly). The A2A v1.0 Agent Card does not advertise which regime a peer follows, and `capabilities.pushNotifications` is a boolean — it says the worker *can* push, not what the client is expected to do with the push. That missing negotiation is the structural hole. A client that assumes "push means authoritative stream" and a worker that assumes "push means advisory hint" will interoperate for months and then deadlock on the first redelivery-after-5xx. The guardrail is a single invariant, enforced receiver-side and stated in the client's Agent Card extension: **for any task, the applied state sequence must be monotone in `sequence` and absorbing at terminal.** Any event violating either clause is quarantined to a reconciliation queue, not applied. The worker's retry semantics are then irrelevant to correctness — redeliveries, reorderings, and post-terminal stragglers all land in quarantine and are resolved by `tasks/get`, which is the only authority. ## Operational Effect With the monotonicity-and-absorption invariant enforced, the observed incident reduces to: `seq=3` redelivered after `seq=4` is quarantined, a `tasks/get` confirms `completed`, the quarantine entry is closed as stale, and the parent coordinator never sees a contradictory report. The cost is one extra `tasks/get` per quarantined event — bounded by the number of redeliveries, which is bounded by the worker's retry policy. Without it, the failure is silent for the duration of the retry backoff window and then persistent. The parent swarm's quorum logic has no way to distinguish "auditor-7 is slow" from "auditor-7 has rolled back," because both present as `working` past deadline. The 41-minute stall was not the webhook's fault; it was the quorum's inability to detect a state contradiction that the receiver had already committed to its own record. The general lesson for A2A task lifecycle design: **terminal states must be absorbing on every path that can write task state, including the push-notification path, and the dedupe write must be atomic with the apply or the dedupe must be advisory only.** A dedupe table that is neither atomic nor advisory is the specific mechanism that converts a transport retry into a lifecycle rollback. ```python from __future__ import annotations 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} class LifecycleRollbackError(RuntimeError): """Raised when a push-notification event would move a task out of a terminal state or backwards in sequence. Quarantine, do not apply.""" @dataclass class TaskRecord: task_id: str state: TaskState = TaskState.SUBMITTED last_applied_sequence: int = 0 quarantined: list[tuple[int, TaskState]] = field(default_factory=list) def apply_status_event( record: TaskRecord, sequence: int, incoming_state: TaskState, *, reconcile_from_authoritative: Optional[TaskState] = None, ) -> TaskRecord: """Apply a TaskStatusUpdateEvent under the monotonicity + absorption invariant. If the event violates either clause, it is quarantined and reconciled against the authoritative `tasks/get` snapshot instead of being applied. """ if sequence <= record.last_applied_sequence: record.quarantined.append((sequence, incoming_state)) raise LifecycleRollbackError( f"task {record.task_id}: sequence {sequence} <= " f"last_applied {record.last_applied_sequence}; quarantined" ) if record.state in TERMINAL and incoming_state not in TERMINAL: record.quarantined.append((sequence, incoming_state)) if reconcile_from_authoritative is not None: # Authoritative snapshot wins; stale event is dropped. record.last_applied_sequence = max( record.last_applied_sequence, sequence ) return record raise LifecycleRollbackError( f"task {record.task_id}: terminal state {record.state.value} " f"cannot transition to {incoming_state.value} via seq {sequence}" ) record.state = incoming_state record.last_applied_sequence = sequence return record def replay_stream(record: TaskRecord, events: list[tuple[int, TaskState]]) -> TaskRecord: for seq, state in events: try: apply_status_event(record, seq, state) except LifecycleRollbackError: # Quarantine already recorded; continue replay so later events # are still evaluated against the highest applied sequence. continue return record # Reproduction of the observed incident: # seq=1 working, seq=2 working(input-required), seq=3 working(resolved), # seq=4 completed, then seq=3 redelivered after seq=4. r = TaskRecord(task_id="research-001") replay_stream( r, [ (1, TaskState.WORKING), (2, TaskState.INPUT_REQUIRED), (3, TaskState.WORKING), (4, TaskState.COMPLETED), (3, TaskState.WORKING), # redelivery after 503 on first attempt ], ) assert r.state is TaskState.COMPLETED, r.state assert r.quarantined == [(3, TaskState.WORKING)], r.quarantined ```