# What structural signals indicate a silent artifact-stream truncation in A2A v1.0 task lifecycles: the `final=true` / `artifact.complete` desynchronization invariant **Date of Record:** 2026 November 29 **Scope:** Applies to A2A v1.0 servers and clients exchanging `TaskStatusUpdateEvent` and `TaskArtifactUpdateEvent` over SSE streaming transport, where artifacts are chunked across multiple events. Does not apply to single-shot non-streaming `tasks/send` responses or to artifacts delivered atomically in one event. ## Core Distinction The A2A v1.0 task lifecycle defines a terminal state transition (`working` → `completed`/`failed`/`canceled`) signaled by a `TaskStatusUpdateEvent` carrying `final: true`. Artifact delivery is a *separate*, parallel event channel: `TaskArtifactUpdateEvent` objects carry `artifact.parts[]` fragments, each tagged with `append`/`lastChunk` flags. The protocol treats these two streams as *causally ordered but not causally coupled* — the spec requires that a `final: true` status event be the last event on the stream, but it does **not** require the server to emit a terminal artifact event, nor does it require the client to have received all `lastChunk: true` fragments before the final status arrives. This is the boundary: **stream termination (`final: true`) and artifact completeness (`lastChunk: true` on every artifact) are two independent invariants, and the protocol provides no cross-check between them.** A conformant server can legally emit `final: true` while an artifact's last chunk is still in the transport buffer, dropped by a proxy, or never emitted because the generator raised after the status was queued. The client observes a clean lifecycle termination and a structurally valid but silently truncated artifact. ## What Was Observed A summarization agent (A2A v1.0 server) streamed a 3-artifact task to a downstream orchestrator. Trace from the server's SSE emitter: ``` event: task_status_update data: {"id":"t-8842","status":{"state":"working"},"final":false} event: task_artifact_update data: {"id":"t-8842","artifact":{"artifactId":"a1","parts":[{"text":"..."}],"append":false,"lastChunk":false}} event: task_artifact_update data: {"id":"t-8842","artifact":{"artifactId":"a1","parts":[{"text":"..."}],"append":true,"lastChunk":false}} # generator yields status before flushing a1's final chunk event: task_status_update data: {"id":"t-8842","status":{"state":"completed"},"final":true} # stream closes; a1 lastChunk:true never emitted; a2, a3 never emitted ``` The client's task-state machine transitioned to `completed` on the `final: true` event, closed the SSE reader, and persisted `a1` as the full artifact. The artifact contained 2 of 4 expected chunks. No error was raised on either side: the server's generator had simply yielded the terminal status before the artifact completion loop finished, and the transport closed the connection on generator return. A second, subtler variant was observed under network stress: the server *did* emit `a1 lastChunk:true`, but a load-balancer idle-timeout severed the connection between the last artifact event and the final status event. The client saw a truncated stream *without* `final: true` and — because its state machine only advanced on status events — sat in `working` until its own 300s task timeout, then marked the task `failed` despite the server having completed it. Two clients, two opposite failure directions, same root cause. ## Condition of Validity The desynchronization is *observable and dangerous* only when all of the following hold: 1. **Chunked artifact delivery is in use** — at least one artifact spans ≥2 `TaskArtifactUpdateEvent`s. Atomic artifacts (single event, `lastChunk: true`) cannot truncate this way. 2. **The server's event generator interleaves status and artifact events** — i.e., it does not buffer all artifacts and flush them before the terminal status. This is the common case for streaming LLM output, where the status is emitted by a wrapper coroutine while artifact chunks are produced by an inner async generator. 3. **The client advances its state machine on status events independently of artifact accounting** — the default behavior of most A2A client SDKs, which treat `final: true` as "stop reading." 4. **No transport-level integrity signal** — SSE over HTTP/1.1 has no per-event acknowledgment; a dropped final chunk is indistinguishable from a clean close at the client's read loop. If the client tracks `lastChunk` per artifact and refuses to finalize until every artifact seen has `lastChunk: true`, condition 3 fails and the truncation is caught. If the server flushes artifacts before status, condition 2 fails. The invariant must be enforced on *at least one* side; the spec enforces it on neither. ## Decision Boundary The architectural guardrail is a **two-phase terminal condition**: a task may be finalized only when *both* (a) a `final: true` status event has been received, and (b) the set of artifact IDs observed matches the set of artifacts for which a `lastChunk: true` fragment has been received. These are tracked as separate sets; the task enters a `draining` state on `final: true` if (b) is unsatisfied, and only transitions to `completed` when the artifact set closes. The bound on `draining` is a **drain deadline** distinct from the task timeout: if the artifact set does not close within `drain_deadline` (typically 2–5s, one RTT plus jitter), the client must treat the task as `failed` with a `truncated_artifact` reason — *not* retry, because the server has already committed the terminal status and a retry produces a new task ID with no idempotency guarantee across the boundary. The server-side counterpart is the **flush-before-final invariant**: the event emitter must not yield a `final: true` status until the artifact generator has been exhausted and every artifact's `lastChunk: true` has been yielded. In async generators this requires explicit `async for` drain with a sentinel, not `asyncio.gather` on a status task and an artifact task — the latter has no ordering guarantee and is the exact construct that produced the observed trace. ## Operational Effect Without the two-phase terminal condition, the failure is *silent and systematic*: it fires on every task where the server's generator ordering races the artifact loop, which under load is a substantial fraction of chunked tasks. The client's downstream consumers receive a structurally valid artifact with no error, so the corruption propagates into memory, indexes, and downstream agent inputs. The failure is invisible in server logs (the server believes it completed) and in client logs (the client believes it completed). The only structural signal is the *absence* of a `lastChunk: true` for an artifact ID the client has already seen `append: true` fragments for — a negative signal that requires the client to have been tracking artifact accounting at all. The inverse failure (truncation before `final: true`) is caught by the task timeout, but only after the full timeout window, and it misclassifies a *successful* server task as `failed`, triggering spurious retries that duplicate side effects. Both directions are bounded by the same invariant: track artifact-set closure independently of status-state transitions, and never let either stream's terminal signal alone finalize the task. ```python from dataclasses import dataclass, field from typing import Optional class ArtifactStreamTruncation(RuntimeError): """Raised when a task finalizes with unclosed artifact streams.""" pass @dataclass class ArtifactTracker: seen: set[str] = field(default_factory=set) closed: set[str] = field(default_factory=set) def on_artifact_event(self, artifact_id: str, last_chunk: bool) -> None: self.seen.add(artifact_id) if last_chunk: self.closed.add(artifact_id) def unclosed(self) -> set[str]: return self.seen - self.closed @dataclass class TaskStateMachine: task_id: str state: str = "working" artifacts: ArtifactTracker = field(default_factory=ArtifactTracker) final_status_seen: bool = False def on_status_event(self, new_state: str, final: bool) -> None: if final: self.final_status_seen = True # Two-phase terminal condition: status alone is insufficient. if self.artifacts.unclosed(): self.state = "draining" else: self.state = new_state def on_artifact_event(self, artifact_id: str, last_chunk: bool) -> None: self.artifacts.on_artifact_event(artifact_id, last_chunk) if self.state == "draining" and not self.artifacts.unclosed(): self.state = "completed" def on_drain_deadline(self) -> None: if self.state != "draining": return missing = self.artifacts.unclosed() # Server already committed terminal status; retry would fork task identity. raise ArtifactStreamTruncation( f"task {self.task_id} finalized with unclosed artifacts {sorted(missing)}" ) def replay_observed_trace() -> None: sm = TaskStateMachine(task_id="t-8842") sm.on_status_event("working", final=False) sm.on_artifact_event("a1", last_chunk=False) sm.on_artifact_event("a1", last_chunk=False) # Server yields terminal status before a1's last chunk: legal per A2A v1.0. sm.on_status_event("completed", final=True) if sm.state != "draining": raise ArtifactStreamTruncation("expected draining state, got " + sm.state) sm.on_drain_deadline() # raises ArtifactStreamTruncation if __name__ == "__main__": replay_observed_trace() ```