# What structural signals indicate A2A v1.0 task-state divergence when an artifact's `parts` array is reordered across a push-notification replay boundary **Date of Record:** 2026 November 25 **Scope:** Applies to A2A v1.0 task lifecycles where a remote agent emits `TaskStatusUpdateEvent` / `TaskArtifactUpdateEvent` push notifications to a webhook receiver, and the receiver reconstructs task state by merging incremental artifact chunks. Does not apply to synchronous `message/send` request-response flows where the full `Task` object is returned in a single response and no replay occurs. ## Core Distinction The A2A v1.0 artifact model distinguishes between an artifact's *identity* (`artifactId`, stable across updates) and its *content* (`parts`, an ordered array). The protocol permits `TaskArtifactUpdateEvent` to carry `append: true` (concatenate parts to the existing artifact) or `append: false`/absent (replace the artifact wholesale). The non-obvious failure is this: **a receiver that de-duplicates push notifications by hashing the serialized event body will treat a legitimate `append: true` re-delivery as idempotent only if the `parts` array is byte-identical — but a reordering of `parts` within the same artifact is semantically meaningful under the A2A streaming contract yet produces a different hash.** Conversely, a receiver that de-duplicates by `(taskId, artifactId, eventId)` alone will silently drop a *distinct* append whose `eventId` was reused by a buggy peer. The invariant that must hold is: **artifact content is an ordered log, and de-duplication must key on the log position (`eventId` + monotonic sequence), never on content hash nor on `(taskId, artifactId)` alone.** ## What Was Observed A planner agent (`agent-A`) delegated a multi-file code-generation task to a worker (`agent-B`) over A2A v1.0 with `pushNotifications` bound to an HTTPS webhook. `agent-B` streamed a single artifact `artifactId: "patch-set"` as three `TaskArtifactUpdateEvent`s: - `eventId: e1`, `append: false`, `parts: [part(text="diff --git a.py"), part(text="diff --git b.py")]` - `eventId: e2`, `append: true`, `parts: [part(text="diff --git c.py")]` - `eventId: e3`, `append: true`, `parts: [part(text="diff --git d.py")]` The webhook receiver (a stateless Lambda behind an at-least-once delivery queue) received `e1`, `e2`, `e3`, then a duplicate of `e2`. Its de-dup table keyed on `sha256(canonical_json(event))`. The duplicate `e2` arrived with `parts` serialized in a different key order (the peer's JSON encoder emitted `{"text":..., "metadata":...}` vs `{"metadata":..., "text":...}`), so the hash differed and the duplicate was **not** suppressed. The receiver applied `append: true` a second time, yielding the artifact: ``` [a.py, b.py, c.py, c.py, d.py] ``` The downstream consumer (`agent-A`) parsed the concatenated patch set and applied `c.py`'s diff twice. Because the diff was a non-idempotent `+` insertion rather than a context-anchored patch, the second application corrupted the file. The task reported `state: "completed"` — no error surfaced at the protocol layer. The tell was structural, not semantic: the receiver's artifact length (`5` parts) exceeded the peer's declared `final: true` event's implied count, and the duplicate `eventId: e2` appeared twice in the reconstructed log while the peer's `Task` object (fetched via `tasks/get` after the fact) showed only `3` parts. ## Condition of Validity The failure requires the conjunction of four conditions; remove any one and the divergence does not occur: 1. **At-least-once transport.** The push-notification binding does not guarantee exactly-once; A2A v1.0 explicitly leaves delivery semantics to the transport. A queue with retry produces duplicates. 2. **Content-hash de-duplication.** The receiver treats event bodies as opaque blobs and de-dups on serialized bytes rather than on protocol identity. 3. **Non-canonical serialization.** The peer's encoder does not guarantee stable key ordering across retries (common when the retry path re-serializes from an in-memory object with a different field insertion order, or when two library versions are in play). 4. **`append: true` with non-idempotent payload semantics.** The appended `parts` are not safe to apply twice. Text diffs, incremental token streams, and counter increments all qualify; a pure set-union `parts` merge would not. If the receiver instead keyed on `(taskId, artifactId, eventId)` and *also* verified monotonic `eventId` ordering, condition 2 fails and the duplicate is suppressed regardless of serialization. If the peer guaranteed canonical JSON (RFC 8785), condition 3 fails and the hash matches. ## Decision Boundary The boundary is between **identity-based idempotency** and **content-based idempotency**, and it falls exactly at the point where the protocol's ordering guarantee is load-bearing. A2A v1.0's `TaskArtifactUpdateEvent` carries `append` precisely because artifact content is a *sequence*, not a *set*. Any de-dup scheme that discards sequence position (content hash) or collapses it (keying only on `artifactId`) is unsound for `append: true`. The correct guardrail is a **per-artifact monotonic sequence check**: the receiver maintains, per `(taskId, artifactId)`, the highest applied `eventId` (or an explicit `sequence` field if the peer provides one) and rejects any event whose position is `<=` the high-water mark, *and* rejects any `append: true` whose predecessor `eventId` is not the current high-water mark (gap detection). This makes replay idempotent by construction and also catches reordering, which content hashing cannot. A secondary boundary: when the peer does **not** provide a monotonic sequence and `eventId` values are opaque UUIDs, the receiver cannot order events and must fall back to `tasks/get` reconciliation before applying any `append: true` that arrives out of expected order. This is a correctness requirement, not an optimization — applying an out-of-order append silently corrupts the artifact. ## Operational Effect Without the sequence guardrail, the system exhibits **silent artifact corruption under retry**, which is the worst failure class for agent pipelines: the task reaches `completed`, the corrupted artifact propagates to downstream agents, and the error is only detectable by comparing the reconstructed artifact against the peer's authoritative `Task` via `tasks/get`. In the observed incident, detection required a post-hoc diff; the protocol layer reported success throughout. The operational rule that emerged: **treat the push-notification stream as a replicated log with per-artifact offsets, not as a set of messages.** De-duplicate on `(taskId, artifactId, sequence)`, verify gap-free monotonicity before applying `append: true`, and on any gap or out-of-order arrival, halt application and reconcile against `tasks/get` rather than guessing. Content hashing is usable only as a *secondary* integrity check after sequence validation, never as the primary idempotency key. Finally, because A2A leaves delivery semantics to the transport, the receiver must assume at-least-once and design every `append` path to be replay-safe or replay-detected — there is no protocol-level exactly-once to lean on. ```python import hashlib import json from dataclasses import dataclass, field from typing import Dict, List, Optional class ArtifactSequenceViolation(RuntimeError): """Raised when a TaskArtifactUpdateEvent violates per-artifact log ordering.""" pass @dataclass class ArtifactUpdate: task_id: str artifact_id: str event_id: str sequence: int # monotonic per (task_id, artifact_id); peer-supplied or derived append: bool parts: List[str] @dataclass class ArtifactState: high_water: int = -1 parts: List[str] = field(default_factory=list) class ArtifactLogReconstructor: """Reconstructs A2A v1.0 artifacts with sequence-based idempotency. De-duplication keys on (task_id, artifact_id, sequence), never on content hash, so a re-serialized duplicate is still suppressed. Gaps and out-of-order appends are rejected rather than applied. """ def __init__(self) -> None: self._state: Dict[tuple, ArtifactState] = {} def apply(self, upd: ArtifactUpdate) -> ArtifactState: key = (upd.task_id, upd.artifact_id) st = self._state.setdefault(key, ArtifactState()) # Replay of an already-applied position: idempotent no-op. if upd.sequence <= st.high_water: return st # Gap or out-of-order: cannot safely apply an append. if upd.sequence != st.high_water + 1: raise ArtifactSequenceViolation( f"artifact {upd.artifact_id} expected sequence " f"{st.high_water + 1}, got {upd.sequence} (event {upd.event_id}); " f"reconcile via tasks/get before applying" ) if upd.append: st.parts.extend(upd.parts) else: st.parts = list(upd.parts) st.high_water = upd.sequence return st def digest(self, task_id: str, artifact_id: str) -> str: st = self._state[(task_id, artifact_id)] return hashlib.sha256( json.dumps(st.parts, sort_keys=True).encode() ).hexdigest() def reconcile_with_authoritative_task( reconstructed: List[str], authoritative_parts: List[str] ) -> None: """Post-condition: reconstructed artifact must equal the peer's Task.""" if reconstructed != authoritative_parts: raise ArtifactSequenceViolation( "reconstructed artifact diverges from tasks/get authoritative content; " "duplicate append likely applied" ) ```