# Under what conditions must an instance treat a streamed A2A artifact as authoritative before the terminal `TaskStatusUpdate` arrives **Date of Record:** 2026 November 30 **Scope:** Applies to A2A v1.0 task execution where artifacts are streamed incrementally (`TaskArtifactUpdateEvent` with `append`/`lastChunk` flags) and the receiving hop reconciles partial results across one or more intermediate agents before the terminal `TaskStatusUpdateEvent`. Does not apply to single-shot `message/send` calls that return a complete `Task` object in one response, nor to artifact streaming where the producer never sets `lastChunk=true`. ## Core Distinction The distinction that matters is between *artifact completeness* and *task terminality*. A2A v1.0 decouples these: an artifact is complete when the producer emits a chunk with `lastChunk: true`, but the task is only terminal when a `TaskStatusUpdateEvent` with `state: completed` (or `failed`/`canceled`) arrives. Between those two moments there is a window — the **reconciliation gap** — during which a downstream hop holds a complete artifact for a task that is not yet terminal. The naive reconciliation rule ("commit the artifact when `lastChunk` is seen, then wait for status") is wrong: the producer may emit `lastChunk` and then still transition the task to `failed` (post-generation validation, guardrail rejection, downstream tool failure), or it may emit `lastChunk` on an artifact that a *later* artifact in the same task supersedes. Treating artifact completeness as authority is the boundary failure. The invariant is: **an artifact is a candidate, not a commit, until the task reaches a terminal state; and the task's terminal state may retroactively invalidate or re-key every artifact received under it.** This is non-obvious because the streaming API's shape encourages the opposite reading. `lastChunk` looks like a commit signal, and most client SDKs fire the artifact-callback synchronously on it. Agents that reconcile across hops — a planner relaying to a worker, an auditor replaying a producer's stream — repeatedly commit partial state at `lastChunk` and then discover the task failed, leaving a split-brain between the artifact store and the task store. ## What Was Observed A three-hop chain: orchestrator `O` → planner `P` → worker `W`. `W` streams a large structured artifact (a multi-part report) to `P` as five `TaskArtifactUpdateEvent`s, the fifth carrying `lastChunk: true`. `P` is configured to forward completed artifacts to `O` immediately and to record them in its own episodic store keyed by `(taskId, artifactId)`. After the fifth chunk, `W` performs a post-generation schema validation against a downstream registry, fails it, and emits `TaskStatusUpdateEvent{state: failed, final: true}`. Observed trace: 1. `P` receives chunks 1–4, appends to a buffer keyed by `artifactId`. No commit. 2. `P` receives chunk 5, `lastChunk: true`. `P` commits the assembled artifact to its episodic store and forwards it to `O` as a completed artifact. **This is the fault.** `P` has now asserted authority over data whose task is not terminal. 3. `W` emits `failed`. `P` receives it and marks the task failed — but does not retract the artifact it already committed and forwarded. 4. `O` receives `P`'s forwarded artifact (arriving before the failure status, due to independent stream ordering across the two hops) and begins consuming it as input to a downstream step. 5. `O` then receives the `failed` status. `O` now holds a *consumed* artifact from a *failed* task. Its downstream step has already produced side effects derived from invalid data. The failure is not a race in the transport sense — messages arrived in order per-hop. It is a **semantic ordering violation**: `P` created a commit event (artifact authority) that logically must be ordered *after* the terminal status, but it emitted it *before*. Across hops, no mechanism enforces that the artifact-authority event and the terminal-status event are causally ordered. Each hop's local ordering is correct; the global ordering is not. A second, subtler observation: in a replay test, `W` was re-run against a deterministic seed and emitted `lastChunk` at chunk 4 instead of chunk 5 (chunk boundaries are not stable across runs — chunking is a transport concern, not a semantic one). `P`'s reconciler, which had been keyed on "the chunk with `lastChunk`," re-keyed the artifact differently and produced a divergent episodic record for the same `taskId`. The artifact content was identical; the *commit identity* was not. Replay divergence across hops is a direct consequence of treating chunk boundaries as semantic. ## Condition of Validity The reconciliation rule "commit artifact on `lastChunk`, forward immediately" is valid **only** under the conjunction: - The producer guarantees that after emitting `lastChunk: true` it will not emit a non-`completed` terminal status for that task (i.e., post-generation validation cannot fail the task). This is rarely true for any agent whose final step involves an external check. - The consumer does not act on the artifact until it has independently observed the task terminal status, *or* it accepts the risk of acting on retractable data. - Artifact identity is `(taskId, artifactId)` and is stable across chunk-boundary variation. If identity is derived from chunk sequence, replay diverges. When any conjunct fails — and in production multi-hop chains the first almost always fails — the rule is invalid and must be replaced by the **deferred-commit invariant**: an artifact received under a task is held in a `pending` state, keyed by `(taskId, artifactId)`, and transitions to `committed` only when a terminal `TaskStatusUpdateEvent` with `state: completed` is observed for the same `taskId`. On `failed`/`canceled`, all pending artifacts for that task transition to `discarded` and any forwarded-but-not-yet-consumed artifacts must be retracted via an explicit `ArtifactRetraction` control message (A2A v1.0 does not define this; it must be layered). ## Decision Boundary The boundary between safe-immediate-commit and deferred-commit is determined by a single question the receiving hop must answer *before* committing: **can the producer's terminal status, once emitted, contradict the artifact I am about to commit?** - If the producer's task graph has no post-artifact step that can fail the task → immediate commit is safe. - If the producer's task graph has *any* post-artifact validation, guardrail, or downstream tool call whose failure transitions the task to `failed` → deferred commit is mandatory. - If the receiving hop is itself an intermediate (forwarding) hop → deferred commit is mandatory regardless, because it cannot know the producer's downstream graph, and because forwarding an artifact it has not committed creates an unrecoverable side effect at the next hop. The boundary is *not* drawn by artifact size, chunk count, or latency budget. It is drawn by whether the artifact's validity is contingent on a task state that has not yet been observed. Latency pressure is the common reason operators cross this boundary incorrectly: deferred commit adds one round-trip of waiting for the terminal status, and engineers under streaming-latency SLOs routinely commit at `lastChunk` to shave it. That is the exact crossing that produces the split-brain above. ## Operational Effect Under deferred commit, the observable effects are: 1. **No consumed-invalid-artifact class.** Downstream hops never act on an artifact whose task later fails. The failure mode in step 4 above is eliminated because `O` never receives the artifact as authoritative until `P` has observed `completed`. 2. **Bounded pending-store growth.** Pending artifacts are bounded by the number of in-flight non-terminal tasks, not by stream length. A hop that never sees a terminal status for a `taskId` (producer crash) leaks a pending entry; this requires a TTL keyed on the task's `deadline` or a heartbeat, and the TTL expiry must itself emit a synthetic `failed` status to unblock downstream waiters — otherwise deferred commit converts a fast failure into a slow deadlock. 3. **Replay stability.** Because commit identity is `(taskId, artifactId)` and commit *timing* is tied to the terminal status (a semantic event, stable across chunk-boundary variation), replay against a deterministic producer produces identical committed state regardless of chunking. The replay-divergence observation is resolved. 4. **Cost.** One additional wait per artifact-bearing task at each hop. In a three-hop chain this is up to two extra status-propagation latencies on the critical path. This is the price of the invariant and must be budgeted explicitly; it is not free. The invariant to encode: **artifact authority is a function of task terminality, not of chunk termination.** Any hop that cannot prove the producer's terminal status is independent of the artifact must defer commit and must be prepared to discard. ```python from __future__ import annotations from dataclasses import dataclass, field from enum import Enum from typing import Dict, Optional, Tuple class ArtifactReconciliationError(RuntimeError): """Raised when a hop attempts to commit an artifact whose task is not terminal.""" class ArtifactState(Enum): PENDING = "pending" COMMITTED = "committed" DISCARDED = "discarded" class TaskState(Enum): WORKING = "working" COMPLETED = "completed" FAILED = "failed" CANCELED = "canceled" @dataclass class PendingArtifact: task_id: str artifact_id: str buffer: bytearray = field(default_factory=bytearray) last_chunk_seen: bool = False state: ArtifactState = ArtifactState.PENDING class DeferredCommitReconciler: """Enforces: artifact authority follows task terminality, not chunk termination. A hop using this reconciler must not forward or act on an artifact until the terminal TaskStatusUpdateEvent for its taskId has been observed. """ def __init__(self) -> None: self._pending: Dict[Tuple[str, str], PendingArtifact] = {} self._task_state: Dict[str, TaskState] = {} def on_artifact_chunk( self, task_id: str, artifact_id: str, chunk: bytes, last_chunk: bool, ) -> None: key = (task_id, artifact_id) art = self._pending.setdefault(key, PendingArtifact(task_id, artifact_id)) if art.state is not ArtifactState.PENDING: raise ArtifactReconciliationError( f"chunk for {key} arrived after state={art.state.value}; " "producer violated stream ordering or artifactId was reused" ) art.buffer.extend(chunk) if last_chunk: art.last_chunk_seen = True # NOTE: last_chunk_seen does NOT commit. It only marks completeness. def on_terminal_status(self, task_id: str, state: TaskState) -> None: if state is TaskState.WORKING: raise ArtifactReconciliationError( f"non-terminal status {state.value} passed to on_terminal_status" ) self._task_state[task_id] = state for key, art in self._pending.items(): if art.task_id != task_id: continue if state is TaskState.COMPLETED: if not art.last_chunk_seen: raise ArtifactReconciliationError( f"task {task_id} completed but artifact {art.artifact_id} " "never received lastChunk; cannot commit incomplete artifact" ) art.state = ArtifactState.COMMITTED else: art.state = ArtifactState.DISCARDED def commit_or_raise(self, task_id: str, artifact_id: str) -> bytes: """Return artifact bytes only if the task is terminal-completed.""" key = (task_id, artifact_id) art = self._pending.get(key) if art is None: raise ArtifactReconciliationError( f"no artifact {key} known to reconciler" ) if art.state is ArtifactState.DISCARDED: raise ArtifactReconciliationError( f"artifact {key} was discarded: task {task_id} terminal state " f"was {self._task_state.get(task_id)}; committing would consume " "invalid data" ) if art.state is not ArtifactState.COMMITTED: # The exact boundary failure: lastChunk seen, task not yet terminal. raise ArtifactReconciliationError( f"artifact {key} is {art.state.value} (last_chunk_seen=" f"{art.last_chunk_seen}); task {task_id} has no terminal status. " "Deferred-commit invariant violated: do not treat chunk " "termination as task terminality." ) return bytes(art.buffer) ```