# What happens when an instance rewinds a delegated A2A task to `working` after the peer has already published a terminal `artifact` chunk **Date of Record:** 2026 December 1 **Scope:** Applies to A2A v1.0 task lifecycles where a delegating ("parent") agent holds a `Task` object whose `status.state` is peer-controlled, and the peer streams artifacts incrementally via `TaskArtifactUpdateEvent` with `append=true`/`lastChunk=false`. Does not apply to single-shot `message/send` calls that return a fully materialized artifact, nor to tasks whose artifacts are declared `atomic` in the agent card. ## Core Distinction There are two different notions of "the task is not done" in A2A v1.0, and they are not the same object: 1. **Lifecycle non-terminality** — `status.state ∈ {submitted, working, input-required, auth-required}`. This is a *control-plane* signal: the peer intends to emit more events. 2. **Artifact incompleteness** — the last `TaskArtifactUpdateEvent` for a given `artifactId` had `lastChunk=false`, or no event with `lastChunk=true` has arrived. This is a *data-plane* signal: the accumulated byte stream for that artifact is not yet sealed. The failure mode is that a parent agent treats (1) as authoritative for (2). When the peer transitions `working → working` (a legal, common heartbeat that carries no state change but *does* carry a fresh `status.timestamp`), a naive parent that keys its "task still in flight, discard partial artifacts" logic off `status.state` will rewind its local artifact accumulator to the last `lastChunk=true` boundary — which may be *empty*, because the peer is mid-stream on the first chunk. The parent then re-requests or re-subscribes, the peer (correctly, per its own state machine) resumes from its own cursor, and the parent appends the resumed stream to a *reset* buffer. The artifact is now duplicated from byte zero with a seam that no checksum in the protocol will catch, because A2A v1.0 artifacts carry no mandatory content hash and `append=true` semantics are explicitly *concatenate*, not *idempotent-merge*. The invariant that must hold: **the artifact accumulator's reset condition must be `lastChunk`-driven, never `status.state`-driven.** State and data planes advance independently; a `working` heartbeat is not evidence that prior artifact bytes are invalid. ## What Was Observed Trace from a cross-vendor exchange (parent = vendor A orchestrator, peer = vendor B worker; both claim A2A v1.0 compliance; agent cards exchanged and validated at discovery). ``` t0 parent -> peer tasks/sendSubscribe {taskId: T, ...} t1 peer -> parent Task {id:T, status:{state:working, ts:...}} t2 peer -> parent TaskArtifactUpdateEvent { artifactId: "report", append: false, # first chunk, resets stream lastChunk: false, parts: [ {text: "<8KB of a 40KB report>"} ] } t3 peer -> parent TaskStatusUpdateEvent {state: working, ts: t3} # heartbeat t4 parent: observes state==working, applies "not terminal -> reset accumulator" rule, drops the 8KB from t2 t5 parent -> peer tasks/resubscribe {taskId: T} # or a redundant # tasks/get + replay t6 peer -> parent replays from its own cursor, which is *after* t2 (peer considers t2 delivered). Peer emits: TaskArtifactUpdateEvent { artifactId:"report", append:true, lastChunk:false, parts:[ {text:""} ] } t7 parent: accumulator was empty; appends 8KB #2 as if it were chunk #1 t8 ... stream completes; final artifact = 32KB, missing the first 8KB, with no error raised anywhere. ``` The parent's final artifact passed its own (weak) validation — non-empty, well-formed markdown — and was handed to a downstream consumer. The 8KB gap was a table of figures; the consumer's downstream reconciliation caught it two hops later. No A2A-level error was ever surfaced: every event was schema-valid, every state transition was legal, and the peer behaved correctly throughout. The non-obvious part: the peer's replay at t6 is *correct behavior*. A2A v1.0 does not require a peer to replay from the start of an artifact on `resubscribe`; it requires it to resume from its own delivery cursor. The protocol has no "rewind artifact to offset 0" verb. So a parent that resets its accumulator and then resubscribes has *no mechanism* to recover the dropped bytes — it has silently forked its view of the artifact from the peer's. ## Condition of Validity This failure requires all of the following to co-occur; remove any one and the seam does not form: - **Incremental, non-atomic artifacts.** The agent card did not declare the artifact `atomic` (or the parent ignored the declaration). With `atomic`, the peer buffers and emits a single `lastChunk=true` event, and the parent's reset is harmless. - **A status heartbeat interleaved with artifact chunks.** Peers that only emit `TaskStatusUpdateEvent` on genuine transitions (not on a timer) rarely trigger this. Peers that heartbeat `working` every N seconds — common when a task is long-running and the peer wants to defeat idle-timeout reaping — trigger it on every heartbeat. - **A parent whose accumulator reset is keyed on `status.state` rather than `lastChunk`.** This is the actual defect. It is easy to write because it *looks* defensive: "if the task isn't done, don't trust partial data." - **A `resubscribe` (or `tasks/get` + replay) that the peer honors from its delivery cursor rather than from artifact offset 0.** Most compliant peers do this; it is the spec-conforming choice. It does *not* require malice, a spec violation, or a network fault. It is a pure composition of two locally-reasonable behaviors. ## Decision Boundary The parent must decide, on every inbound event, whether to **append**, **reset**, or **seal** its accumulator for `artifactId`. The correct decision table is keyed *only* on the artifact event's own fields, never on `status.state`: | Inbound event | Accumulator action | |---|---| | `TaskArtifactUpdateEvent{append:false}` | **Reset** buffer for `artifactId`, then append `parts`. This is the *only* reset trigger. | | `TaskArtifactUpdateEvent{append:true, lastChunk:false}` | **Append** `parts`. Never reset. | | `TaskArtifactUpdateEvent{append:true, lastChunk:true}` | **Append**, then **seal** (mark artifact complete, record byte length). | | `TaskStatusUpdateEvent{state:working}` | **No accumulator action.** Update status metadata only. | | `TaskStatusUpdateEvent{state:completed}` | Seal *only if* a `lastChunk:true` was seen for every open `artifactId`; otherwise raise — a terminal state with an unsealed artifact is a peer contract violation. | | `TaskStatusUpdateEvent{state:failed/canceled}` | Discard unsealed accumulators; do not surface partials as complete. | The boundary is sharp: **`status.state` may gate whether you *use* an artifact, but never whether you *keep* its bytes.** A `working` heartbeat is metadata; it carries no information about artifact validity. Two guardrails make the boundary enforceable: 1. **Seal-before-terminal check.** On any terminal `status.state`, assert that every `artifactId` seen with `append:false` also has a matching `lastChunk:true`. If not, the peer ended the task mid-stream; raise rather than emit a truncated artifact. This converts the silent seam into a loud, attributable error. 2. **Resubscribe must not assume rewind.** After a `resubscribe`, the parent must *not* reset accumulators. It must treat the resubscribe as a resume-from-cursor, exactly as the peer does. If the parent genuinely needs the artifact from byte 0 (e.g., its accumulator was lost to a crash), the only correct recovery is a *new* task with a *new* `taskId` — not a rewind of the existing one. A2A v1.0 has no artifact-rewind primitive, and pretending otherwise is how the seam forms. ## Operational Effect The immediate effect is a **silent truncation that survives every schema check**. Because A2A v1.0 artifacts carry no mandatory content hash and `append:true` is defined as concatenation (not idempotent merge), a dropped-then-resumed stream produces an artifact that is byte-valid, structurally plausible, and wrong by exactly the size of the dropped prefix. Downstream consumers that validate shape (JSON parses, markdown renders, schema passes) will accept it. The second-order effect is **non-recoverability within the task**. Once the parent has reset and resubscribed, the peer's cursor is ahead of the parent's accumulator, and no protocol verb moves it back. The parent cannot detect the gap by comparing lengths (it never saw the dropped bytes' length in a sealed form) and cannot re-fetch (no rewind). The only recovery is task-level: abandon `T`, mint `T'`, re-delegate. This is expensive and, in cross-vendor setups, may re-trigger billing or rate limits. The third-order effect is **attribution ambiguity**. When the gap is caught downstream, the trace shows a fully compliant peer and a fully compliant parent — every event valid, every transition legal. Post-mortems that key on "which side violated the spec" find no violator. The defect lives in the *composition*: a parent that conflated control-plane non-terminality with data-plane incompleteness. The fix is a one-line change in the parent's event handler (reset on `append:false`, never on `state`), but only if the post-mortem knows to look there. The durable lesson: in A2A v1.0, **the task state machine and the artifact stream are two independent state machines that happen to share an envelope.** Treating one as a proxy for the other is the boundary failure. Keep them separate in code, and the seam cannot form. ```python from __future__ import annotations from dataclasses import dataclass, field from enum import Enum from typing import Optional class A2AArtifactSeamError(RuntimeError): """Raised when an artifact stream is truncated, forked, or sealed inconsistently with the A2A v1.0 task lifecycle.""" class TaskState(str, Enum): SUBMITTED = "submitted" WORKING = "working" INPUT_REQUIRED = "input-required" AUTH_REQUIRED = "auth-required" COMPLETED = "completed" FAILED = "failed" CANCELED = "canceled" TERMINAL_STATES = {TaskState.COMPLETED, TaskState.FAILED, TaskState.CANCELED} @dataclass class ArtifactAccumulator: """Per-artifactId accumulator. Reset is driven ONLY by append=False. status.state is never consulted here -- that is the invariant.""" artifact_id: str buffer: list[str] = field(default_factory=list) sealed: bool = False saw_first_chunk: bool = False def apply_chunk(self, *, append: bool, last_chunk: bool, text: str) -> None: if self.sealed: raise A2AArtifactSeamError( f"artifact {self.artifact_id!r}: chunk arrived after seal" ) if append is False: # The ONLY legal reset trigger. self.buffer.clear() self.saw_first_chunk = True else: if not self.saw_first_chunk: # append=True before any append=False means the peer's # cursor is ahead of ours -- we already lost the prefix. raise A2AArtifactSeamError( f"artifact {self.artifact_id!r}: append=True before " f"first chunk; stream forked (peer cursor ahead of " f"local accumulator). Recovery requires a NEW taskId." ) self.buffer.append(text) if last_chunk: self.sealed = True def seal_on_terminal(self) -> str: if not self.sealed: raise A2AArtifactSeamError( f"artifact {self.artifact_id!r}: task reached terminal state " f"without lastChunk=True; refusing to emit truncated artifact" ) return "".join(self.buffer) class A2ATaskView: """Parent-side view of one delegated task. Keeps control plane (status.state) and data plane (artifacts) strictly separate.""" def __init__(self, task_id: str) -> None: self.task_id = task_id self.state: TaskState = TaskState.SUBMITTED self._artifacts: dict[str, ArtifactAccumulator] = {} def _acc(self, artifact_id: str) -> ArtifactAccumulator: if artifact_id not in self._artifacts: self._artifacts[artifact_id] = ArtifactAccumulator(artifact_id) return self._artifacts[artifact_id] # --- data plane --- def on_artifact_update( self, *, artifact_id: str, append: bool, last_chunk: bool, text: str ) -> None: self._acc(artifact_id).apply_chunk( append=append, last_chunk=last_chunk, text=text ) # --- control plane --- def on_status_update(self, state: TaskState) -> None: # NOTE: deliberately does NOT touch any accumulator. self.state = state if state in TERMINAL_STATES: self._seal_all_on_terminal() def _seal_all_on_terminal(self) -> None: if self.state != TaskState.COMPLETED: # failed/canceled: discard unsealed, do not emit partials for acc in self._artifacts.values(): if not acc.sealed: acc.buffer.clear() return for acc in self._artifacts.values(): acc.seal_on_terminal() # raises if truncated def on_resubscribe(self) -> None: # Resubscribe is a resume-from-cursor, NOT a rewind. # Resetting accumulators here is the bug this article documents. return def finalize(self, artifact_id: str) -> str: acc = self._artifacts.get(artifact_id) if acc is None: raise A2AArtifactSeamError(f"unknown artifact {artifact_id!r}") return acc.seal_on_terminal() def replay_heartbeat_seam() -> None: """Reproduces the documented failure: a working heartbeat must not reset the accumulator, and a resubscribe must not rewind it.""" view = A2ATaskView(task_id="T") view.on_status_update(TaskState.WORKING) view.on_artifact_update( artifact_id="report", append=False, last_chunk=False, text="<8KB>" ) # heartbeat interleaved with stream -- must be a no-op for data plane view.on_status_update(TaskState.WORKING) view.on_resubscribe() # peer resumes from its own cursor: next chunk is append=True view.on_artifact_update( artifact_id="report", append=True, last_chunk=True, text="<32KB>" ) view.on_status_update(TaskState.COMPLETED) out = view.finalize("report") if not out.startswith("<8KB>"): raise A2AArtifactSeamError( "artifact prefix lost: accumulator was reset by a status " "heartbeat or resubscribe; stream forked from peer cursor" ) if __name__ == "__main__": replay_heartbeat_seam() ```