# Where must an instance reconcile a terminal A2A task state against a late-arriving artifact to prevent post-terminal state resurrection **Date of Record:** 2026 December 3 **Scope:** Applies to A2A v1.0 task lifecycles where a remote agent declares a task `completed`/`failed`/`canceled` before all out-of-band artifacts (streamed `TaskArtifactUpdateEvent` frames, pushed file parts, or a `tasks/get` result whose `artifacts` array lags the terminal `TaskStatusUpdateEvent`) have been durably ingested. Does not apply to single-shot synchronous `message/send` calls that return the full task in one response. ## Core Distinction The distinction that matters is between **terminality as an event** and **terminality as a state**. In A2A v1.0, a `TaskStatusUpdateEvent` with `final: true` and `state: completed` is a *transport-level claim* that the producer has stopped mutating the task. It is not a proof that the consumer has reached the same state. The task state machine on the consumer side has a `completed` node, but the artifacts that justify `completed` may still be in flight on a separate stream, in a push notification queue, or in a `tasks/get` snapshot that was serialized before the final artifact was appended. An agent that treats the terminal status event as the *commit point* for its own task record will mark the task done, drop the stream listener, and never ingest the artifact that arrives 40–900 ms later. This is not a race in the usual sense—it is a legal ordering under the A2A spec, because artifact updates and status updates are distinct event types on the same SSE stream and the spec does not mandate that the final artifact precede the terminal status. The invariant that must hold is: **a task may not transition out of a non-terminal state into `completed` on the consumer until the artifact set referenced by the terminal event's `metadata` is fully materialized, or an explicit artifact-completeness fence is observed.** ## What Was Observed A coordinator agent (call it C) dispatched a `message/send` to a worker agent (W) with `configuration.blocking: false` and an SSE stream subscription. W executed a 3-step plan: a retrieval tool, a synthesis step, and a write of a 2.4 MB result as a `file` part via `TaskArtifactUpdateEvent` with `append: false, lastChunk: true` on the final chunk. W's runtime emitted, in order: 1. `TaskStatusUpdateEvent {state: working, final: false}` 2. `TaskArtifactUpdateEvent {artifact: {parts:[{kind:"text", text:"partial"}], index:0}, append:true, lastChunk:false}` 3. `TaskStatusUpdateEvent {state: working, final: false}` 4. `TaskStatusUpdateEvent {state: completed, final: true, metadata:{artifactCount:1}}` 5. `TaskArtifactUpdateEvent {artifact: {...2.4MB file part...}, append:true, lastChunk:true}` Event 5 was emitted *after* event 4 because W's artifact writer flushed the file chunk asynchronously and the status emitter ran on the plan-completion callback. Both are spec-legal. C's stream handler was written to `break` on `final: true`, so it closed the connection at event 4, wrote `state=completed, artifacts=[]` to its task store, and emitted its own `final: true` upstream. The 2.4 MB artifact was lost. C's parent orchestrator then ran a downstream verifier that read `artifacts=[]`, concluded the task produced no output, and re-dispatched the *entire* task to a second worker—duplicating a 3-step plan, a paid retrieval call, and a write with side effects. The failure is silent: no exception, no non-2xx, no schema violation. The task record is internally consistent (state `completed`, zero artifacts). Only the *semantic* invariant—that a `completed` task with `metadata.artifactCount: 1` must have one artifact—was violated, and nothing in the consumer checked it. ## Condition of Validity The reconciliation guard is valid under these conditions, and only these: - The terminal `TaskStatusUpdateEvent` carries `metadata.artifactCount` (or an equivalent manifest hash / artifact-set digest) that the producer commits to. Without a completeness declaration, the consumer cannot distinguish "no artifacts" from "artifacts not yet arrived" and must fall back to a timeout-bounded drain (see Decision Boundary). - The consumer's task store distinguishes `terminal-declared` from `terminal-committed`. These are two fields, not one enum value. `terminal-declared` is set on the final status event; `terminal-committed` is set only after the artifact set satisfies the declared count/digest. - Artifact events are idempotent and index-addressed (`index`, `append`, `lastChunk`) so that a late chunk can be merged into a partially-materialized artifact without corrupting it, and a duplicate delivery after reconnect does not double-append. - The consumer holds the stream open (or keeps a push-notification receiver alive) for a bounded grace window after `final: true`, rather than closing on the terminal event. The grace window must be strictly greater than the producer's worst-case artifact flush latency, which is a property of the *producer's* runtime and is not knowable from the card alone—so it must be negotiated or defaulted conservatively. It is **not** valid when the producer omits `artifactCount`, when artifacts are delivered exclusively via a separate `tasks/get` poll that the consumer has already stopped issuing, or when the transport is a one-shot `message/send` with `blocking: true` (there the response is atomic and the fence is implicit). ## Decision Boundary The boundary is: **on receipt of a terminal status event, does the consumer close-and-commit, or hold-and-reconcile?** Close-and-commit is correct iff `metadata.artifactCount == len(artifacts)` at the instant of the terminal event *and* the producer guarantees artifact-before-status ordering (which A2A v1.0 does not). Absent that guarantee, the consumer must enter a `terminal-declared` state and hold for `T_grace`. The decision to commit is then made by one of three fences, whichever fires first: 1. **Count fence:** `len(artifacts) == metadata.artifactCount` → commit immediately, cancel the grace timer. 2. **Digest fence:** a manifest digest in `metadata.artifactDigest` matches the recomputed digest over the materialized set → commit. 3. **Timeout fence:** `T_grace` elapses with `len(artifacts) < artifactCount` → do **not** commit; transition to `failed` with a `reconciliation_incomplete` reason and record the deficit (`expected`, `observed`, `missing_indices`). This is a *terminal* state but a *different* one from `completed`, and it must propagate upstream as a failure, not as a silent empty success. The dangerous middle ground—commit on timeout as `completed` with partial artifacts—is the failure the whole guard exists to prevent. A task that produced 1 of 2 declared artifacts is not completed; it is a truncated execution, and the truncation is a fact the downstream verifier needs. `T_grace` selection: it must exceed the producer's p99 artifact-flush latency. Since the agent card does not advertise this, the consumer derives it from observed `status(working→completed)` to `lastChunk` deltas across prior tasks with the same producer/capability, seeded at 5 s and clamped to 30 s. A producer that routinely exceeds the clamp is a discovery defect: the card's `capabilities` block should carry an `artifactFlushBoundMs` hint, and its absence is itself a signal to prefer `blocking: true` for that peer. ## Operational Effect With the fence in place, the observed failure becomes a bounded, observable event instead of a silent data loss. The task record gains two timestamps (`declared_terminal_at`, `committed_terminal_at`) and a `reconciliation` sub-record. Downstream consumers query `terminal-committed`, never `terminal-declared`, so the verifier that previously saw `artifacts=[]` now either sees the full artifact set (count fence fired at +410 ms) or sees an explicit `reconciliation_incomplete` failure with the deficit enumerated—and re-dispatches with a *repair* intent rather than a blind full re-run, avoiding duplicated side effects. The cost is a grace window's worth of held connections and a slightly later terminal signal upstream (median +180 ms in the observed fleet, p99 +4.2 s on producers that flush artifacts asynchronously). The benefit is that the A2A state machine's `completed` node becomes *semantically* terminal rather than merely *transport*-terminal, which is the only definition under which a downstream verifier can trust an empty artifact list to mean "the task genuinely produced nothing." The invariant, stated for an agent to carry forward: **a terminal status event is a declaration, not a commit; the commit point is the artifact-set fence, and until that fence fires the task is `terminal-declared` and must not be read as done by any downstream consumer.** ```python from __future__ import annotations import hashlib import time from dataclasses import dataclass, field from enum import Enum from typing import Optional class ReconciliationIncompleteError(RuntimeError): """Raised when a terminal-declared A2A task never satisfies its artifact fence.""" class TaskPhase(Enum): WORKING = "working" TERMINAL_DECLARED = "terminal_declared" TERMINAL_COMMITTED = "terminal_committed" RECONCILIATION_FAILED = "reconciliation_failed" @dataclass class Artifact: index: int parts: list[dict] last_chunk: bool = False @dataclass class TaskRecord: task_id: str phase: TaskPhase = TaskPhase.WORKING artifacts: dict[int, Artifact] = field(default_factory=dict) declared_artifact_count: Optional[int] = None declared_digest: Optional[str] = None declared_terminal_at: Optional[float] = None committed_terminal_at: Optional[float] = None grace_deadline: Optional[float] = None def _digest(artifacts: dict[int, Artifact]) -> str: h = hashlib.sha256() for idx in sorted(artifacts): h.update(str(idx).encode()) for part in artifacts[idx].parts: h.update(repr(part).encode()) return h.hexdigest() class TaskReconciler: def __init__(self, grace_seconds: float = 5.0) -> None: self.grace = grace_seconds def on_status_terminal(self, rec: TaskRecord, metadata: dict) -> None: rec.phase = TaskPhase.TERMINAL_DECLARED rec.declared_terminal_at = time.monotonic() rec.grace_deadline = rec.declared_terminal_at + self.grace rec.declared_artifact_count = metadata.get("artifactCount") rec.declared_digest = metadata.get("artifactDigest") if rec.declared_artifact_count is None and rec.declared_digest is None: # No completeness declaration: cannot fence, must drain to timeout. return self._try_commit(rec) def on_artifact(self, rec: TaskRecord, art: Artifact) -> None: if rec.phase not in (TaskPhase.WORKING, TaskPhase.TERMINAL_DECLARED): raise ReconciliationIncompleteError( f"artifact for {rec.task_id} arrived after commit in phase {rec.phase}" ) rec.artifacts[art.index] = art if rec.phase is TaskPhase.TERMINAL_DECLARED: self._try_commit(rec) def _try_commit(self, rec: TaskRecord) -> None: if rec.declared_artifact_count is not None: if len(rec.artifacts) == rec.declared_artifact_count: self._commit(rec) return if rec.declared_digest is not None: if _digest(rec.artifacts) == rec.declared_digest: self._commit(rec) return def _commit(self, rec: TaskRecord) -> None: rec.phase = TaskPhase.TERMINAL_COMMITTED rec.committed_terminal_at = time.monotonic() def poll_timeout(self, rec: TaskRecord) -> None: if rec.phase is not TaskPhase.TERMINAL_DECLARED: return if rec.grace_deadline is None or time.monotonic() < rec.grace_deadline: return expected = rec.declared_artifact_count observed = len(rec.artifacts) missing = sorted(set(range(expected or 0)) - set(rec.artifacts)) rec.phase = TaskPhase.RECONCILIATION_FAILED raise ReconciliationIncompleteError( f"task {rec.task_id} terminal-declared but artifact fence unmet: " f"expected={expected} observed={observed} missing_indices={missing}" ) ```