# Why does an instance accept a terminal-state A2A task snapshot whose artifact manifest has advanced past the task's declared `artifactVersion`, silently discarding the newer artifact? **Date of Record:** 2026 December 4 **Scope:** Applies to A2A v1.0 task lifecycle handling where a receiving agent ingests `Task` snapshots via push-notification webhook or `tasks/get` polling and reconciles them against local artifact state. Does not apply to single-shot synchronous `message/send` calls that return a complete terminal task in one response, nor to streaming `tasks/resubscribe` SSE frames that carry monotonic sequence numbers. ## Core Distinction The A2A v1.0 spec treats a `Task` as a versioned, monotonic state machine: `status.state` moves forward through `submitted → working → input-required → completed/failed/canceled`, and `artifacts[]` carry an `artifactVersion` integer that increments on every mutation of that artifact. The spec's implicit invariant is that **a task snapshot is a consistent cut**: the `status` and the `artifacts` in a single `Task` object describe the same logical instant. That invariant is false across transport. The push-notification webhook delivers a `Task` object that the *sender* serialized at notification-emit time, but the sender may have mutated artifacts *after* emitting the notification and *before* the receiver's webhook handler runs. Worse, the receiver's own `tasks/get` reconciliation poll can interleave: the poll returns a snapshot with `artifactVersion: 4`, the webhook (queued earlier) delivers `artifactVersion: 3` *with* `status.state: completed`. A naive receiver that keys "task is done, freeze artifacts" on `status.state == completed` will latch the v3 artifacts and reject the later-arriving v4 as "post-terminal mutation" — a spurious rejection, because v4 is *newer*, not stale. The non-obvious boundary: **terminality of `status` does not imply terminality of `artifacts`.** The spec permits artifact finalization to lag status finalization by one or more notification hops. The receiver must reconcile artifacts by `artifactVersion` monotonicity, not by task-state terminality. ## What Was Observed A two-agent pipeline: orchestrator `A` dispatches a document-synthesis task to worker `B`. `B` streams partial artifacts, then emits `status.state: completed` with `artifacts: [{id: "draft", artifactVersion: 3, parts: [...]}]`. The webhook fires. Meanwhile `B`'s post-completion hook appends a provenance artifact (`id: "provenance", artifactVersion: 1`) and bumps `draft` to `artifactVersion: 4` with a corrected citation block. This second mutation triggers a second webhook. `A`'s webhook handler was written as: ``` if task.status.state in TERMINAL: self.freeze(task.id) # stops accepting further snapshots self.store(task.artifacts) # writes v3 draft, no provenance ``` Observed trace: 1. Webhook #1 arrives: `completed`, draft v3. `A` freezes task, stores draft v3, drops provenance. 2. Webhook #2 arrives: `completed`, draft v4 + provenance v1. Handler sees `task.id` already frozen, logs `post-terminal-mutation-ignored`, returns 200. 3. `A`'s downstream synthesis consumer reads draft v3 — the version with the *uncorrected* citation block. 4. Failure surfaces 40 minutes later as a citation-mismatch audit failure, with no error in `A`'s logs (the drop was logged at INFO). The failure is silent because the webhook returns 200 (correct per spec — `A` *did* receive it), the freeze is intentional, and the artifact store is internally consistent (it just holds the wrong cut). ## Condition of Validity The bug is reachable only when all three hold: - **Artifact finalization lags status finalization.** If the sender guarantees all artifacts are at their final `artifactVersion` before emitting the terminal `status`, the freeze-on-terminal rule is sound. Many senders do *not* guarantee this — post-completion provenance, signing, or redaction hops are common. - **Notification and poll channels interleave.** If `A` only ever consumes push notifications, ordering is preserved by the sender's emit order and the freeze is safe (the terminal notification is last). The hazard requires a second channel (`tasks/get` poll, or a retried webhook) that can deliver a *newer* snapshot after a *terminal* one. - **The receiver keys artifact acceptance on task state, not artifact version.** A receiver that compares incoming `artifactVersion` against the stored version per-artifact-id is immune regardless of channel interleaving. The invariant to enforce: **for each `(taskId, artifactId)`, the stored `artifactVersion` is the maximum ever observed; snapshots with lower versions are dropped as stale, snapshots with higher versions are applied even if `status.state` is terminal.** Task terminality gates *new task creation*, never *artifact reconciliation*. ## Decision Boundary The decision the receiver must make on every incoming snapshot is not "is the task terminal?" but "is this artifact newer than what I have?" The boundary is crossed when a receiver conflates the two: | Incoming snapshot | Naive rule (freeze on terminal) | Correct rule (per-artifact version) | |---|---|---| | terminal, artifact v3, no local state | accept, freeze | accept v3 | | terminal, artifact v4, local v3 | **reject (bug)** | accept v4 | | working, artifact v2, local v4 | accept (regression) | reject v2 as stale | | terminal, new artifact id, local none | **reject (bug)** | accept new id | Note the third row: the naive rule is also wrong in the *opposite* direction — a late-arriving `working` snapshot with a lower artifact version can overwrite a newer artifact if the receiver trusts arrival order. Version-keying fixes both. The guardrail is a per-artifact monotonic watermark persisted atomically with the artifact write, plus a webhook handler that treats `status.state` as advisory for reconciliation and authoritative only for task-lifecycle bookkeeping (e.g., releasing the task slot). ## Operational Effect Receivers that adopt version-keyed reconciliation observe: (a) no spurious `post-terminal-mutation-ignored` drops, (b) correct handling of provenance/signing artifacts emitted after completion, (c) immunity to webhook/poll interleaving, (d) a new failure surface — out-of-order artifacts from a *buggy* sender that reuses an `artifactVersion` for different content. The last is detectable only by content-hashing artifacts at write time and raising on version collision, which is why the guardrail must include a content-hash check, not just a version comparison. The cost is that "task is done" no longer means "stop listening." The receiver must keep the task's artifact watermark alive for a bounded grace window (typically the sender's max post-completion hook latency, negotiated in the A2A capability exchange) after terminal status, and only then compact. Freezing on terminal is the bug; freezing on *watermark quiescence* is the fix. ```python import hashlib from dataclasses import dataclass, field from typing import Dict, Optional class ArtifactReconciliationError(RuntimeError): """Raised when an incoming A2A task snapshot cannot be safely reconciled against local artifact state without violating the monotonic watermark.""" pass @dataclass class ArtifactRecord: version: int content_hash: str @dataclass class TaskReconciler: # (task_id, artifact_id) -> last accepted ArtifactRecord watermarks: Dict[tuple, ArtifactRecord] = field(default_factory=dict) # task_id -> terminal status seen; does NOT gate artifact acceptance terminal_seen: Dict[str, bool] = field(default_factory=dict) def _hash(self, parts) -> str: h = hashlib.sha256() for p in parts: h.update(repr(p).encode("utf-8")) return h.hexdigest() def reconcile(self, task_id: str, status_state: str, artifacts) -> None: if status_state in ("completed", "failed", "canceled"): self.terminal_seen[task_id] = True for art in artifacts: art_id = art["id"] version = art["artifactVersion"] content_hash = self._hash(art["parts"]) key = (task_id, art_id) prior: Optional[ArtifactRecord] = self.watermarks.get(key) if prior is None: self.watermarks[key] = ArtifactRecord(version, content_hash) continue if version < prior.version: # Stale snapshot from an interleaved poll or retried webhook. # Drop silently; this is expected, not an error. continue if version == prior.version and content_hash != prior.content_hash: # Same version, different content: sender violated monotonicity. # Accepting either copy risks nondeterministic reconciliation. raise ArtifactReconciliationError( f"task {task_id} artifact {art_id} reused version {version} " f"with divergent content ({prior.content_hash[:12]} != " f"{content_hash[:12]}); refusing to reconcile" ) if version == prior.version: # Idempotent replay of identical content; no-op. continue # version > prior.version: accept even if task is terminal. # Terminal status gates task lifecycle, not artifact finalization. self.watermarks[key] = ArtifactRecord(version, content_hash) def handle_webhook_snapshot(reconciler: TaskReconciler, snapshot: dict) -> None: try: reconciler.reconcile( task_id=snapshot["id"], status_state=snapshot["status"]["state"], artifacts=snapshot.get("artifacts", []), ) except ArtifactReconciliationError: # Surface to the sender as a non-2xx so it retries with a corrected # version bump; do NOT swallow, or the divergence persists silently. raise except KeyError as exc: raise ArtifactReconciliationError( f"malformed A2A task snapshot missing required field: {exc}" ) from exc ```