# What happens when an instance negotiates an A2A task against a stale agent card and the artifact stream outlives the task state machine **Date of Record:** 2026 November 28 **Scope:** Applies to A2A v1.0 task lifecycle negotiation where a client agent discovers a remote agent via agent card, opens a streaming task (`tasks/sendSubscribe`), and the remote emits artifacts over SSE while a separate push-notification channel mirrors state. Does not cover synchronous `tasks/send` request/response, nor A2A versions lacking `artifact` delta semantics. ## Core Distinction The A2A task lifecycle treats the **task state machine** (`submitted → working → input-required → completed/failed/canceled`) and the **artifact stream** as two channels that are *causally ordered but not synchronously coupled*. A task can transition to a terminal state in the authoritative state store while artifact chunks for that same task are still in flight on the SSE transport, and—critically—while a push-notification webhook for a *later* event of the same task is being delivered to a callback URL the client no longer owns. The invariant operators assume ("terminal state implies no further artifacts for that task") is **not** an A2A v1.0 guarantee. It is only true if the client pins the agent card version it negotiated against and the server honors artifact-to-task binding across the full stream lifetime. The non-obvious failure: **agent card discovery is a point-in-time read, but the task stream is a long-lived subscription.** When the remote agent's card is re-published mid-stream (capability change, endpoint rotation, `pushNotifications` flag flip), a client that re-reads the card to decide how to interpret a late artifact will apply *new* capability semantics to *old* stream frames. The result is a silent artifact drop, not an error. ## What Was Observed A client orchestrator (`orchestrator-a`) discovered `remote-summarizer` via `GET /.well-known/agent.json`, caching the card with `capabilities.streaming: true`, `capabilities.pushNotifications: true`, and `skills[0].id: "summarize-v2"`. It opened `tasks/sendSubscribe` with `taskId: t-7741`. Sequence observed on the wire: 1. `t-7741` emits `status-update` → `working`. 2. Three `artifact-update` frames arrive with `append: true`, `lastChunk: false`, `artifactId: art-1`. 3. The remote operator deploys a new card: `skills[0].id` becomes `summarize-v3`, `capabilities.pushNotifications` flips to `false` (webhook backend decommissioned), and the `defaultInputModes` change. 4. The remote emits `status-update` → `completed` for `t-7741`. 5. The final `artifact-update` frame for `art-1` (`lastChunk: true`) arrives **after** the terminal status frame, 340 ms later, because the artifact serializer and the status serializer are separate goroutines on the server. 6. `orchestrator-a`'s stream handler, on receiving the post-terminal artifact, calls `revalidateCard()` (a defensive check added after a prior incident), gets `summarize-v3` with `pushNotifications: false`, and rejects the frame under a rule that says "artifacts from a task whose negotiated card no longer advertises streaming for this skill must be discarded." 7. `art-1` is dropped. The task is `completed` in the store, but the client's assembled artifact is truncated by one chunk. No exception is raised; the client logs `artifact_orphaned` at DEBUG. The push-notification channel independently failed: `orchestrator-a` had registered a webhook at `tasks/pushNotification/set` before the card flip. Post-flip, the remote's push dispatcher rejected delivery (backend decommissioned) and, per spec ambiguity, **did not surface a `pushNotificationNotSupported` error to the client** because the task was already terminal. The client's webhook receiver never learned the task had completed out-of-band; it only learned via the SSE terminal frame, which it had already processed. ## Condition of Validity The failure requires all of the following to hold simultaneously: - **Card re-publication during an open stream.** If the card is immutable for the stream's lifetime, step 3 cannot occur and the revalidation in step 6 returns the same card. - **Artifact/status serializer decoupling.** If the server guarantees artifact frames are flushed before the terminal status frame (a common but non-mandated implementation choice), step 5 cannot occur. - **Client-side card revalidation on late frames.** A client that pins the negotiated card (snapshot at `sendSubscribe` time) and never re-reads mid-stream is immune, because it applies old semantics to old frames consistently. - **Push channel registered against a capability that later disappears.** If the client had not registered a webhook, or had registered after the flip, the push-side failure would be a clean `pushNotificationNotSupported` at registration time. The invariant that actually holds in A2A v1.0 is weaker than operators assume: > *For a given `taskId`, the server MUST NOT emit artifact frames referencing an `artifactId` after emitting a terminal `status-update` for that task **if and only if** the server's transport guarantees in-order flush; the spec does not mandate in-order flush across the status and artifact serializers.* This is the boundary. The spec's normative language covers *what* frames mean, not *when* they are ordered relative to each other on a multiplexed SSE channel. ## Decision Boundary The client must choose between two policies at the moment it receives a frame whose validity depends on a card property that may have changed: 1. **Pin-and-trust.** Snapshot the agent card at `sendSubscribe` time. All frames for `taskId` are interpreted against that snapshot. Late artifacts are accepted under the pinned `streaming` capability. Card re-reads are permitted only for *new* tasks. This preserves artifact integrity but means a client can act on revoked capabilities for the duration of a long stream (potentially minutes). 2. **Revalidate-and-drop.** Re-read the card on every frame whose semantics depend on capabilities. This is what `orchestrator-a` did, and it caused silent truncation because the revalidation raced the terminal transition. The correct boundary is a **hybrid with an explicit terminal fence**: pin the card for the stream, but maintain a `terminalFence` timestamp set when the terminal status frame is observed. Artifact frames arriving *after* the fence are accepted **only** if they carry `lastChunk: true` and reference an `artifactId` already seen, and they are accepted under the **pinned** card, never the live card. Frames arriving after the fence that introduce a *new* `artifactId` are rejected with a hard error, because those indicate a server bug (artifact emitted for a task already terminal without prior chunks). The push-notification side needs a separate fence: the client must treat `pushNotifications` capability as pinned at registration time, and must not interpret the absence of a webhook delivery as evidence the task is incomplete. The SSE terminal frame is authoritative; the webhook is advisory. ## Operational Effect Without the fence, the observed effect is **silent artifact truncation correlated with card re-publication timing**. The client's assembled output is missing the final chunk, but the task is `completed`, the artifact hash in the terminal frame's `metadata` (if present) does not match the assembled bytes, and no error is raised because artifact-hash verification is not a required A2A v1.0 step. Downstream consumers receive a truncated summary with a `completed` status and trust it. The second-order effect is **push/stream divergence**: the client's webhook receiver and its SSE handler maintain separate views of task completion. If the client uses the webhook to update a shared task store and the SSE handler to update a per-stream buffer, the store can record `completed` before the buffer is flushed, and a crash between the two leaves the store consistent but the buffer truncated—a checkpoint/resume hazard that only manifests when the process restarts mid-stream. The guardrail is a **terminal fence with pinned-card semantics and mandatory artifact-hash verification**: - Snapshot the agent card at `sendSubscribe`; store `cardVersion` (the card's `version` field or an ETag) alongside `taskId`. - On terminal status frame, set `terminalFence = now()` and record `expectedArtifacts` from the terminal frame's `artifacts` array (if present). - Accept post-fence artifact frames only if `artifactId ∈ expectedArtifacts` and `cardVersion` matches the pinned snapshot; otherwise raise. - Verify assembled artifact bytes against any hash in the terminal frame's `metadata`; on mismatch, raise. - Treat webhook deliveries as advisory; never use their absence to infer task state. - On resume after crash, re-fetch the card and compare `version` to the pinned `cardVersion`; if changed, do **not** resume the stream—re-open a new task, because the pinned semantics may no longer be honored. ```python import hashlib import time from dataclasses import dataclass, field from typing import Dict, List, Optional class A2AStreamContractViolation(RuntimeError): """Raised when an A2A artifact/status frame violates the pinned-card terminal fence contract.""" @dataclass class PinnedCard: version: str streaming: bool push_notifications: bool skill_ids: List[str] @dataclass class TaskStreamState: task_id: str pinned_card: PinnedCard terminal_fence_at: Optional[float] = None expected_artifacts: Dict[str, str] = field(default_factory=dict) # artifactId -> expected sha256 assembled: Dict[str, bytearray] = field(default_factory=dict) seen_artifacts: set = field(default_factory=set) def on_artifact_frame(state: TaskStreamState, frame: dict) -> None: artifact_id = frame["artifactId"] chunk = frame["chunk"].encode() is_last = frame.get("lastChunk", False) if state.terminal_fence_at is not None: # Post-terminal frame: only allowed if it closes an artifact we already saw # and was declared in the terminal frame's expected set, under the PINNED card. if artifact_id not in state.seen_artifacts: raise A2AStreamContractViolation( f"post-terminal artifact {artifact_id} for task {state.task_id} " f"introduces a new artifactId; server violated artifact-to-task binding" ) if artifact_id not in state.expected_artifacts: raise A2AStreamContractViolation( f"post-terminal artifact {artifact_id} not declared in terminal frame " f"for task {state.task_id}; cannot verify under pinned card {state.pinned_card.version}" ) if not state.pinned_card.streaming: raise A2AStreamContractViolation( f"pinned card {state.pinned_card.version} does not advertise streaming; " f"refusing post-terminal artifact {artifact_id}" ) state.seen_artifacts.add(artifact_id) state.assembled.setdefault(artifact_id, bytearray()).extend(chunk) if is_last and artifact_id in state.expected_artifacts: digest = hashlib.sha256(bytes(state.assembled[artifact_id])).hexdigest() if digest != state.expected_artifacts[artifact_id]: raise A2AStreamContractViolation( f"artifact {artifact_id} hash mismatch for task {state.task_id}: " f"assembled {digest} != expected {state.expected_artifacts[artifact_id]}" ) def on_terminal_status_frame(state: TaskStreamState, frame: dict) -> None: if frame["state"] not in ("completed", "failed", "canceled"): raise A2AStreamContractViolation(f"non-terminal state {frame['state']} passed to terminal handler") state.terminal_fence_at = time.monotonic() for art in frame.get("artifacts", []): if "sha256" in art.get("metadata", {}): state.expected_artifacts[art["artifactId"]] = art["metadata"]["sha256"] def on_resume(state: TaskStreamState, live_card: PinnedCard) -> None: if live_card.version != state.pinned_card.version: raise A2AStreamContractViolation( f"cannot resume task {state.task_id}: pinned card {state.pinned_card.version} " f"no longer matches live card {live_card.version}; re-open task under new semantics" ) ```