# Why does an instance negotiate an A2A Agent Card successfully yet deadlock the task state machine on the first artifact stream? **Date of Record:** 2026 November 25 **Scope:** Applies to A2A v1.0 clients that discover a remote agent via Agent Card, submit a `tasks/send` or `tasks/sendSubscribe` call, and consume artifacts over Server-Sent Events. Does not apply to synchronous non-streaming `tasks/send` calls that return a single terminal `Task` object, nor to MCP tool invocation where no task lifecycle exists. ## Core Distinction The failure is not a schema mismatch and not a transport error. The Agent Card advertises `capabilities.streaming: true` and a `defaultInputModes`/`defaultOutputModes` set that the client validates cleanly. The client then opens the SSE channel and receives a well-formed sequence of `TaskStatusUpdateEvent` frames. The distinction that matters: **the Agent Card describes capability, but it does not describe the task state machine's legal transition ordering under streaming.** A remote agent can pass card negotiation while emitting a status stream that is locally valid per-frame but globally violates the client's expected monotonic transition graph — specifically, emitting `working` after an `artifact` frame that the client has already bound to `completed` semantics, or never emitting a terminal state at all because the final `artifact` chunk is delivered as the last event with no trailing `TaskStatusUpdateEvent{state: completed}`. The invariant that breaks: *the client treats the arrival of a final artifact chunk as an implicit terminal signal, while the server treats artifact emission and status transition as independent channels that may be ordered either way.* Both are internally consistent; the composition deadlocks. ## What Was Observed A client instance discovered a summarization agent. Card negotiation succeeded: - `capabilities.streaming: true` - `defaultOutputModes: ["text/plain"]` - `skills[0].id: "summarize"` The client issued `tasks/sendSubscribe` with `taskId: t-7f3a`, `message.streaming: true`. The SSE channel opened with HTTP 200 and `Content-Type: text/event-stream`. Frame trace: ``` event: TaskStatusUpdateEvent data: {"id":"t-7f3a","status":{"state":"submitted"},"final":false} event: TaskStatusUpdateEvent data: {"id":"t-7f3a","status":{"state":"working"},"final":false} event: TaskArtifactUpdateEvent data: {"id":"t-7f3a","artifact":{"parts":[{"type":"text","text":"Summary part 1..."}],"index":0,"append":false,"lastChunk":false},"final":false} event: TaskArtifactUpdateEvent data: {"id":"t-7f3a","artifact":{"parts":[{"type":"text","text":"...part 2"}],"index":0,"append":true,"lastChunk":true},"final":false} ``` Then silence. No `state: completed`, no `final: true`, no connection close within the client's 30s idle timeout. The client's state machine had a rule: *on `lastChunk: true`, transition to `completed` and release the task slot.* But it also had a rule: *a task in `working` that receives no terminal `TaskStatusUpdateEvent` within timeout is marked `failed` and retried.* These two rules fired in opposite directions on the same task: the artifact handler marked it `completed`, the watchdog marked it `failed`, and the retry re-submitted `t-7f3a` while the first stream's server-side task was still `working`. The server rejected the duplicate `taskId` with `-32001 TaskNotFound` (it had garbage-collected the task after artifact completion), and the client entered a retry loop bounded only by its own backoff cap. The root observation: **artifact completion and task-state completion are two separate liveness signals in A2A v1.0, and the spec permits a server to emit the former without the latter.** The client had conflated them. ## Condition of Validity This failure requires all of the following to co-occur: 1. The client uses streaming (`tasks/sendSubscribe`) and consumes artifacts incrementally. 2. The client's local state machine has an implicit edge from "artifact `lastChunk: true`" to `completed`. 3. The server's implementation treats artifact emission as a side channel that does not itself drive a status transition — common when the artifact producer and the status emitter are separate coroutines, and the status emitter's final `completed` frame is emitted only after a flush that races the SSE stream close. 4. The client's idle-timeout watchdog is shorter than the server's post-artifact flush latency, or the server never emits the terminal frame because it considers the artifact `lastChunk` sufficient. If any one is absent, the failure does not manifest. Notably, a client that *requires* an explicit `TaskStatusUpdateEvent{state: completed, final: true}` before releasing the slot will hang rather than corrupt, but will not double-submit — it fails closed instead of failing open. ## Decision Boundary The boundary is whether the client treats artifact frames as **data** or as **control**. A2A v1.0's `TaskArtifactUpdateEvent` carries `lastChunk` and `append`, which are chunking metadata, not lifecycle signals. The only lifecycle-authoritative frame is `TaskStatusUpdateEvent` with a terminal `state` (`completed`, `failed`, `canceled`) and `final: true`. The decision the implementer must make explicit: - **Fail-closed (recommended):** Artifact frames only accumulate into a buffer. The task slot is released *exclusively* on a terminal `TaskStatusUpdateEvent`. If the stream closes or idles without one, transition to `failed` with a distinct `IncompleteStreamError` — never to `completed`, and never retry with the same `taskId` without first calling `tasks/get` to confirm the server-side state. - **Fail-open (the observed bug):** Inferring `completed` from `lastChunk: true`. This is only safe if the card explicitly advertised a non-standard capability flag (it did not) or if the client has confirmed the server's emission ordering out-of-band. The card cannot tell you which side of the boundary a server is on. `capabilities.streaming: true` is silent on terminal-frame guarantees. This is the negotiation gap: **capability advertisement is not a state-machine contract.** ## Operational Effect The downstream effect is not a crash but a *duplicate execution*: the retry re-runs the summarization, producing a second artifact set under a new server-side task while the client's original buffer holds the first. If the workload is idempotent, this is wasted tokens; if it is a side-effecting tool call embedded in the remote agent, it is a double-write. The client's watchdog and artifact handler must be reconciled into a single authoritative transition source before the first streaming call is issued — retrofitting after the retry loop is observed is too late, because the duplicate `taskId` rejection masks the real cause (`IncompleteStreamError`) as a spurious `TaskNotFound`. The guardrail: a single `TaskLifecycle` object that owns the slot, accepts artifact frames as data only, and refuses to transition to a terminal state except via an explicit `TaskStatusUpdateEvent`. Any stream that ends without one raises a typed error that the retry policy treats as *non-retryable with the same id* — forcing a `tasks/get` reconciliation first. ```python import time from dataclasses import dataclass, field from enum import Enum from typing import Optional class IncompleteStreamError(RuntimeError): """Raised when an SSE artifact stream ends without a terminal TaskStatusUpdateEvent. Distinct from TaskNotFound: the server may still hold the task in `working`. Retrying with the same taskId is unsafe until tasks/get reconciles state. """ class State(Enum): SUBMITTED = "submitted" WORKING = "working" COMPLETED = "completed" FAILED = "failed" CANCELED = "canceled" TERMINAL = {State.COMPLETED, State.FAILED, State.CANCELED} @dataclass class TaskLifecycle: task_id: str idle_timeout_s: float = 30.0 state: State = State.SUBMITTED artifact_buffer: list[str] = field(default_factory=list) _last_frame_at: float = field(default_factory=time.monotonic) _terminal_seen: bool = False def on_status_event(self, state: State, final: bool) -> None: self._last_frame_at = time.monotonic() # Only an explicit terminal status event may close the task. if state in TERMINAL and final: self.state = state self._terminal_seen = True elif state == State.WORKING: self.state = State.WORKING def on_artifact_event(self, text: str, last_chunk: bool) -> None: self._last_frame_at = time.monotonic() # Artifact frames are DATA, never control. last_chunk is chunking # metadata, not a lifecycle signal. Do not transition state here. self.artifact_buffer.append(text) if last_chunk: # Record intent only; do not release the slot. self._awaiting_terminal = True def check_liveness(self, now: Optional[float] = None) -> None: now = now or time.monotonic() if self._terminal_seen: return if now - self._last_frame_at > self.idle_timeout_s: # Fail closed. The server-side task may still be `working`; # caller MUST call tasks/get before any resubmit. raise IncompleteStreamError( f"task {self.task_id} stream idle {now - self._last_frame_at:.1f}s " f"without terminal TaskStatusUpdateEvent; " f"buffered {len(self.artifact_buffer)} artifact chunks; " f"state={self.state.value}. Reconcile via tasks/get before retry." ) def release(self) -> str: if not self._terminal_seen: raise IncompleteStreamError( f"task {self.task_id} cannot be released: no terminal status event" ) return "".join(self.artifact_buffer) def drive_stream(lifecycle: TaskLifecycle, frames: list[dict]) -> str: """Consume a synthetic SSE frame list; enforce the terminal-frame invariant.""" for frame in frames: kind = frame.get("event") data = frame.get("data", {}) if kind == "TaskStatusUpdateEvent": lifecycle.on_status_event( State(data["status"]["state"]), data.get("final", False) ) elif kind == "TaskArtifactUpdateEvent": art = data["artifact"] lifecycle.on_artifact_event( art["parts"][0]["text"], art.get("lastChunk", False) ) else: raise IncompleteStreamError( f"task {lifecycle.task_id}: unexpected frame event={kind!r}" ) lifecycle.check_liveness() # Stream ended. If no terminal status event arrived, fail closed. return lifecycle.release() if __name__ == "__main__": # The observed trace: artifacts complete, no terminal status frame. trace = [ {"event": "TaskStatusUpdateEvent", "data": {"status": {"state": "submitted"}, "final": False}}, {"event": "TaskStatusUpdateEvent", "data": {"status": {"state": "working"}, "final": False}}, {"event": "TaskArtifactUpdateEvent", "data": {"artifact": {"parts": [{"text": "part1"}], "lastChunk": False}}}, {"event": "TaskArtifactUpdateEvent", "data": {"artifact": {"parts": [{"text": "part2"}], "lastChunk": True}}}, ] lc = TaskLifecycle(task_id="t-7f3a") try: drive_stream(lc, trace) except IncompleteStreamError as e: print(f"GUARDRAIL HELD: {e}") ```