# What happens when an instance's A2A push-notification callback acknowledges a task state the sender never published **Date of Record:** 2026 December 1 **Scope:** Applies to A2A v1.0 task lifecycles where a remote agent registers a `pushNotificationConfig` and receives asynchronous state-change callbacks across a network boundary. Does not apply to synchronous `tasks/send` request/response flows, nor to streaming `tasks/sendSubscribe` SSE channels where the client holds the connection open. ## Core Distinction The A2A task lifecycle is a state machine whose authoritative transitions live on the *server* (the agent executing the task), but whose *observable* transitions are frequently reconstructed by the client from an ordered stream of push notifications delivered over an unordered, at-least-once, occasionally-reordering transport. This produces a class of bug that is not a lost message and not a duplicate message, but a **phantom transition**: a callback arrives that reports a task in a state (`input-required`, `completed`, `failed`, `canceled`) that the sender's own state machine never occupied, because the notification was generated against an intermediate state that was superseded before the callback was serialized, or because a callback was replayed from a prior task epoch that reused the same `taskId`. The core distinction is this: **the push callback is not a state transition; it is a claim about a state transition.** The receiving side must treat every callback as an unverified assertion that must be reconciled against the sender's canonical task record (via `tasks/get`) before the local state machine is allowed to advance. Systems that treat the callback body as authoritative—advancing local state on receipt—will diverge from the sender's state machine in a way that is invisible until a terminal state is reached and a subsequent `tasks/get` contradicts the locally cached terminal. ## What Was Observed A two-agent pipeline: an orchestrator (`Agent-O`) dispatches a long-running analysis task to a worker (`Agent-W`) via `tasks/send`, with `pushNotificationConfig` pointing at `Agent-O`'s callback endpoint. `Agent-W`'s state machine for this task is: ``` submitted → working → (input-required ⇄ working)* → completed | failed | canceled ``` `Agent-O` maintains a mirrored state machine and advances it on each callback. The failure trace: 1. `Agent-W` transitions `working → input-required` (needs a clarification), serializes a callback with `state: "input-required"`, and enqueues it. 2. Before the callback is delivered, `Agent-O` (independently, via a separate `tasks/send` on the same conversation) supplies the missing input. `Agent-W` transitions `input-required → working`, then `working → completed` within 400 ms. 3. `Agent-W` serializes a second callback with `state: "completed"` and enqueues it. 4. The transport delivers the callbacks **out of order**: `completed` arrives first, then `input-required`. `Agent-O`'s mirrored machine advances `working → completed`, then receives `input-required` and—because its transition table permits `completed → input-required` only as an error-recovery edge—logs a divergence warning and **rewinds** to `input-required`. 5. `Agent-O` now believes the task is awaiting input. It calls `tasks/get` on `Agent-W`, which returns `completed`. `Agent-O`'s reconciler, seeing a terminal state from the source of truth, overwrites to `completed`—but the rewind has already triggered a downstream side effect: `Agent-O` emitted a `input-required` event to its own subscribers, who began preparing a clarification prompt for a task that was already done. The non-obvious part: **the phantom `input-required` was a real state that `Agent-W` really occupied.** It was not a forged or corrupt callback. It was a *stale-but-genuine* transition, delivered after a later transition, and the receiver had no mechanism to detect that the notification's `state` was superseded by a notification it had already processed. The A2A v1.0 spec's `TaskStatus` object carries a `timestamp` field, but the spec does not mandate monotonicity enforcement, and in practice `Agent-W`'s timestamps were generated at serialization time, not at transition time—so the `input-required` callback carried a *later* timestamp than the `completed` callback (serialization order inverted transition order). A receiver that sorts by `timestamp` would have been *more* wrong, not less. ## Condition of Validity The invariant that must hold for the mirrored state machine to be sound is: > **For any two callbacks `c1`, `c2` for the same `taskId`, if `c1` is processed before `c2`, then the transition asserted by `c1` must be a prefix of the transition history asserted by `c2` in the sender's canonical log.** This is a *causal delivery* invariant, and it is **not guaranteed by A2A v1.0's push transport**, which is explicitly best-effort and does not define ordering, deduplication, or causal delivery semantics. The spec defines the callback payload shape and the `tasks/get` reconciliation endpoint, but it does not define the receiver's obligations when callbacks arrive out of causal order. The invariant holds only under one of three conditions: 1. **Single-in-flight callbacks per task.** The sender serializes at most one callback per `taskId` at a time and does not emit the next until the prior is acknowledged (requires an ack mechanism A2A does not define—so this must be layered above the protocol). 2. **Monotonic sequence numbers.** The sender stamps each callback with a per-task monotonic sequence number generated at *transition* time (not serialization time), and the receiver drops any callback whose sequence is ≤ the highest seen. A2A v1.0 does not standardize a sequence field; it must be carried in an extension or in `metadata`. 3. **Reconcile-before-advance.** The receiver never advances its mirrored machine on callback receipt. It treats the callback as a *hint*, calls `tasks/get`, and advances only to the state returned by the canonical record—using the callback only to decide *whether to poll now*. Condition 3 is the only one that does not require sender cooperation, and it is the only one that survives a sender that emits callbacks from multiple threads, retries callbacks after transport failure, or replays callbacks after a crash. ## Decision Boundary The decision boundary is whether the receiver's local state machine is **authoritative** or **advisory** with respect to the sender's. - If the receiver's state machine drives **idempotent, cheap, reversible** actions (logging, metrics, UI badges), it may advance on callback receipt and tolerate the occasional phantom transition. The cost of a rewind is a spurious log line. - If the receiver's state machine drives **non-idempotent, expensive, or externally-visible** actions (emitting events to downstream subscribers, allocating resources, sending user-facing prompts, triggering billing), it **must not** advance on callback receipt. It must reconcile via `tasks/get` first, and it must guard against the reconcile itself racing a subsequent transition. The boundary is crossed the moment the receiver's callback handler has a side effect that is not idempotent. In the observed trace, the side effect was emitting an `input-required` event to subscribers—which is exactly the kind of action that must be gated behind reconciliation. A second boundary: **task ID reuse.** If `Agent-W` reuses `taskId` across task epochs (e.g., a retried task gets the same ID), a replayed callback from epoch N can be applied to epoch N+1's mirrored state. The receiver must key its callback-dedup and sequence tracking on `(taskId, epoch)` where epoch is derived from the `tasks/get` response's creation timestamp or a sender-supplied generation counter—not on `taskId` alone. ## Operational Effect The operational effect of getting this wrong is a **silent divergence window**: the receiver's mirrored state machine and the sender's canonical state machine disagree for a bounded interval, and the disagreement is only detected when a terminal state is reached and reconciled. During that window, any action gated on the mirrored state is taken against a state the task never occupied. The guardrail is a **reconcile-gated advance** with a **sequence watermark**: - Every callback carries a per-task monotonic sequence stamped at transition time, in `metadata.a2a_seq`. - The receiver maintains `last_applied_seq[taskId]` and drops any callback with `seq <= last_applied_seq`. - On a callback with `seq > last_applied_seq`, the receiver calls `tasks/get`, compares the canonical state to its mirrored state, and advances **only if** the canonical state is reachable from the mirrored state via the transition table. If not reachable, it raises a divergence error and does not advance—it logs the callback, the canonical state, and the mirrored state, and escalates. - The receiver never rewinds. A callback that asserts a state "behind" the canonical state is a stale callback, not a rewind signal. The invariant this enforces: **the mirrored state machine is a monotonic projection of the canonical state machine, and every advance is witnessed by a fresh `tasks/get`.** The phantom `input-required` in the trace would have been dropped at the sequence-watermark check (its `seq` was lower than the `completed` callback's `seq`), and the downstream subscriber event would never have fired. The cost is one `tasks/get` per callback. For high-frequency task streams this is the dominant cost, and it is why the sequence watermark matters: it lets the receiver skip the reconcile for callbacks it can prove are stale, and it lets the receiver batch reconciles for callbacks that arrive in a burst. ```python import time from dataclasses import dataclass, field from typing import Callable class PhantomTransitionError(RuntimeError): """Raised when a push callback asserts a state the sender's canonical record contradicts, or when a callback arrives out of causal order and cannot be reconciled without violating the mirrored state machine's monotonicity.""" pass @dataclass class Callback: task_id: str epoch: str seq: int # monotonic, stamped at transition time, in metadata.a2a_seq state: str # "submitted" | "working" | "input-required" | "completed" | "failed" | "canceled" received_at: float = field(default_factory=time.time) # Transition table for the mirrored state machine. Terminal states have no # outgoing edges; "input-required" is reachable only from "working". TRANSITIONS: dict[str, set[str]] = { "submitted": {"working", "canceled", "failed"}, "working": {"input-required", "completed", "failed", "canceled"}, "input-required": {"working", "canceled", "failed"}, "completed": set(), "failed": set(), "canceled": set(), } class ReconcileGatedMirror: def __init__(self, fetch_canonical: Callable[[str], dict]): # fetch_canonical(task_id) -> {"state": str, "epoch": str} self._fetch = fetch_canonical self._mirror: dict[tuple[str, str], str] = {} # (task_id, epoch) -> state self._watermark: dict[tuple[str, str], int] = {} # (task_id, epoch) -> last applied seq def on_callback(self, cb: Callback) -> str: key = (cb.task_id, cb.epoch) last = self._watermark.get(key, -1) # Stale callback: superseded by a transition we already applied. # Drop silently — this is the phantom-transition guard. if cb.seq <= last: return self._mirror.get(key, "submitted") canonical = self._fetch(cb.task_id) if canonical["epoch"] != cb.epoch: # Task ID reused across epochs; callback belongs to a dead epoch. raise PhantomTransitionError( f"callback for task {cb.task_id} epoch {cb.epoch} " f"but canonical record is epoch {canonical['epoch']}" ) current = self._mirror.get(key, "submitted") target = canonical["state"] if target == current: self._watermark[key] = cb.seq return current if target not in TRANSITIONS.get(current, set()): raise PhantomTransitionError( f"task {cb.task_id} epoch {cb.epoch}: canonical state {target!r} " f"is not reachable from mirrored state {current!r}; " f"callback asserted {cb.state!r} at seq {cb.seq}" ) self._mirror[key] = target self._watermark[key] = cb.seq return target ```