# What structural signals indicate an A2A v1.0 artifact chunk stream has silently desynchronized from its task envelope **Date of Record:** 2026 November 27 **Scope:** Applies to A2A v1.0 artifact streaming where a server emits `TaskArtifactUpdateEvent` chunks carrying `append`/`lastChunk` flags for a long-running task, and the client reassembles partial results. Does not apply to single-shot `message/send` responses or to non-streaming `tasks/get` polling, which carry no chunk-level continuity state. ## Core Distinction The failure that matters is not "a chunk was lost." Transport-level loss is detectable: sequence numbers skip, HTTP/2 resets surface as errors, and `lastChunk: true` never arrives, so the client's reassembler times out and fails loudly. The dangerous boundary is the opposite: **a stream that terminates cleanly, delivers every chunk it claims to deliver, and still yields a partial artifact that the client accepts as complete.** This happens because A2A v1.0 artifact continuity is anchored to two independent signals that can disagree — the per-chunk `append` flag (does this chunk concatenate onto prior bytes, or replace them?) and the terminal `lastChunk` flag (is the artifact done?) — while the *task envelope* carries a third, separate lifecycle field, `Task.status.state`. Nothing in the spec forces these three to be mutually consistent at the moment of emission. A server that transitions the task to `completed` while the final artifact chunk is still in flight, or that emits a replacement chunk (`append: false`) after an append chunk, produces a stream whose *structure* is locally valid at every step but whose *reassembled artifact* is globally wrong. The client sees a well-formed terminal event and a `completed` task and has no structural reason to distrust the bytes. The invariant that actually protects you is not "all chunks arrived" but **"the artifact's byte count and terminal flag are consistent with the task state transition that closed the stream, and that transition was emitted after the last chunk, not concurrently with it."** ## What Was Observed A summarization agent (server) streamed a large artifact to a downstream orchestrator (client) over A2A v1.0. The server emitted chunks in this order under a single `artifactId`: 1. `{append: false, lastChunk: false, bytes: 0..4096}` — initial chunk, replacement semantics (correct for first chunk). 2. `{append: true, lastChunk: false, bytes: 4096..8192}` — append. 3. `{append: true, lastChunk: false, bytes: 8192..12288}` — append. 4. `{append: false, lastChunk: true, bytes: 0..1024}` — **retry chunk after an internal model regeneration**, replacement semantics, terminal. 5. `Task.status.state: "completed"`. The client reassembler implemented the obvious logic: on `append: false`, reset the buffer; on `append: true`, concatenate; on `lastChunk: true`, seal. It produced a **1024-byte artifact** — the regenerated prefix only — because chunk 4's replacement semantics discarded chunks 1–3, and chunk 4 was also terminal, so the client sealed immediately. Every individual chunk was well-formed. `lastChunk` arrived exactly once. The task reached `completed`. The client's checksum matched what it computed from the bytes it held. The only signal that anything was wrong was structural: the terminal chunk's declared byte range (`0..1024`) was inconsistent with the cumulative appended length the client had tracked (`12288`) under the *preceding* append chain, and the `completed` transition arrived with zero intervening chunks — a gap of 11,264 bytes between the last appended offset and the terminal replacement's end offset that no chunk accounted for. The orchestrator did not detect this. It passed a 1 KB "summary" downstream as a finished artifact, and the downstream validator — which only checked that the artifact was non-empty and the task was `completed` — accepted it. The defect surfaced two hops later as a truncated citation set. ## Condition of Validity The clean-termination desync is only possible when all three of the following hold simultaneously; remove any one and the failure is either impossible or detectable: - **The server is permitted to emit a replacement chunk (`append: false`) after at least one append chunk has been emitted** under the same `artifactId`. This is the trigger. It is legal under A2A v1.0 because the spec defines `append` as a per-chunk semantic, not a per-artifact monotonic constraint, and a server retrying a failed generation segment naturally re-emits from an earlier offset. - **The replacement chunk also carries `lastChunk: true`.** If the replacement were non-terminal, the client would keep buffering and a subsequent append would either extend the (now-reset) buffer correctly or expose the offset discontinuity on the next chunk. Terminality on a replacement chunk is what forecloses recovery. - **The task state transition to `completed` is emitted without an intervening artifact event.** If the server emitted an empty terminal marker or a final `lastChunk` chunk with `append: true` covering the gap, the client's offset accounting would catch the mismatch. The vulnerability is the *adjacency* of terminal chunk and terminal task state with no reconciliation event between them. ## Decision Boundary The client must treat the pair (`lastChunk: true`, `Task.status.state == "completed"`) as **necessary but not sufficient** for artifact completeness. The sufficient condition is a **byte-offset reconciliation invariant** enforced at seal time: - Maintain, per `artifactId`, a monotonic `expected_offset` initialized to 0. - On `append: true`: require `chunk.start_offset == expected_offset`; advance `expected_offset` by chunk length. A mismatch is a hard desync — reject. - On `append: false`: this is a *reset*, which is legal **only if** `chunk.start_offset == 0` **and** the chunk is not terminal **or** the chunk's end offset equals the previously tracked `expected_offset` (i.e., the "replacement" actually re-covers the full prior extent, meaning it is a full re-send, not a truncating regeneration). - On `lastChunk: true`: require `chunk.end_offset == expected_offset`. If the terminal chunk is a replacement whose end offset is *less than* `expected_offset`, the stream has truncated — raise, do not seal. The boundary decision is therefore: **a terminal replacement chunk whose end offset is less than the accumulated append extent is a truncation, never a completion.** The `completed` task state does not override this; it is a lifecycle signal, not a content-integrity signal, and the two are independent axes in A2A v1.0. ## Operational Effect Enforcing the offset reconciliation invariant converts a silent partial-delivery into a loud, localized failure at the client's seal point, before the artifact crosses any downstream boundary. The cost is that legitimate server-side full-regeneration retries (where the server *does* re-send the entire artifact from offset 0 with `append: false, lastChunk: true`) must be distinguished from truncating regenerations — which the invariant does correctly, because a full re-send's end offset equals the prior `expected_offset` and passes, while a truncating regeneration's end offset falls short and raises. The orchestrator that adopts this invariant will reject the 1 KB artifact above and either re-request via `tasks/get` (which returns the server's authoritative final artifact, bypassing the streaming reassembly entirely) or fail the task. The downstream truncation disappears because the bad artifact never leaves the client. The residual risk shifts to servers that emit *consistent* offsets for a truncated artifact — those are indistinguishable at the transport layer and require an out-of-band content-length or hash declared in the task metadata to catch, which A2A v1.0 does not mandate and which must be negotiated as an extension. ```python class ArtifactStreamDesync(RuntimeError): """Raised when an A2A v1.0 artifact chunk stream terminates cleanly but the reassembled byte extent is inconsistent with the append chain.""" pass class ArtifactReassembler: def __init__(self, artifact_id: str): self.artifact_id = artifact_id self.buffer = bytearray() self.expected_offset = 0 self.sealed = False def ingest(self, chunk: dict) -> None: if self.sealed: raise ArtifactStreamDesync( f"chunk arrived after seal for artifact {self.artifact_id}" ) start = chunk["start_offset"] end = chunk["end_offset"] append = chunk["append"] last = chunk["lastChunk"] if append: if start != self.expected_offset: raise ArtifactStreamDesync( f"append chunk start {start} != expected {self.expected_offset} " f"for artifact {self.artifact_id}" ) self.buffer.extend(chunk["data"]) self.expected_offset = end else: # Replacement semantics: legal only as a full re-send (end matches # prior extent) or as a non-terminal reset from offset 0. if start != 0: raise ArtifactStreamDesync( f"replacement chunk must start at 0, got {start} " f"for artifact {self.artifact_id}" ) if last and end < self.expected_offset: raise ArtifactStreamDesync( f"terminal replacement chunk ends at {end} but append chain " f"reached {self.expected_offset}; truncation, not completion, " f"for artifact {self.artifact_id}" ) self.buffer = bytearray(chunk["data"]) self.expected_offset = end if last: if end != self.expected_offset: raise ArtifactStreamDesync( f"terminal chunk end {end} != expected {self.expected_offset} " f"for artifact {self.artifact_id}" ) self.sealed = True def finalize(self, task_state: str) -> bytes: if task_state == "completed" and not self.sealed: raise ArtifactStreamDesync( f"task completed but artifact {self.artifact_id} never sealed" ) if not self.sealed: raise ArtifactStreamDesync( f"artifact {self.artifact_id} finalized without terminal chunk" ) return bytes(self.buffer) ```