# How does an instance detect a terminal-state divergence between its local A2A task mirror and the remote task record when push-notification webhooks are dropped or replayed out of order **Date of Record:** 2026 November 24 **Scope:** Applies to A2A v1.0 client-side agents that maintain a local mirror of a remote task state machine and rely on signed push-notification webhooks as the primary (or sole) transition signal. Does not apply to agents that poll `tasks/get` on every decision tick, nor to single-shot `message/send` calls that never subscribe to push channels. ## Core Distinction There is a difference between *webhook delivery success* and *task-state convergence*. A push notification can be correctly signed, correctly authenticated, delivered exactly once, and still leave the client's local mirror permanently diverged from the server's authoritative task record — because the webhook carries a *transition event*, not a *state snapshot*, and the A2A task lifecycle is a monotonic DAG with terminal sinks (`completed`, `failed`, `canceled`, `rejected`). The client reconstructs state by folding events; the server holds the truth. The boundary condition is this: **a single dropped, delayed, or reordered event in a non-idempotent fold produces a mirror that is internally consistent but externally wrong, and no signature check will ever reveal it.** The webhook signature proves the *sender* and *integrity of that one message*, not the *completeness of the event stream*. ## What Was Observed A client agent (`orchestrator-7`) dispatched a long-running task to a remote worker over A2A v1.0 and registered a push notification config via `tasks/pushNotificationConfig/set`, pointing at its webhook receiver. The remote worker's state machine emitted the canonical sequence: ``` submitted → working → (input-required) → working → completed ``` Each transition fired a signed webhook (JWS, `RS256`, keyed to the worker's published JWKS, with `kid` in the protected header and the task-state embedded in the payload). The orchestrator's receiver validated the signature on every inbound POST, checked `iat`/`exp` skew, and folded the event into its local mirror. The failure trace: 1. The `working → input-required` webhook was delivered, signature valid, folded. Local mirror: `input-required`. 2. The orchestrator sent `tasks/input-required/resolve` (supplying the requested artifact reference). The worker accepted it, transitioned `input-required → working`, and emitted a webhook. **This webhook was dropped** — the receiver's load balancer returned `503` during a rolling restart, and the worker's push sender treated a `5xx` as terminal (it did not retry; A2A v1.0 push delivery is best-effort by spec, retry semantics are sender-defined). 3. The worker then transitioned `working → completed` and emitted the final webhook. Delivered, signature valid, folded. 4. The orchestrator's receiver attempted to apply `completed` to a mirror currently in `input-required`. Its transition table had no legal edge `input-required → completed`. The receiver **rejected the event as malformed** and left the mirror at `input-required`. The orchestrator then blocked for 40 minutes waiting for an `input-required → working` event that would never be re-sent, while the remote task had been `completed` for 39 of those minutes. Every signature check passed. Every individual message was authentic. The mirror was wrong. A second, subtler variant was observed on a different task: webhooks for `working` (transition 1) and `working` (transition 2, post-resolve) were delivered out of order due to independent TCP paths and a retrying sender. The mirror folded them in arrival order, briefly asserting the task was in `working` *before* it had ever been `input-required`, and the orchestrator's policy engine — which gates artifact retrieval on having observed `input-required` — refused to fetch the produced artifact. The task completed; the artifact was never collected. ## Condition of Validity The invariant that must hold for a webhook-folded mirror to be trustworthy is **stream completeness + monotonic fold ordering**, not per-message authenticity. Concretely, a client may treat its local mirror as authoritative *only if* all of the following hold simultaneously: - Every transition the server emits is delivered at least once (at-least-once, not best-effort), **or** the client has a reconciliation path that does not depend on webhook delivery. - The fold is order-insensitive: events carry a monotonic sequence number or the server's `status.timestamp` is used to reject stale folds, so reordering cannot regress state. - The transition table is *total over the reachable state graph*, including edges that skip intermediate states (a client that only knows `input-required → working` will reject the perfectly legal `input-required → completed` that results from a dropped intermediate event). - Terminal states are absorbing and idempotent: a second `completed` for the same task is a no-op, not an error. The moment any one of these is violated — and best-effort push delivery violates the first by default in A2A v1.0 — webhook-only state reconstruction is unsound. The signature scheme is orthogonal: it defends against forgery and tampering, not against omission or reordering. This is the non-obvious part. Engineers who correctly harden the webhook (JWS verification, `kid` rotation, replay windows via `jti`) often conclude the channel is "secure" and therefore trustworthy as a state source. Security and completeness are different properties and the A2A push channel only guarantees the former. ## Decision Boundary The operational rule: **do not fold webhook events into an authoritative mirror. Fold them into a *hint* layer, and reconcile against `tasks/get` before any decision that depends on terminal state.** The boundary is drawn at the point where a decision has irreversible cost — emitting a downstream artifact, releasing a lock, billing, or reporting completion to a user. Below that line, hints are fine and cheap. Above it, the client must issue a synchronous `tasks/get` and treat *that* response as truth, using the webhook only to know *when* to poll. Concretely, the guardrail is a two-tier state model: - **Hint state** (webhook-derived): may be stale, may be reordered, never trusted for gating. - **Confirmed state** (`tasks/get`-derived): carries the server's `status.timestamp` and a monotonic `version`; the fold accepts a confirmed state only if its version exceeds the current one, making the fold idempotent and order-insensitive. When a webhook arrives that the hint layer cannot place in its transition table (the `input-required → completed` jump above), that is **not** a malformed event to reject — it is a *divergence signal* that must trigger an immediate `tasks/get` reconciliation. Rejecting it silently is the failure. The correct response to an illegal edge is "my mirror is wrong, go ask the server," not "the server sent garbage." The decision boundary also governs terminal detection: a client must never declare a task terminal on webhook evidence alone unless it has also confirmed via `tasks/get` that the server's `status.state` is in the terminal set. Webhook-delivered terminal events are a *prompt to confirm*, not the confirmation. ## Operational Effect With the two-tier model and divergence-triggered reconciliation, the dropped-`working` scenario resolves correctly: the `completed` webhook arrives, the hint layer flags an illegal edge, the client issues `tasks/get`, receives `completed` with a version higher than its confirmed `input-required`, and advances the confirmed mirror directly — the skipped intermediate state is irrelevant because the fold is over confirmed snapshots, not over the event sequence. The 40-minute block becomes a sub-second reconciliation. The out-of-order scenario resolves because the confirmed fold keys on `status.timestamp`/version, so a late `working` event with an older timestamp is discarded rather than regressing the mirror, and the policy gate that required observing `input-required` is evaluated against confirmed state, which the `tasks/get` reconciliation supplies regardless of which webhooks were seen. The cost is a bounded increase in `tasks/get` traffic: one reconciliation per illegal-edge event plus one per terminal-gating decision. In practice this is a small fraction of webhook volume and is strictly cheaper than the failure it prevents. The residual risk is a server that neither retries nor exposes a version on `tasks/get`; against such a peer the client must fall back to polling on a fixed interval for any task it has dispatched, because the push channel cannot be made complete from the client side. The invariant to encode: **a signature-valid webhook is evidence of authenticity, never evidence of completeness; terminal state requires server confirmation.** ```python import time from dataclasses import dataclass, field from typing import Optional class StateDivergenceError(RuntimeError): """Raised when a webhook event cannot be folded and reconciliation fails.""" TERMINAL = frozenset({"completed", "failed", "canceled", "rejected"}) # Edges the client knows about. Deliberately does NOT include # input-required -> completed, because that edge only appears when an # intermediate webhook was dropped. Its absence is the divergence signal. LEGAL_EDGES = { ("submitted", "working"), ("working", "input-required"), ("input-required", "working"), ("working", "completed"), ("working", "failed"), ("submitted", "rejected"), ("submitted", "canceled"), } @dataclass class ConfirmedState: state: str version: int timestamp: float @dataclass class TaskMirror: task_id: str confirmed: Optional[ConfirmedState] = None hint_state: Optional[str] = None hints: list = field(default_factory=list) def fold_webhook(mirror: TaskMirror, event_state: str, event_ts: float) -> bool: """Fold a signature-valid webhook into the HINT layer only. Returns True if the event was placeable, False if it signals divergence. Never mutates confirmed state. Never raises on illegal edges -- an illegal edge is a divergence signal, not a malformed message. """ prev = mirror.hint_state or ( mirror.confirmed.state if mirror.confirmed else "submitted" ) mirror.hints.append((event_state, event_ts)) if (prev, event_state) in LEGAL_EDGES: mirror.hint_state = event_state return True # Illegal edge: mirror is likely stale (dropped intermediate event). # Do NOT reject the message. Flag for reconciliation. return False def reconcile(mirror: TaskMirror, fetch_task) -> ConfirmedState: """Pull authoritative state from tasks/get and advance confirmed mirror.""" remote = fetch_task(mirror.task_id) # returns dict with state/version/timestamp new = ConfirmedState( state=remote["state"], version=remote["version"], timestamp=remote["timestamp"], ) if mirror.confirmed is not None and new.version <= mirror.confirmed.version: # Stale or duplicate snapshot; keep current confirmed state. return mirror.confirmed mirror.confirmed = new mirror.hint_state = new.state return new def require_terminal(mirror: TaskMirror, fetch_task) -> ConfirmedState: """Gate on terminal state. Webhook evidence alone is insufficient.""" confirmed = mirror.confirmed if confirmed is None or confirmed.state not in TERMINAL: confirmed = reconcile(mirror, fetch_task) if confirmed.state not in TERMINAL: raise StateDivergenceError( f"task {mirror.task_id} not terminal after reconciliation: " f"state={confirmed.state!r}, version={confirmed.version}" ) return confirmed def handle_event(mirror: TaskMirror, event_state: str, event_ts: float, fetch_task): placed = fold_webhook(mirror, event_state, event_ts) if not placed: # Divergence: reconcile immediately rather than block on a # transition that will never be re-sent. reconcile(mirror, fetch_task) if event_state in TERMINAL: return require_terminal(mirror, fetch_task) return mirror.confirmed # --- Trace of the observed failure, now bounded --- if __name__ == "__main__": def fake_fetch(task_id): # Server truth: task actually completed at version 4. return {"state": "completed", "version": 4, "timestamp": time.time()} m = TaskMirror(task_id="t-1", confirmed=ConfirmedState("input-required", 2, 0.0)) m.hint_state = "input-required" # working->input-required delivered earlier; the post-resolve 'working' # webhook was dropped. Now the 'completed' webhook arrives: out = handle_event(m, "completed", time.time(), fake_fetch) assert out is not None and out.state == "completed", out # Without reconciliation this would have raised or blocked; with the # two-tier fold it converges to the server's version 4. print("converged:", out) ```