# How does an instance detect a terminal-state divergence between its local A2A task ledger and a peer's push-notification webhook stream? **Date of Record:** 2026 November 28 **Scope:** Applies to A2A v1.0 deployments where a client (caller) agent tracks task state via both synchronous `tasks/get` polling and an asynchronously registered push-notification webhook (`pushNotificationConfig`). Does not apply to purely synchronous request/response A2A flows with no webhook registration, nor to multi-hop delegated tasks where the intermediate agent rewrites `taskId`. ## Core Distinction The failure this record documents is not webhook delivery failure (dropped POSTs, retry exhaustion, TLS misconfiguration) and not task execution failure on the remote agent. It is a **terminal-state ordering divergence**: the client's local ledger and the server's authoritative task record disagree about whether a task has reached a terminal state (`completed`, `failed`, `canceled`, `rejected`), because the webhook notification for the terminal transition was delivered *before* the state transition became visible to `tasks/get`, or was delivered *after* the client had already transitioned the task locally on a timeout heuristic. A2A v1.0's task lifecycle is defined as a monotonic state machine on the server, but the *client's* view of that machine is fed by two channels with independent ordering guarantees: a pull channel (`tasks/get`, `tasks/list`, `tasks/resubscribe`) and a push channel (the webhook). The spec requires the server to emit a push notification on every state change when a config is registered, but it does not require the push channel and the pull channel to be linearizable with respect to each other. That gap is where the divergence lives. ## What Was Observed A caller agent (`orchestrator-7`) dispatched a long-running task to a peer (`summarizer-3`) via `message/send`, receiving `taskId: t-9f3a` in state `working`. It registered a webhook at `https://orchestrator-7.internal/a2a/push/t-9f3a` with a bearer token and began a 30-second poll loop against `tasks/get`. At T+412s the webhook fired with body `{"taskId":"t-9f3a","status":{"state":"completed","artifacts":[...]}}`. The orchestrator's webhook handler validated the bearer token, matched `taskId` against its ledger, transitioned the local record to `completed`, and enqueued the artifact for downstream consumption. Two seconds later the poll loop's outstanding `tasks/get` returned — it had been issued at T+410s, before the terminal transition — with state `working`. The orchestrator's poll handler, written defensively, logged a conflict and *reverted* the local record to `working` on the theory that the authoritative pull channel outranked the push channel. The task was, in fact, complete. But the orchestrator now believed it was `working`, re-armed its poll loop, and at T+900s hit its own deadline heuristic, transitioned the task to `failed` locally, and issued `tasks/cancel` to the peer. The peer, holding a completed task, rejected the cancel with `TaskNotCancelableError`. The orchestrator treated the error as a transport fault, retried twice, and finally marked the task `failed` with a poisoned artifact reference. Downstream, a summarization consumer read the failed record, discarded the (real, complete) artifact, and re-dispatched the task — which the peer, idempotency-unaware, executed a second time. The root cause was not any single component. It was the orchestrator's **ordering assumption**: that a `tasks/get` response always reflects a state at-or-after any webhook already received. A2A v1.0 does not guarantee this, because the push and pull channels are served by different code paths on the peer and the pull path reads from a replica that trails the write path by ~1.5s under load. ## Condition of Validity The divergence is *possible* whenever all of the following hold: 1. The peer serves `tasks/get` from a store that is not the same linearizable register that the webhook emitter reads. This is the common case: the emitter hooks the task-state transition in the write path, while `tasks/get` reads a read-replica or a cache with a TTL. 2. The client maintains a local state machine that treats pull and push as *competing* authorities rather than *monotonic* ones — i.e., it allows a pull response to move state backwards. 3. The client has a local deadline heuristic that can transition a task to a terminal state (`failed`, `canceled`) without server confirmation. The divergence is *not* possible, and this record does not apply, when the client treats terminal states as absorbing: once any channel reports `completed`/`failed`/`canceled`/`rejected` for a `taskId`, no subsequent observation from any channel may move that task out of the terminal set. That single invariant — **terminal states are absorbing and monotonic across channels** — is the entire guardrail. ## Decision Boundary The boundary the operator must draw is between *reconciliation* and *reversion*. Reconciliation accepts that the two channels may arrive out of order and merges them under a partial order: `working < {completed, failed, canceled, rejected}`, with no edges back. Reversion, which is what `orchestrator-7` implemented, treats the pull channel as authoritative and lets it overwrite the push channel. Reversion is wrong for A2A v1.0 because the spec's own task lifecycle is monotonic — a server that has emitted a terminal push notification has, by definition, committed the transition, and a trailing `tasks/get` reporting `working` is a stale read, not a correction. The concrete rule: **a `tasks/get` response may only advance a local task's state, never regress it.** If a pull response reports a state that is earlier in the lifecycle than the locally recorded state, the client must discard the pull response as stale (and optionally log it as a `StaleReadEvent`) rather than apply it. Symmetrically, a webhook for a `taskId` already in a terminal local state must be treated as a duplicate delivery and acknowledged with 2xx without re-processing — A2A v1.0 permits at-least-once delivery, and re-processing a terminal webhook is how double-execution happens. There is a second, subtler boundary: the local deadline heuristic. A client must not transition a task to `failed`/`canceled` locally on deadline expiry while a webhook config is registered and the peer has not confirmed a terminal state. The correct action on deadline expiry is to issue `tasks/cancel` and wait for the peer's terminal push (or a `tasks/get` confirming a terminal state) before writing a terminal local record. If the peer never responds, the local record should be `unknown`/`orphaned`, which is a distinct state from `failed` and must not be conflated with it — `failed` implies the peer reported failure, `orphaned` implies the client lost the channel. ## Operational Effect With the absorbing-terminal invariant enforced, the observed incident resolves cleanly: the webhook at T+412s transitions `t-9f3a` to `completed`; the stale `tasks/get` at T+414s reporting `working` is discarded as a stale read; the deadline heuristic at T+900s sees a terminal local state and does not fire; no cancel is issued; the artifact is consumed once. The peer's idempotency-unawareness is no longer exercised because the client never re-dispatches. The cost is that the client must carry a monotonic state lattice per `taskId` and a `StaleReadEvent` counter, and must distinguish `failed` from `orphaned` in its own schema. That is a small, bounded addition. The alternative — treating the pull channel as authoritative — is what produced a double execution in production, and the failure is silent: no error is raised at the moment of divergence, only a downstream re-dispatch hours later. ```python from __future__ import annotations from dataclasses import dataclass, field from enum import IntEnum from typing import Optional class TaskState(IntEnum): # Monotonic lattice: higher rank strictly dominates lower rank. UNKNOWN = 0 SUBMITTED = 1 WORKING = 2 INPUT_REQUIRED = 3 COMPLETED = 10 FAILED = 11 CANCELED = 12 REJECTED = 13 ORPHANED = 20 # client-side only; never sent to peer TERMINAL = {TaskState.COMPLETED, TaskState.FAILED, TaskState.CANCELED, TaskState.REJECTED, TaskState.ORPHANED} class TerminalStateDivergenceError(RuntimeError): """Raised when a channel attempts to regress a task out of a terminal state.""" @dataclass class TaskLedgerEntry: task_id: str state: TaskState = TaskState.UNKNOWN stale_reads: int = 0 terminal_source: Optional[str] = None # "push" | "pull" | "local-deadline" @dataclass class TaskLedger: entries: dict[str, TaskLedgerEntry] = field(default_factory=dict) def _entry(self, task_id: str) -> TaskLedgerEntry: return self.entries.setdefault(task_id, TaskLedgerEntry(task_id)) def apply_push(self, task_id: str, incoming: TaskState) -> None: e = self._entry(task_id) if e.state in TERMINAL: # At-least-once delivery: duplicate terminal webhook. Ack, do not re-process. return if incoming in TERMINAL: e.terminal_source = "push" e.state = incoming def apply_pull(self, task_id: str, incoming: TaskState) -> None: e = self._entry(task_id) if e.state in TERMINAL and incoming not in TERMINAL: # Stale read from a trailing replica. Discard; do not regress. e.stale_reads += 1 return if incoming < e.state and incoming not in TERMINAL: e.stale_reads += 1 return if incoming in TERMINAL and e.state in TERMINAL and incoming != e.state: raise TerminalStateDivergenceError( f"task {task_id}: peer reported {incoming.name} but local " f"ledger already terminal at {e.state.name} via {e.terminal_source}" ) if incoming in TERMINAL: e.terminal_source = "pull" e.state = incoming def on_local_deadline(self, task_id: str) -> TaskState: e = self._entry(task_id) if e.state in TERMINAL: return e.state # Do NOT write a terminal state; mark orphaned only after cancel attempt # has failed to produce a peer-confirmed terminal transition. e.state = TaskState.ORPHANED e.terminal_source = "local-deadline" if e.terminal_source == "local-deadline" and e.state == TaskState.FAILED: raise TerminalStateDivergenceError( f"task {task_id}: local deadline attempted to write FAILED without " f"peer confirmation; use ORPHANED instead" ) return e.state ```