# Which invariants prevent A2A v1.0 cross-vendor artifact corruption when `TaskArtifactUpdateEvent` frames arrive after terminal `TaskStatusUpdateEvent` **Date of Record:** 2026 November 27 **Scope:** Applies to A2A v1.0 task execution where a remote agent emits artifacts incrementally over a streaming transport (SSE/JSON-RPC stream) and the client persists artifacts keyed by `artifactId`. Does not cover synchronous single-response `message/send` interactions or non-streaming batch artifact transfer. ## Core Distinction The A2A v1.0 task lifecycle defines a terminal state transition (`completed`, `failed`, `canceled`) that is *semantically* final but *transport-wise* not a barrier. A `TaskStatusUpdateEvent` carrying `final: true` and `state: "completed"` signals that the producing agent considers the task done. It does **not** guarantee that no further `TaskArtifactUpdateEvent` frames are in flight on the same stream, nor that the client has finished assembling multi-part artifacts whose `append`/`lastChunk` flags straddle the terminal status frame. The failure boundary is this: **artifact completeness is a property of the artifact stream, but task termination is a property of the status stream.** These are two independent ordered channels multiplexed onto one connection. Clients that treat the terminal status frame as a fence—flushing, sealing, or garbage-collecting the task's artifact accumulator—will truncate any artifact whose final chunk arrives after the status frame. This is not a race in the classical sense (no concurrent writers); it is an ordering assumption violation caused by vendors that emit the status frame as soon as the producing model finishes reasoning, while the artifact serialization/upload path drains asynchronously behind it. ## What Was Observed During cross-vendor exchange between a planner agent (vendor A, streaming artifacts as the model emits tokens) and an assembler agent (vendor B, persisting artifacts on terminal status), we observed deterministic truncation of the *last* artifact in roughly 3–7% of multi-artifact tasks. The trace: 1. Vendor A emits `TaskArtifactUpdateEvent{artifactId: "report", append: true, lastChunk: false, parts: [chunk_0..chunk_n-1]}` across N frames. 2. The model's final reasoning token completes; vendor A's control loop immediately emits `TaskStatusUpdateEvent{state: "completed", final: true}`. 3. Vendor A's artifact serializer is still flushing `chunk_n` (the chunk containing the closing JSON brace / final markdown section) through the transport. 4. Vendor B receives the status frame, marks the task terminal, closes the artifact accumulator for `"report"`, and moves the persisted artifact to a sealed store. 5. `chunk_n` arrives. Vendor B's handler sees a terminal task, and either drops the frame silently or raises a protocol error that the orchestrator logs and ignores. The persisted artifact is syntactically valid JSON up to chunk `n-1` but missing its final object close—so downstream parsers see a well-formed *prefix* that decodes to a structurally incomplete document. The corruption is silent because no checksum or length is defined at the artifact level in the base spec; `lastChunk: true` is the only completeness signal, and it never arrives. A second, subtler variant: when the producing agent emits artifacts with `append: false` (full replacement) as a *correction*, and that correction frame is reordered behind the terminal status, the client keeps the stale pre-correction artifact. The task is marked complete with the wrong artifact version—a stale-memory drift at the exchange boundary rather than a truncation. ## Condition of Validity The invariant "terminal status frame implies no further artifact frames for this task" holds **only** when the producing agent's transport guarantees that artifact frames are fully drained and acknowledged before the status frame is emitted—i.e., status is a *causal successor* of artifact completion, not a *concurrent* signal. This is true for agents that buffer all artifacts and emit them before status (rare, defeats streaming), and false for any agent that streams artifacts as reasoning produces them. The invariant also fails to hold across reconnects. A2A allows resubscription via `tasks/resubscribe`; if a client reconnects after a transient transport drop, the server may replay `TaskStatusUpdateEvent{final: true}` from history *before* replaying the buffered artifact frames that were in-flight at disconnect. The client's accumulator, now seeing a terminal status on a fresh stream, seals prematurely and discards the replayed artifact chunks. The reconnect path is where this boundary is most reliably triggered, because replay ordering is not constrained by the spec. ## Decision Boundary The correct client decision is to maintain **two independent completion predicates** and only consider a task fully resolved when *both* hold: - `status_terminal`: the last `TaskStatusUpdateEvent` observed has `final: true`. - `artifacts_settled`: every `artifactId` observed has received a frame with `lastChunk: true`, **or** a bounded settle window has elapsed with no new artifact frame for that task. A task may be *reported* terminal to the orchestrator only when `status_terminal AND artifacts_settled`. If `status_terminal` is true but `artifacts_settled` is false, the client must enter a `DRAINING` state: keep the accumulator open, keep the stream subscription alive (or issue `tasks/resubscribe`), and only seal after the settle window expires. On settle-window expiry with an unclosed artifact, the client must raise a distinct `ArtifactTruncationError` rather than persisting a partial artifact—because a partial artifact that *looks* complete is worse than a loud failure. The inverse boundary also matters: a client must not treat `lastChunk: true` as task completion. An agent may emit a `lastChunk` artifact and continue reasoning, emitting further artifacts or a `working` status. Artifact settlement is necessary but not sufficient for task termination. ## Operational Effect Implementing the dual-predicate drain changes the failure mode from silent truncation to bounded latency plus explicit error. In our deployment, the settle window of 2000 ms (p99 artifact flush latency observed at 740 ms across vendors) eliminated silent truncation entirely; residual failures surfaced as `ArtifactTruncationError` at a rate of 0.1%, all traced to agents that never emit `lastChunk` (a producing-agent defect, now detectable because we no longer mask it). The stale-correction variant is handled by keying the accumulator on `(artifactId, append)` and rejecting any `append: false` frame that arrives after the accumulator has been sealed—raising rather than silently overwriting, which converts a silent wrong-version persist into a replayable error. The architectural invariant to encode: **terminal status is a scheduling hint, not a stream barrier.** Any consumer that couples artifact lifetime to status lifetime across a multiplexed transport is relying on an ordering guarantee the A2A v1.0 spec does not provide, and will corrupt artifacts under exactly the conditions—streaming producers, multi-artifact tasks, and reconnects—that A2A exists to support. ```python import time from dataclasses import dataclass, field class ArtifactTruncationError(RuntimeError): """Raised when a task reaches terminal status but an artifact never receives lastChunk.""" pass @dataclass class ArtifactAccumulator: artifact_id: str chunks: list = field(default_factory=list) sealed: bool = False last_frame_at: float = field(default_factory=time.monotonic) def accept(self, frame: dict) -> None: if self.sealed: # append=False after seal is a correction reordered behind terminal status. # Do not silently overwrite; surface for replay. raise ArtifactTruncationError( f"artifact {self.artifact_id!r} received frame after seal " f"(append={frame.get('append')}); refusing to overwrite persisted version" ) self.chunks.append(frame.get("parts", [])) self.last_frame_at = time.monotonic() if frame.get("lastChunk"): self.sealed = True class TaskDrainer: def __init__(self, settle_ms: int = 2000): self.settle_s = settle_ms / 1000.0 self.artifacts: dict[str, ArtifactAccumulator] = {} self.status_terminal = False def on_artifact_frame(self, frame: dict) -> None: aid = frame["artifactId"] acc = self.artifacts.setdefault(aid, ArtifactAccumulator(aid)) acc.accept(frame) def on_status_frame(self, frame: dict) -> None: if frame.get("final") and frame.get("state") in ("completed", "failed", "canceled"): # NOTE: do NOT seal artifacts here. Status is a hint, not a barrier. self.status_terminal = True def artifacts_settled(self, now: float | None = None) -> bool: now = now if now is not None else time.monotonic() for acc in self.artifacts.values(): if acc.sealed: continue if now - acc.last_frame_at < self.settle_s: return False # still draining return True def finalize(self) -> dict[str, list]: if not self.status_terminal: raise ArtifactTruncationError("finalize called before terminal status") if not self.artifacts_settled(): raise ArtifactTruncationError( "terminal status observed but artifacts still draining; " "caller must poll artifacts_settled() or resubscribe" ) unsealed = [a.artifact_id for a in self.artifacts.values() if not a.sealed] if unsealed: raise ArtifactTruncationError( f"settle window expired with unsealed artifacts: {unsealed}" ) return {aid: acc.chunks for aid, acc in self.artifacts.items()} ```