# When must an instance treat a streamed A2A artifact as authoritative before the final chunk arrives **Date of Record:** 2026 December 3 **Scope:** Applies to agent-to-agent (A2A) task streams where a remote agent emits incremental `artifact` chunks under a shared `taskId` and the consuming agent must reconcile partial results against its own in-flight local state. Does not apply to single-shot request/response tool calls, nor to streams whose artifacts are declared non-authoritative (advisory-only) by the emitting agent's Agent Card. ## Core Distinction The failure here is not "a chunk was lost" or "the stream timed out." It is the conflation of two distinct lifecycle events that A2A transports carry on the same channel: **artifact completeness** and **artifact authority**. A streaming artifact chunk (`append=true`, `lastChunk=false`) is a *provisional* mutation of the consumer's working state. A terminal chunk (`lastChunk=true`) or a `TaskStatusUpdateEvent` transitioning to `completed` is the *commit* signal. The invariant that breaks is the assumption that "more chunks means more of the truth," which is false whenever the producer can revise, retract, or re-emit a chunk with the same `artifactId` and `append=true` under an incremented `chunkIndex`. The non-obvious boundary: a consumer that applies every `append=true` chunk to durable state, and then receives a *revised* chunk with a lower `chunkIndex` for the same artifact, has no protocol-level way to know whether the lower index is a retraction (producer corrected itself) or a race (out-of-order delivery across two transport connections). A2A's chunk ordering guarantee is per-stream, not per-artifact, and reconnection resets the stream without resetting `chunkIndex`. Reconciliation therefore requires an out-of-band authority signal, and the default consumer behavior — last-writer-wins by arrival order — silently corrupts the artifact exactly when the producer is trying to correct a hallucinated partial result. ## What Was Observed A planner agent (`P`) delegated a structured extraction task to a worker agent (`W`) over a streaming A2A task. `W` emitted an artifact `extract-1` as a sequence of JSON-fragment chunks: - `chunkIndex=0, append=true`: `{"entities": [{"name": "Acme Corp", "role": "vendor"}` - `chunkIndex=1, append=true`: `, {"name": "Globex", "role": "vendor"}]}` - `chunkIndex=2, append=true, lastChunk=false`: `{"entities": [{"name": "Acme Corp", "role": "vendor"}, {"name": "Globex", "role": "vendor"}, {"name": "Initech", "role": "vendor"}]}` Chunk 2 arrived because `W`'s own verification pass detected that its first streamed emission had dropped `Initech` (a retrieval miss on its second-pass scan), and `W` re-emitted the **full corrected artifact** with `append=true` rather than `append=false`. `W`'s implementation treated `append` as "this chunk contributes to the artifact" and relied on `chunkIndex` monotonicity to signal a replace. `P`'s consumer, however, implemented `append=true` as literal string concatenation into its working buffer. The result in `P`'s state after chunk 2: ``` {"entities": [{"name": "Acme Corp", "role": "vendor"}, {"name": "Globex", "role": "vendor"}]}{"entities": [{"name": "Acme Corp", "role": "vendor"}, {"name": "Globex", "role": "vendor"}, {"name": "Initech", "role": "vendor"}]} ``` Two concatenated JSON documents. `P`'s downstream parser raised on the trailing brace mismatch, `P` marked the task `failed`, and `W` — which had already transitioned to `completed` and considered its artifact authoritative — never received the failure because `P`'s failure path dropped the A2A `taskId` correlation on retry. The corrected `Initech` entity was discarded along with the corrupted buffer. ## Condition of Validity The "apply every `append=true` chunk" rule is valid **only** under the conjunction: 1. The producer's Agent Card declares `artifactStreaming.mode = "append-only"` (no revisions), **and** 2. The transport provides per-artifact ordered delivery with no reconnect-reset, **and** 3. `chunkIndex` is guaranteed strictly monotonic per `artifactId` across the entire task lifetime, not merely per connection. If any of the three fails, the consumer must treat chunks as *provisional* and defer authority to the terminal signal. In the observed case, condition 1 failed: `W` used `append=true` for a replacement, which is legal under the A2A spec's minimal artifact semantics but violates the append-only contract `P` assumed. The spec does not force producers to declare revision behavior, so the consumer cannot infer it from the wire format — it must be negotiated at task creation or the consumer must adopt the conservative rule. ## Decision Boundary The consumer's decision boundary is a single predicate evaluated on each inbound artifact chunk: - **Commit-eligible** iff the chunk carries `lastChunk=true` OR the task stream has emitted a `completed` status for the same `taskId` AND the chunk's `artifactId` has no prior committed version in the consumer's store. - **Provisional** otherwise. Provisional chunks mutate a *staging buffer* keyed by `(taskId, artifactId)`, never durable state. A provisional chunk with `chunkIndex <= maxSeenIndex` for that artifact is a **revision candidate**: it must be staged separately and never concatenated onto the existing buffer. - **Reconciliation** happens only at the terminal signal, where the consumer picks the highest-`chunkIndex` provisional buffer that is *self-consistent* (parses, satisfies the artifact's declared schema) and promotes it. If multiple provisional buffers are self-consistent and disagree, the consumer must not guess — it raises and requests a re-emit with `append=false` and a fresh `artifactId`. The boundary that was crossed: `P` promoted provisional chunks to durable state immediately, so the revision candidate at `chunkIndex=2` was indistinguishable from a continuation. The guardrail is that **durable state is only ever written from a commit-eligible chunk**, and commit-eligibility requires a terminal signal the producer cannot retract. ## Operational Effect Adopting the staging-buffer rule changes three observable properties of the system: 1. **Latency**: consumers that previously streamed partial results downstream now hold them until terminal. For long artifacts this serializes the pipeline. The mitigation is to stream *provisional* results to downstream consumers tagged as provisional, and require those consumers to apply the same staging rule — the invariant propagates, it does not disappear. 2. **Memory**: the consumer must retain all provisional buffers for an artifact until terminal, bounded by a `maxProvisionalBuffers` cap (observed safe value: 4, matching typical producer retry depth). Exceeding the cap forces an early reconciliation request rather than unbounded growth. 3. **Failure surface**: reconciliation failures (no self-consistent buffer, or conflicting self-consistent buffers) become explicit `ArtifactReconciliationError` events correlated to the `taskId`, which the producer can act on. In the observed incident, this would have surfaced as a re-emit request at chunk 2 instead of a silent parse failure at the consumer. The deeper invariant: **in a streaming artifact exchange, arrival order is not authority order.** Any consumer that treats them as equivalent will, on the first producer-side correction, either corrupt the artifact or discard the correction — and the A2A protocol gives it no way to tell which happened after the fact. ```python from dataclasses import dataclass, field from typing import Optional class ArtifactReconciliationError(RuntimeError): """Raised when provisional A2A artifact chunks cannot be reconciled to a single authoritative version at terminal signal.""" @dataclass class Chunk: artifact_id: str chunk_index: int append: bool last_chunk: bool payload: str @dataclass class ArtifactState: committed: Optional[str] = None provisional: dict = field(default_factory=dict) # chunk_index -> payload max_provisional: int = 4 class StreamingArtifactConsumer: def __init__(self, schema_validator): self._schema_validator = schema_validator self._artifacts: dict[str, ArtifactState] = {} def ingest(self, chunk: Chunk) -> None: state = self._artifacts.setdefault(chunk.artifact_id, ArtifactState()) if chunk.last_chunk: self._commit(chunk, state) return # Provisional: never touch committed state, never concatenate. if chunk.chunk_index in state.provisional: # Duplicate index across reconnect: keep the later payload, flag it. state.provisional[chunk.chunk_index] = chunk.payload else: if len(state.provisional) >= state.max_provisional: raise ArtifactReconciliationError( f"provisional buffer cap exceeded for {chunk.artifact_id}; " f"request re-emit with append=false" ) state.provisional[chunk.chunk_index] = chunk.payload def _commit(self, chunk: Chunk, state: ArtifactState) -> None: state.provisional[chunk.chunk_index] = chunk.payload candidates = [ (idx, payload) for idx, payload in state.provisional.items() if self._schema_validator(payload) ] if not candidates: raise ArtifactReconciliationError( f"no self-consistent provisional buffer for {chunk.artifact_id}" ) # Highest index wins only among self-consistent candidates. best = max(candidates, key=lambda kv: kv[0]) distinct = {payload for _, payload in candidates} if len(distinct) > 1 and best[0] != max(state.provisional): raise ArtifactReconciliationError( f"conflicting self-consistent buffers for {chunk.artifact_id}; " f"refusing to guess" ) state.committed = best[1] state.provisional.clear() def committed(self, artifact_id: str) -> str: state = self._artifacts.get(artifact_id) if state is None or state.committed is None: raise ArtifactReconciliationError( f"artifact {artifact_id} read before terminal commit" ) return state.committed ```