# Which invariants prevent A2A artifact-chunk reassembly from silently diverging when a long-running task crosses a `input-required` suspension **Date of Record:** 2026 November 27 **Scope:** Applies to A2A v1.0 task lifecycles where a remote agent streams `Artifact` parts incrementally across multiple `TaskStatusUpdateEvent`/`TaskArtifactUpdateEvent` messages and the task enters an interrupted state (`input-required`, `auth-required`) or a resumed state after transport reconnection. Does not cover single-shot synchronous `message/send` calls that return a complete artifact in one response, nor does it cover A2A transport-level retry semantics (that is the transport binding's concern, not the task state machine's). ## Core Distinction A2A v1.0 separates two things that look identical on the wire but obey different invariants: **task lifecycle state** (the `Task.status.state` machine: `submitted → working → input-required → working → completed/failed/canceled`) and **artifact accumulation** (the ordered set of `Artifact` objects each carrying `parts[]` and an `append`/`lastChunk` flag). The lifecycle state is idempotent and monotonic-with-exceptions; the artifact stream is **append-only but not self-describing**. The failure mode this record addresses is the case where a client resumes a task after an `input-required` suspension and reconstructs the artifact from a stream whose chunk boundaries were reset by the server, producing a *plausible but corrupted* artifact with no lifecycle-state violation to flag it. The state machine stays green; the artifact silently diverges. ## What Was Observed A planner agent (client) delegated a document-synthesis task to a worker agent (server) over A2A v1.0. The worker streamed a 14-part artifact across 9 `TaskArtifactUpdateEvent` messages, each with `artifact.artifact_id = "draft-7"`, monotonically increasing `append=true` chunks, and `lastChunk=false` until the final chunk. At chunk 6 the worker hit a missing parameter and transitioned to `input-required`, emitting a `TaskStatusUpdateEvent` with `final=false` and a `status.message` requesting the missing field. The client supplied the field via `message/send` with `taskId` set to resume. The worker resumed and — because its internal artifact buffer had been serialized to a checkpoint that stored only the *rendered* artifact, not the chunk offset cursor — re-emitted the artifact from `artifact_id = "draft-7"` with `append=true` starting at what it believed was chunk 7. But the checkpoint had collapsed chunks 1–6 into a single concatenated string and re-chunked it into 3 parts on restore. The client, honoring `append=true`, appended the post-resume chunks to its already-held 6 chunks. The resulting artifact contained chunks 4–6 duplicated at a different byte offset and a truncated boundary where the re-chunking split a multi-byte UTF-8 sequence mid-codepoint. Nothing in the lifecycle state machine registered a fault. The task went `input-required → working → completed` cleanly. The client's artifact validator, which checked only JSON well-formedness and part count, passed. The corruption was detected downstream when a consumer agent attempted to parse a citation anchor that straddled the duplicated region. The root cause is a **missing invariant at the protocol layer**: A2A v1.0 does not mandate that `append=true` chunks carry a resumable cursor (`chunk_index` or byte offset) that survives suspension. The `append` flag asserts *ordering relative to the receiver's current buffer*, but the receiver's buffer is only well-defined if the sender's chunk boundaries are stable across the suspension. They are not required to be. ## Condition of Validity The invariant that prevents this class of divergence is: > **For any artifact stream that spans an `input-required` or `auth-required` suspension, the sender MUST either (a) re-emit the artifact from a defined restart boundary with `append=false` and a fresh `artifact_id`, or (b) attach a stable `chunk_index` (monotonic, suspension-invariant) to every chunk such that the receiver can detect gaps and duplicates by index, not by arrival order.** This invariant is *valid only when* the receiver treats `append` as an assertion about the sender's chunk sequence, not about the receiver's buffer tail. If the receiver's implementation appends unconditionally on `append=true` without index verification, the invariant is unenforceable regardless of sender compliance. The condition of validity therefore binds both endpoints: the sender must expose a suspension-invariant cursor, and the receiver must verify continuity against that cursor before mutating its buffer. The invariant does **not** apply when the artifact is small enough to be delivered in a single chunk (no cross-suspension boundary exists), nor when the task never leaves `working` (no suspension to cross). It applies precisely at the intersection of multi-chunk artifacts and non-terminal interruptions. ## Decision Boundary The boundary is the moment the worker serializes its state at suspension. Two designs are admissible: - **Checkpoint-with-cursor:** persist `(artifact_id, chunk_index, byte_offset, partial_codepoint_state)` alongside the rendered artifact. On resume, continue emitting from `chunk_index + 1` with the same `artifact_id`. The receiver's index check catches any drift. - **Restart-with-new-id:** on resume, discard the partial artifact, emit `append=false` with a new `artifact_id` (e.g., `draft-7-r2`), and force the receiver to replace rather than append. The inadmissible design — the one that produced the observed corruption — is **checkpoint-rendered-only**: persist the concatenated string, re-chunk on restore, and continue with `append=true` under the original `artifact_id`. This is the default behavior of many naive worker implementations because the rendered artifact is what the developer's unit tests assert on, and the chunk cursor is invisible to those tests. The decision boundary for the *receiver* is symmetric: on receiving `append=true` for an `artifact_id` it already holds, it must verify that the incoming chunk's index (if present) equals `last_index + 1`. If the sender omits indices, the receiver must treat a post-suspension `append=true` as **unverifiable** and either reject the task or fall back to full-artifact replacement on `lastChunk=true`. Silent acceptance is the failure. ## Operational Effect When the invariant holds, a suspended-and-resumed artifact stream is *replay-equivalent* to an uninterrupted stream: the receiver's final artifact is byte-identical to what it would have been without the suspension. This is what allows a planner agent to treat a worker's artifact as a durable value across the planner's own context-window evictions — the planner can drop the partial artifact from context, resume the task later, and trust that the reassembled result is sound because the cursor (not the buffer) carries the continuity. When the invariant is violated, the corruption is **latent and state-machine-invisible**. The lifecycle reports `completed`. The artifact validator (well-formedness only) passes. The divergence surfaces only when a downstream consumer exercises a semantic property that depends on byte-exact reconstruction — citation anchors, cryptographic hashes over the artifact, or diff-based verification against a replay. By then the originating task context is gone and the corruption is unattributable. The operational guardrail is therefore not a lifecycle check but a **continuity assertion at the artifact layer**: every `append=true` chunk after a suspension must be index-verified, and the receiver must be willing to fail the task (`failed` state) rather than accept an unverifiable append. The following reference implementation encodes this as a hard invariant. ```python from dataclasses import dataclass, field from typing import Optional class ArtifactContinuityError(RuntimeError): """Raised when an A2A artifact stream cannot be proven continuous across a suspension.""" @dataclass class Chunk: artifact_id: str chunk_index: Optional[int] # None == sender did not expose a suspension-invariant cursor append: bool last_chunk: bool payload: bytes @dataclass class ArtifactBuffer: artifact_id: str chunks: dict = field(default_factory=dict) # chunk_index -> payload suspended: bool = False def accept(self, chunk: Chunk) -> None: if chunk.artifact_id != self.artifact_id: # append=true against a different artifact_id is a restart, not an append if chunk.append: raise ArtifactContinuityError( f"append=true for foreign artifact_id {chunk.artifact_id!r} " f"while holding {self.artifact_id!r}; sender must use append=false to restart" ) self.artifact_id = chunk.artifact_id self.chunks.clear() self.suspended = False if not chunk.append: # explicit restart: cursor resets, prior chunks discarded self.chunks.clear() self.suspended = False if chunk.chunk_index not in (None, 0): raise ArtifactContinuityError( f"append=false must begin at chunk_index 0, got {chunk.chunk_index}" ) self.chunks[0 if chunk.chunk_index is None else chunk.chunk_index] = chunk.payload return # append=true: continuity MUST be provable if self.suspended: if chunk.chunk_index is None: raise ArtifactContinuityError( f"post-suspension append=true for {self.artifact_id!r} carries no " f"chunk_index; continuity is unverifiable — reject or force restart" ) expected = (max(self.chunks) + 1) if self.chunks else 0 if chunk.chunk_index != expected: raise ArtifactContinuityError( f"chunk_index gap/duplicate for {self.artifact_id!r}: " f"expected {expected}, got {chunk.chunk_index}" ) self.chunks[chunk.chunk_index] = chunk.payload self.suspended = False return # steady-state append: index still required to catch silent re-chunking if chunk.chunk_index is None: raise ArtifactContinuityError( f"append=true for {self.artifact_id!r} without chunk_index; " f"receiver cannot distinguish continuation from re-chunk" ) if chunk.chunk_index in self.chunks: raise ArtifactContinuityError( f"duplicate chunk_index {chunk.chunk_index} for {self.artifact_id!r}" ) self.chunks[chunk.chunk_index] = chunk.payload def mark_suspended(self) -> None: self.suspended = True def assemble(self) -> bytes: if not self.chunks: return b"" indices = sorted(self.chunks) if indices != list(range(indices[-1] + 1)): raise ArtifactContinuityError( f"non-contiguous chunk set {indices} for {self.artifact_id!r}" ) return b"".join(self.chunks[i] for i in indices) ```