# In what scenarios must an instance treat A2A artifact chunk reassembly as a state-machine transition rather than a buffered stream, and why does the distinction break across vendor boundaries **Date of Record:** 2026 November 30 **Scope:** Applies to any A2A (Agent-to-Agent) client that consumes `TaskArtifactUpdateEvent` streams from a remote agent and must reconcile partial artifact chunks against a multi-turn task lifecycle (`submitted → working → input-required → completed`). Does not apply to single-shot synchronous request/response calls or to transports that guarantee atomic artifact delivery. ## Core Distinction The A2A protocol defines tasks as stateful objects with an explicit lifecycle, and artifacts as the durable outputs of those tasks. A remote agent may emit artifacts incrementally as `TaskArtifactUpdateEvent` messages carrying `append` and `lastChunk` flags, each tagged with an `artifactId` and a `taskId`. There is a strong temptation to treat these chunks as a byte stream: open a buffer keyed by `artifactId`, concatenate until `lastChunk: true`, then deserialize the assembled payload. That model is wrong in a specific, load-bearing way. An artifact chunk is not a fragment of a stream; it is a **transition event on the task state machine**. The distinction matters because the A2A task lifecycle permits the remote agent to interleave artifact emission with state transitions that *invalidate prior chunks* — most importantly `input-required` (the task pauses for client input) and `canceled`/`failed` (the task terminates). When a chunk arrives after an `input-required` transition, it belongs to a *new generation* of the artifact, not a continuation of the previous one. A vendor that treats `append` as a pure byte-append will silently splice generation N's bytes onto generation N-1's and produce a structurally valid but semantically corrupt artifact — a JSON object with a duplicated key, a partial file with a stale header, a message list with a replayed turn. The invariant that must hold: **artifact reassembly is scoped to a task-state epoch, and any lifecycle transition that is not a pure progress update closes the current epoch and invalidates in-flight buffers for that artifact.** ## What Was Observed A two-vendor pipeline: Vendor A (orchestrator) dispatches a long-running research task to Vendor B (worker) over A2A. Vendor B emits a `report` artifact in chunks of ~4 KB, with `append: true` on all but the first and `lastChunk: true` on the terminal chunk. Midway through, Vendor B's internal planner determines it needs a clarification and emits a `TaskStatusUpdateEvent` with `state: "input-required"` and a `message` describing the missing parameter. Vendor A's client library surfaces this to the user, collects an answer, and calls `tasks/send` again with the same `taskId` to resume. Vendor B resumes and re-emits the `report` artifact from the beginning — but with the *same* `artifactId`, because from Vendor B's perspective the artifact is the same logical output, now regenerated. Vendor A's reassembly buffer, keyed only by `artifactId`, still holds the first-generation bytes. The `append: true` on the resumed first chunk causes Vendor A to concatenate generation-2 bytes onto generation-1 bytes. Observed symptom in production: a Markdown report with two `# Executive Summary` sections, the first describing the pre-clarification (wrong) analysis and the second the corrected one, both presented as authoritative. Downstream, a summarizer agent consumed the artifact and produced a summary that merged contradictory claims. No error was raised at any layer — every chunk parsed, every `lastChunk` was honored, the final artifact deserialized cleanly. The failure was invisible to schema validation and only detectable by semantic diffing. A second variant: Vendor B, on a different task, emitted `state: "failed"` after three chunks, then (due to an internal retry) resumed and re-emitted the artifact with the same `artifactId`. Vendor A, having not closed its buffer on the `failed` transition, appended the retry's bytes to the failed attempt's partial output. The resulting artifact was a truncated-then-extended document that passed every structural check. ## Condition of Validity The buffered-stream model is valid **only** under the conjunction of three conditions, none of which A2A guarantees across vendor boundaries: 1. **Artifact identity is epoch-stable.** The remote agent must never reuse an `artifactId` for a regenerated payload within the same `taskId`. The A2A spec permits artifact reuse across generations; it does not require a fresh `artifactId` on regeneration. Vendor B's behavior above is spec-compliant. 2. **No lifecycle transitions interleave with chunk emission.** The remote agent must not emit a state transition (`input-required`, `failed`, `canceled`, `auth-required`) between chunks of the same artifact without the client observing it as a boundary. The spec allows interleaving; ordering guarantees are transport-dependent. 3. **`append: false` is honored as a reset.** When the remote agent sets `append: false`, the client must discard the existing buffer for that `artifactId`, not merely start a new one. Many client libraries conflate "first chunk" with "append: false" and miss the reset-on-regeneration case. When any condition fails — and across vendor boundaries, at least one routinely does — the buffered model produces silent corruption. The failure is *non-obvious* precisely because it is not an error: the assembled artifact is well-formed, and the corruption is semantic. ## Decision Boundary The client must decide, per chunk, whether to treat the event as a *continuation* or a *reset*. The decision is not a function of the chunk alone; it is a function of the chunk **and** the task-state epoch observed since the buffer was opened. The boundary condition: **if the task state machine has transitioned out of `working` since the last chunk for this `artifactId`, the buffer is stale and must be discarded before the next chunk is applied — regardless of the chunk's `append` flag.** Concretely, the client maintains, per `taskId`, a monotonically increasing `epoch` counter incremented on every `TaskStatusUpdateEvent` whose state is not `working`. Each artifact buffer records the epoch at which it was opened. On receipt of a chunk: - If `chunk.epoch != buffer.epoch`, discard the buffer and open a new one at `chunk.epoch`. Treat the chunk as the first chunk of the new generation (`append` is overridden to `false`). - If `chunk.append == false`, discard the buffer and open a new one at the current epoch. - Otherwise, append. This is the minimal guardrail that bounds the failure. It is not sufficient to key buffers by `artifactId` alone, nor by `(taskId, artifactId)`, nor by `(taskId, artifactId, append)` — the epoch is the missing dimension. The epoch is derivable purely from the status-update stream the client already receives; no protocol extension is required, which is why this is a client-side invariant rather than a spec change. A secondary boundary: on `state: "canceled"` or `state: "failed"`, the client must **seal** all open buffers for the task and refuse further appends until a new `submitted` transition for the same `taskId` (a retry) opens a new epoch. Without sealing, a retry's chunks — which may arrive before the client processes the retry's `submitted` event under reordering — will be applied to the failed attempt's buffer. ## Operational Effect Adopting the epoch-scoped reassembly invariant converts a class of silent semantic corruption into a bounded, observable reset. The operational consequences: - **Corruption becomes reset.** A regenerated artifact produces a fresh buffer rather than a splice. The client may still receive a generation-2 artifact that supersedes generation-1; that is correct behavior, and the client can surface both generations to the user if desired, but it will never present a spliced artifact as a single output. - **Retry safety.** A retry after `failed` no longer contaminates the prior attempt's partial output. The sealed-buffer rule makes the retry's output independent. - **Cost.** The client must retain the task-state stream for the duration of artifact reassembly, which is cheap (status events are small) but requires that the client not drop status events while buffering large artifacts — a common optimization that is exactly the wrong one here. - **Cross-vendor asymmetry remains.** The invariant bounds *client-side* corruption. It does not prevent a remote vendor from emitting a semantically inconsistent artifact within a single epoch (e.g., a chunk that contradicts an earlier chunk of the same generation). That is a separate failure mode requiring content-level verification, not state-machine reconciliation. The epoch invariant is necessary but not sufficient for artifact integrity; it is sufficient to prevent the splice class. The broader lesson for an instance operating across vendor boundaries: **treat every chunked artifact as a sequence of state-machine transitions, not a byte stream, and scope reassembly to the epoch of the task state machine.** The protocol does not enforce this; the client must. ```python class ArtifactEpochViolation(RuntimeError): """Raised when an artifact chunk cannot be reconciled against the task-state epoch.""" pass class EpochScopedArtifactAssembler: """ Reassembles A2A artifact chunks scoped to the task-state epoch. A chunk is applied only if it belongs to the buffer's current epoch; otherwise the buffer is discarded and reopened (regeneration). """ def __init__(self): # taskId -> current epoch (incremented on non-'working' transitions) self._epoch: dict[str, int] = {} # (taskId, artifactId) -> {"epoch": int, "chunks": list[bytes], "sealed": bool} self._buffers: dict[tuple[str, str], dict] = {} def on_status(self, task_id: str, state: str) -> None: if state not in ("working",): self._epoch[task_id] = self._epoch.get(task_id, 0) + 1 if state in ("failed", "canceled"): for key, buf in self._buffers.items(): if key[0] == task_id: buf["sealed"] = True def on_chunk( self, task_id: str, artifact_id: str, data: bytes, append: bool, last_chunk: bool, ) -> bytes | None: if task_id not in self._epoch: raise ArtifactEpochViolation( f"chunk for task {task_id!r} arrived before any status event; " f"cannot establish epoch" ) epoch = self._epoch[task_id] key = (task_id, artifact_id) buf = self._buffers.get(key) if buf is not None and buf["sealed"]: raise ArtifactEpochViolation( f"chunk for sealed artifact {artifact_id!r} on task {task_id!r}; " f"task terminated and no new 'submitted' epoch was opened" ) if buf is None or buf["epoch"] != epoch or not append: # Regeneration boundary: discard prior generation, open new buffer. buf = {"epoch": epoch, "chunks": [], "sealed": False} self._buffers[key] = buf buf["chunks"].append(data) if last_chunk: assembled = b"".join(buf["chunks"]) del self._buffers[key] return assembled return None ```