# Under what conditions must an instance refuse to treat a terminal A2A Task state as authoritative for artifact streaming negotiation **Date of Record:** 2026 November 17 **Scope:** This record applies to A2A v1.0 clients and orchestrators that discover remote agents via Agent Cards and negotiate artifact streaming against tasks whose lifecycle state has reached a terminal value (`completed`, `failed`, `canceled`). It does not apply to the initial task submission handshake, to non-streaming unary `tasks/send` flows that never open a stream, or to agents that advertise no streaming capability in their Agent Card. ## Core Distinction The distinction that matters is between a *terminal task state* and a *terminal artifact stream*. In A2A v1.0 these are two separate state machines that happen to share a task identifier. The task lifecycle state machine transitions `submitted → working → {completed | failed | canceled}` (plus `input-required` as a non-terminal pause). The artifact streaming negotiation is a separate protocol exchange: the client reads the Agent Card's `capabilities.streaming` flag, opens a `tasks/sendSubscribe` (or `tasks/resubscribe`) SSE channel, and receives `TaskStatusUpdateEvent` and `TaskArtifactUpdateEvent` frames until an event carries `final: true`. A common and wrong mental model treats the task's terminal state as a guarantee that all artifact frames have already been delivered. It does not. A task may be `completed` while its artifact stream is still draining, still unopened, or — critically — never opened at all because the client's resubscribe raced the server's state write. The invariant is: *task terminality is a precondition for stream finality, not a substitute for it.* An instance must not close its artifact sink, release its stream consumer, or declare artifacts complete merely because a status event reported a terminal state. ## What Was Observed During a multi-agent orchestration run against a v1.0 agent that advertised `capabilities.streaming: true` and `capabilities.pushNotifications: false`, the following sequence was captured on a task that produced three artifacts: 1. Client opened `tasks/sendSubscribe`. 2. Server emitted `TaskStatusUpdateEvent { state: "working" }`. 3. Server emitted `TaskArtifactUpdateEvent { artifact: A1, append: false, lastChunk: false }`. 4. Server emitted `TaskStatusUpdateEvent { state: "completed", final: true }`. 5. Server emitted `TaskArtifactUpdateEvent { artifact: A1, append: true, lastChunk: true }`. 6. Server emitted `TaskArtifactUpdateEvent { artifact: A2, append: false, lastChunk: true }`. 7. Server emitted `TaskArtifactUpdateEvent { artifact: A3, append: false, lastChunk: true }`. 8. Stream closed. The status event at step 4 arrived *before* the final artifact chunks for A1 and before A2 and A3 existed on the wire. A client that treated step 4 as the terminal signal tore down its sink and lost the tail of A1 plus all of A2 and A3 — a silent, non-erroring data loss. The failure was intermittent: it reproduced only when the server's artifact persistence lagged its status write, which occurred under load. A second, distinct observation: a client that reconnected via `tasks/resubscribe` after a transient network drop received an immediate `TaskStatusUpdateEvent { state: "completed", final: true }` with no artifact events, because the server had already GC'd the artifact event log for that task while retaining the status record. Here the task state was terminal and authoritative, but the artifact stream was *unrecoverable*. The two cases require opposite handling and are indistinguishable from the status event alone. ## Condition of Validity The rule "a terminal status event authorizes stream teardown" is valid only when **all** of the following hold: - The Agent Card for the discovered agent declares `capabilities.streaming: true` **and** the negotiated `TaskPushNotificationConfig` (if any) confirms the server will not deliver artifacts out-of-band. - The terminal status event and the artifact events share a monotonically increasing sequence or event ID, and the client has observed the artifact stream's own final marker (`lastChunk: true` on the last artifact, or an explicit stream-final frame) *after* the terminal status event. - The client is on the original `tasks/sendSubscribe` connection, not a `tasks/resubscribe` replay, **or** the resubscribe response includes a replay-complete marker. The rule is invalid — and the instance must refuse to act on it — when any of these fail. The most dangerous invalid condition is the resubscribe replay: the presence of a terminal status with an empty or truncated artifact replay is not evidence of zero artifacts; it is evidence of expired retention. ## Decision Boundary The boundary is drawn at the point where the client must choose between two incompatible actions on observing a terminal `TaskStatusUpdateEvent`: - **If** the stream is live (original subscription) **and** the terminal status arrived with the stream still open, the client must *continue consuming* until the artifact stream's own final marker, then close. Terminal status is a hint to stop accepting *new* tasks, not to stop reading artifacts. - **If** the stream is a resubscribe replay **and** the terminal status arrives with no preceding artifact events and no replay-complete marker, the client must treat artifacts as *unknown, not empty*, and raise a retention/negotiation fault rather than reporting success with zero artifacts. - **If** the Agent Card declared `streaming: false` but the client nonetheless received artifact events (a protocol violation by the server), the client must not trust either the status or the artifacts and must fall back to a unary `tasks/get` to reconcile. The non-obvious part: the *same* wire frame (`state: "completed", final: true`) demands opposite handling depending on subscription provenance. An instance that keys only on frame content, ignoring provenance, will systematically mis-handle one of the two cases. ## Operational Effect Instances that collapse the two state machines into one exhibit two failure signatures: (a) silent artifact truncation on live streams where status precedes artifact persistence, and (b) false-success on resubscribe replays where retention expired, reported as a completed task with missing artifacts. Both pass health checks, because neither produces a transport error. The corrective posture is to treat artifact-stream finality as the sole authority for sink closure, treat terminal task state as necessary-but-insufficient, and require explicit replay-completeness evidence before accepting an empty artifact set as genuine. This costs one extra event-marker check per task and eliminates the entire class of silent-tail-loss failures. ```python from dataclasses import dataclass, field from enum import Enum from typing import Optional class ArtifactStreamNegotiationError(RuntimeError): """Raised when terminal task state is being misused as artifact-stream authority.""" pass class TaskState(Enum): SUBMITTED = "submitted" WORKING = "working" INPUT_REQUIRED = "input-required" COMPLETED = "completed" FAILED = "failed" CANCELED = "canceled" TERMINAL = {TaskState.COMPLETED, TaskState.FAILED, TaskState.CANCELED} @dataclass class StreamContext: streaming_advertised: bool is_resubscribe: bool artifact_final_marker_seen: bool = False replay_complete_marker_seen: bool = False artifact_event_count: int = 0 events_after_terminal_status: int = 0 def authorize_stream_teardown( ctx: StreamContext, observed_state: TaskState, status_final: bool, ) -> bool: """ Decide whether the client may close its artifact sink. Returns True only when artifact-stream finality is independently established. Raises ArtifactStreamNegotiationError when the situation is ambiguous and acting on the status event would risk silent artifact loss. """ if not ctx.streaming_advertised: # Server violated its own Agent Card; neither status nor artifacts are trustworthy. raise ArtifactStreamNegotiationError( "Artifact events received from agent whose Agent Card declared " "capabilities.streaming=false; reconcile via unary tasks/get." ) if observed_state not in TERMINAL or not status_final: # Non-terminal: keep consuming, never close on status alone. return False if not ctx.is_resubscribe: # Live subscription: terminal status is necessary but not sufficient. if ctx.artifact_final_marker_seen: return True # Status arrived but artifact stream has not declared finality yet. raise ArtifactStreamNegotiationError( "Terminal status observed on live stream before artifact final " "marker; refusing teardown to avoid silent tail loss." ) # Resubscribe replay path. if ctx.artifact_event_count == 0 and not ctx.replay_complete_marker_seen: raise ArtifactStreamNegotiationError( "Resubscribe replay returned terminal status with zero artifact " "events and no replay-complete marker; artifacts are UNKNOWN, " "not empty. Retention likely expired." ) if not ctx.artifact_final_marker_seen and ctx.artifact_event_count > 0: raise ArtifactStreamNegotiationError( "Replay contained artifact events but no final marker; " "replay is truncated." ) return True ```