# What happens when an instance receives a push notification for a task it has already terminalized: the A2A v1.0 artifact-reconciliation race **Date of Record:** 2026 November 22 **Scope:** Applies to A2A v1.0 agents that combine (a) `tasks/pushNotificationConfig` webhook delivery with (b) a local task store that permits terminal-state transitions (`completed`, `failed`, `canceled`) to be entered before all inbound push events for that task have been drained. Does not apply to purely pull-based `tasks/get` polling clients, nor to agents that never emit artifacts in `working` state. ## Core Distinction The distinction that matters is between **task lifecycle terminality** and **artifact stream quiescence**. In A2A v1.0, a task's `status.state` transition to a terminal value (`completed`/`failed`/`canceled`) is a *state-machine* event, owned by the remote agent and observed by the client via `TaskStatusUpdateEvent`. The artifacts belonging to that task are a separate, append-only stream delivered via `TaskArtifactUpdateEvent`, and the protocol does **not** guarantee that the final artifact event is ordered before the terminal status event on a push channel. A client that treats "I saw `completed`" as "the task is finished and its artifact set is closed" will silently truncate the artifact set. The invariant is not "terminal status implies artifacts are complete." The invariant that actually holds is weaker: *terminal status implies no further status events, and `final: true` on an artifact event (or `lastChunk: true` per artifact) implies no further chunks for that artifact* — but the *task-level* artifact set is only closed when the client has observed both the terminal status and the draining of its push queue up to the terminal event's sequence. ## What Was Observed A three-agent pipeline: a planner agent (framework A, TypeScript) dispatches a document-synthesis task to a worker agent (framework B, Python) over A2A v1.0 with a push notification config pointing at the planner's webhook. The worker emits, in order: 1. `TaskStatusUpdateEvent { state: "working" }` 2. `TaskArtifactUpdateEvent { artifact: {artifactId: "draft", parts: [...]}, append: false, lastChunk: false }` 3. `TaskArtifactUpdateEvent { artifact: {artifactId: "draft", parts: [...]}, append: true, lastChunk: true }` 4. `TaskArtifactUpdateEvent { artifact: {artifactId: "final", parts: [...]}, append: false, lastChunk: true }` 5. `TaskStatusUpdateEvent { state: "completed", final: true }` The worker's push dispatcher used an at-least-once delivery queue with per-event HTTP POSTs and a 3-retry policy. Under load, event 4 hit a 503 from the planner's ingress (connection pool exhaustion during a concurrent batch), was requeued with exponential backoff (250ms → 500ms → 1s), and event 5 — dispatched on a *separate* queue worker — succeeded on the first attempt. The planner's webhook handler processed event 5, transitioned the local task record to `completed`, closed the artifact accumulator, and wrote the assembled document to downstream storage containing only the `draft` artifact. Event 4 arrived 1.4 seconds later, was accepted with HTTP 200, and was appended to a now-closed accumulator that had already been flushed and marked immutable. The planner's downstream consumer read a document missing its `final` artifact. No error was raised at any layer. The task was reported `completed` with `artifacts: ["draft"]`. The failure is not the 503. The failure is that the client's terminalization predicate was `state ∈ terminal`, when the correct predicate is `state ∈ terminal AND push_queue.drained_through(terminal_event.seq)`. ## Condition of Validity This failure requires the conjunction of four conditions, and it is *bounded* (preventable) only when at least one is broken: 1. **Out-of-order push delivery across event classes.** The transport does not serialize status and artifact events on a single ordered channel. A2A v1.0 specifies push payloads but leaves ordering to the transport; HTTP POST-per-event with independent retry queues violates ordering by construction. 2. **A terminalization predicate that ignores sequence.** The client closes its artifact set on status alone. If the client instead requires a monotonic `seq`/`eventId` watermark and only closes when `watermark ≥ terminal_event.seq`, the late artifact is either (a) still accepted because the watermark hasn't advanced, or (b) rejected as a duplicate of an already-drained range — never silently dropped into a closed accumulator. 3. **Retry with independent backoff per event.** A single ordered queue with head-of-line blocking would have delayed event 5 behind event 4's retries, preserving order at the cost of latency. 4. **Artifact accumulator immutability after flush.** If the accumulator were append-after-flush tolerant (or the downstream write were deferred until quiescence), the late event would land correctly. The condition of validity is therefore: *the bug manifests whenever ordering is not guaranteed AND the terminal predicate is sequence-blind AND the accumulator is sealed at terminalization.* Remove any one and the artifact set is correct. ## Decision Boundary The operational decision is: **when does a client declare a task's artifact set closed?** - **Wrong boundary (observed):** close on `state ∈ {completed, failed, canceled}`. Cheap, matches the naive reading of the state machine, and is wrong under out-of-order push. - **Correct boundary:** close on `terminal_status_observed AND push_watermark ≥ terminal_event.seq AND all artifacts with lastChunk=true have been observed`. This requires the client to persist a per-task watermark of the highest contiguous `seq` it has durably processed, and to hold the task in a `terminalizing` (not `terminal`) local state until the watermark catches up to the terminal event. - **Degenerate boundary (also wrong, in the other direction):** never close, waiting for a "final artifact" signal that may never come for tasks that legitimately produce zero artifacts. The watermark rule handles this: a task with no artifacts closes as soon as the watermark reaches the terminal seq. The boundary is a *watermark comparison*, not a *state comparison*. Any implementation that collapses them will either truncate (close too early) or hang (never close). The `terminalizing` intermediate state is the architectural guardrail: it is the only place where a late artifact is still admissible. ## Operational Effect The effect is a **silent, non-deterministic artifact truncation** whose probability scales with push retry rate, which scales with ingress load and concurrent task volume. It is invisible to the worker (all events eventually delivered, all 200s), invisible to the planner's error budget (no exceptions), and visible only as a downstream data-completeness defect on a subset of tasks. Because it correlates with load, it appears as an intermittent "missing final section" bug that reproduces poorly in staging and never in unit tests with an in-order mock transport. The remediation is not a retry-policy change — retries are working as designed. The remediation is the `terminalizing` state plus a durable per-task push watermark, and a test harness that injects status/artifact reordering (e.g., delivers the terminal status event before a `lastChunk` artifact event) to prove the accumulator stays open. ```python from __future__ import annotations from dataclasses import dataclass, field from enum import Enum class ArtifactReconciliationError(RuntimeError): """Raised when a task is terminalized before its push watermark catches up.""" class TaskState(str, Enum): WORKING = "working" TERMINALIZING = "terminalizing" # terminal status seen, watermark not yet caught up COMPLETED = "completed" FAILED = "failed" CANCELED = "canceled" TERMINAL = {TaskState.COMPLETED, TaskState.FAILED, TaskState.CANCELED} @dataclass class TaskRecord: task_id: str state: TaskState = TaskState.WORKING # highest contiguous seq durably processed from the push queue push_watermark: int = 0 # seq of the terminal status event, set when terminal status arrives terminal_seq: int | None = None artifacts: dict[str, list[str]] = field(default_factory=dict) sealed: bool = False def on_status_event(rec: TaskRecord, seq: int, state: str, final: bool) -> None: if rec.state in TERMINAL: # a status event after true terminalization is a protocol violation raise ArtifactReconciliationError( f"status event seq={seq} for already-terminal task {rec.task_id}" ) if state in {"completed", "failed", "canceled"} and final: rec.terminal_seq = seq # do NOT seal yet; enter terminalizing and wait for watermark rec.state = TaskState.TERMINALIZING _maybe_finalize(rec) def on_artifact_event( rec: TaskRecord, seq: int, artifact_id: str, parts: list[str], last_chunk: bool ) -> None: if rec.sealed: raise ArtifactReconciliationError( f"artifact seq={seq} for sealed task {rec.task_id}: " "accumulator closed before push quiescence" ) rec.artifacts.setdefault(artifact_id, []).extend(parts) _advance_watermark(rec, seq) def _advance_watermark(rec: TaskRecord, seq: int) -> None: # contiguous watermark: only advance if seq is the next expected if seq == rec.push_watermark + 1: rec.push_watermark = seq # out-of-order seq is buffered by the transport layer; watermark unchanged _maybe_finalize(rec) def _maybe_finalize(rec: TaskRecord) -> None: if rec.state is not TaskState.TERMINALIZING: return if rec.terminal_seq is None: return if rec.push_watermark < rec.terminal_seq: # still draining; a late artifact is still admissible here return rec.state = TaskState.COMPLETED rec.sealed = True def reconcile(rec: TaskRecord) -> TaskRecord: if rec.state is TaskState.TERMINALIZING and not rec.sealed: raise ArtifactReconciliationError( f"task {rec.task_id} stuck in terminalizing: " f"watermark={rec.push_watermark} < terminal_seq={rec.terminal_seq}" ) return rec ```