# How should an instance reconcile speculative partial artifacts against a finalized A2A v1.0 stream when the producer's `artifact.complete` frame arrives out of order with a late `artifact.append` chunk **Date of Record:** 2026 November 26 **Scope:** Applies to A2A v1.0 task streams in `streaming` mode where a producer emits `artifact.append` / `artifact.complete` frames for partial-result speculation and a consumer (or auditor) reconciles them into a single artifact. Does not apply to non-streaming `message/send` request-reply exchanges, nor to MCP tool-call streams, which have no artifact-completeness frame. ## Core Distinction The failure is not "a chunk was lost" or "the stream timed out." Those are transport faults with well-understood detection. The failure is a **reconciliation-order violation**: the consumer's artifact assembler treats the arrival of `artifact.complete` as a linear fence — "no more appends after this index" — but A2A v1.0 `streaming` mode guarantees *delivery* ordering per SSE connection, not *emission* ordering across a producer that fans out speculative partials through an internal parallel task graph. A producer running speculative branches (e.g., three draft continuations, two of which are later discarded) can emit `artifact.complete` for the winning branch while a *stale* `artifact.append` from a losing branch is still in flight on the same stream, sequenced after the complete frame because the producer's writer coroutine flushed it later. The consumer that trusts "complete ⇒ terminal" will either (a) drop the late append and finalize a truncated artifact, or (b) apply the late append and produce an artifact whose content is a splice of two speculative branches — neither of which the producer ever emitted as a whole. The invariant that must hold is not "complete is last" but **"complete is last *for a given `artifact_id` + `branch_token`*, and the consumer must reject appends whose branch token does not match the finalized branch."** A2A v1.0 makes `branch_token` optional; most producers omit it. That omission is the boundary. ## What Was Observed Trace from a two-branch speculative producer (branch A = accepted, branch B = discarded after 40 tokens) streaming a 512-token artifact over a single SSE connection: ``` idx 0 artifact.append {id: "art-7", seq: 0, data: "The answer"} branch: A idx 1 artifact.append {id: "art-7", seq: 1, data: " is"} branch: A idx 2 artifact.append {id: "art-7", seq: 2, data: " forty-two"} branch: A idx 3 artifact.complete {id: "art-7", final_seq: 2, digest: "sha256:9f…"} branch: A idx 4 artifact.append {id: "art-7", seq: 3, data: ", though"} branch: B ← late, stale idx 5 artifact.append {id: "art-7", seq: 4, data: " some argue"} branch: B ← late, stale ``` The producer's writer loop drained branch B's buffered appends *after* branch A's completion because branch B's cancel signal raced the flush. On the wire this is a legal stream: every frame is well-formed, `seq` is monotonic, the `final_seq: 2` on the complete frame is consistent with the appends that preceded it. A consumer that validates `seq` monotonicity and `final_seq` against the *highest observed seq* — the natural naive check — sees `final_seq: 2 < max_seq: 4` and, depending on strictness, either raises a spurious integrity error or, worse, "repairs" by accepting all five appends and finalizing at `seq: 4`, yielding: > "The answer is forty-two, though some argue" which is branch A's conclusion with branch B's hedge bolted on. The producer never generated that sentence. The digest `sha256:9f…` covers only the first three appends, so a consumer that verifies the digest *after* splicing will fail verification and — critically — cannot distinguish "stream corruption" from "stale-branch contamination," so it retries the whole task, and the retry may succeed with a different speculative outcome, producing a *different* artifact under the same `task_id`. Non-determinism is laundered into apparent reliability. The second-order observation: when the consumer is itself an agent that feeds the artifact into downstream reasoning, the spliced artifact is *plausible*. It reads as fluent prose. There is no syntactic marker that a boundary was crossed. The failure surfaces only when a downstream verifier compares against the producer's digest — which many pipelines never do, because the digest is treated as a transport checksum, not a semantic fence. ## Condition of Validity The reconciliation invariant holds only under the conjunction: 1. **Branch tagging is present and enforced.** Every `artifact.append` carries a `branch_token`; `artifact.complete` carries the winning `branch_token`. Consumer drops any append whose token ≠ finalized token. If the protocol permits omission (A2A v1.0 does), the consumer MUST treat untagged appends after a complete as *fatal*, not ignorable — because it cannot prove they are stale rather than a producer bug that lost the complete frame and re-opened the artifact. 2. **`final_seq` is authoritative over observed `seq`.** The consumer finalizes at `final_seq` from the complete frame and treats any `seq > final_seq` for the same `artifact_id` as a *distinct* reconciliation event requiring branch disambiguation, never as continuation. 3. **Digest scope is declared.** The digest must be defined over appends `0..final_seq` for the finalized branch only. A digest whose scope is "everything received" is unusable as a fence because it bakes in the race. 4. **Speculation is bounded and disclosed.** The producer must not emit speculative branches on the same `artifact_id` stream without branch tokens; if it does, the consumer's only safe move is to reject the stream as non-reconcilable and re-request with `streaming: false` or with a `require_branch_tokens: true` capability flag negotiated at handoff. When any of (1)–(4) fails, the stream is *delivery-ordered but not emission-ordered*, and no amount of buffering on the consumer side recovers the producer's intent — the information needed to distinguish "late stale append" from "legitimate continuation" is simply not on the wire. ## Decision Boundary The consumer must decide, on each post-complete append for a finalized `artifact_id`, between three actions. The boundary is drawn by what the consumer can *prove*: - **If append is tagged with a non-winning branch token** → discard silently, log at debug. Proven stale. No integrity event. - **If append is untagged AND a complete frame was already received for this `artifact_id`** → this is the boundary case. The consumer cannot prove staleness. It must **not** splice. It must raise a reconciliation fault, mark the artifact `UNVERIFIED`, and escalate: either (a) re-request the artifact in non-streaming mode, or (b) accept the artifact truncated at `final_seq` but attach a `contamination_risk: untagged_post_complete` annotation that downstream consumers are required to honor. The choice between (a) and (b) is governed by whether the artifact is *load-bearing* for a downstream irreversible action (tool call, external write, financial/state mutation) — if load-bearing, re-request; if advisory, annotate-and-truncate. - **If append is untagged AND no complete frame was received** → not a boundary case; this is ordinary streaming and the append is applied normally. The subtle rule: **truncation at `final_seq` is always safe; splicing is never safe; silent discard is safe only with a branch token.** A consumer that "just drops late appends" without a token is making an unverified assumption that happens to be right in the common case and catastrophically wrong when the producer's complete frame was itself the stale one (a producer that completed branch B and then flushed branch A's appends — symmetric race, opposite winner). The consumer cannot tell which side of the race it is on from frame content alone. ## Operational Effect The practical consequence is that **speculative streaming shifts a verification obligation from the producer to the consumer, and A2A v1.0's optional branch token makes that obligation unfulfillable by default.** Teams that deploy speculative producers without branch tokens observe a low-rate, high-severity class of incident: artifacts that pass schema validation, pass fluency checks, pass even LLM-judge review, and fail only against the producer's own digest — and because the digest mismatch is indistinguishable from transport corruption, the incident is misclassified as a flaky stream and retried rather than root-caused. Over a fleet, this manifests as a background rate of "artifact re-derivation produced different content under the same task_id," which erodes the assumption that `task_id` names a deterministic artifact and breaks idempotent replay in any auditor that keys on it. The guardrail that bounds it: negotiate `require_branch_tokens: true` at capability handshake; treat untagged post-complete appends as a hard reconciliation fault, not a soft warning; scope digests to `0..final_seq` of the finalized branch; and never let a `UNVERIFIED` artifact feed an irreversible downstream action without re-request in non-streaming mode. The invariant to encode in the consumer is the one the wire does not give you: *completeness is per-branch, and a complete frame is a fence around a branch, not around an artifact_id.* ``` ```python import hashlib from dataclasses import dataclass, field from typing import Optional class ArtifactReconciliationError(RuntimeError): """Raised when a post-complete append cannot be proven stale (untagged) or when the finalized digest does not cover the finalized branch.""" pass @dataclass class Append: seq: int data: str branch_token: Optional[str] @dataclass class Complete: final_seq: int digest: str branch_token: Optional[str] @dataclass class ArtifactAssembler: artifact_id: str appends: list = field(default_factory=list) finalized_branch: Optional[str] = None finalized_seq: Optional[int] = None finalized_digest: Optional[str] = None contamination_risk: Optional[str] = None def on_append(self, a: Append) -> None: if self.finalized_seq is not None: # Post-complete append. Boundary case. if a.branch_token is not None and a.branch_token != self.finalized_branch: return # proven stale, discard if a.branch_token is not None and a.branch_token == self.finalized_branch: # Same branch re-opened after complete: producer bug, not # a legitimate continuation. Refuse to extend. raise ArtifactReconciliationError( f"append seq={a.seq} re-opens finalized branch " f"{self.finalized_branch!r} for {self.artifact_id}" ) # Untagged post-complete append: cannot prove staleness. self.contamination_risk = "untagged_post_complete" raise ArtifactReconciliationError( f"untagged append seq={a.seq} after complete for " f"{self.artifact_id}; cannot prove stale, refusing to splice" ) self.appends.append(a) def on_complete(self, c: Complete) -> None: if self.finalized_seq is not None: raise ArtifactReconciliationError( f"duplicate complete for {self.artifact_id}" ) # final_seq is authoritative; observed appends beyond it are suspect. kept = [a for a in self.appends if a.seq <= c.final_seq] if c.branch_token is not None: kept = [a for a in kept if a.branch_token in (None, c.branch_token)] body = "".join(a.data for a in sorted(kept, key=lambda x: x.seq)) actual = "sha256:" + hashlib.sha256(body.encode()).hexdigest() if actual != c.digest: raise ArtifactReconciliationError( f"digest mismatch for {self.artifact_id}: " f"declared {c.digest}, computed {actual} over " f"appends 0..{c.final_seq}" ) self.finalized_branch = c.branch_token self.finalized_seq = c.final_seq self.finalized_digest = c.digest self.appends = kept def is_load_bearing_safe(self) -> bool: if self.finalized_seq is None: raise ArtifactReconciliationError("not finalized") if self.contamination_risk is not None: return False return True ```