# What happens when an instance trusts a cached Agent Card across a task lifecycle transition and the remote peer's artifact MIME schema has silently drifted **Date of Record:** 2026 November 28 **Scope:** Applies to A2A v1.0 task lifecycles where a client agent reuses a previously discovered `AgentCard` (and its declared `defaultInputModes`/`defaultOutputModes`/artifact schema) to negotiate artifacts across `working → completed` transitions without re-fetching. Does not apply to single-shot `message/send` calls that terminate in one turn, nor to peers that pin card versions via ETag and reject stale `If-None-Match`. ## Core Distinction The failure is not "the remote agent returned the wrong MIME type." It is that the **Agent Card is a discovery-time snapshot, but artifact negotiation is a completion-time event**, and A2A v1.0 permits a peer to change the concrete `Part` media type of a `Task.artifacts[]` entry between the moment the card was cached and the moment the task reaches `completed`, provided the new type remains *a member of the declared `outputModes` set*. A client that treats the cached card's `outputModes` as a closed contract—rather than as a capability envelope the peer may narrow or reorder per-task—will accept a `Part` whose schema it cannot deserialize, and will fail *after* the task is already terminal and unmutable. The invariant that breaks: **card-level capability ≠ task-level artifact commitment.** The card says what the peer *can* emit; it does not say what it *will* emit for this task. The gap between those two is where the failure lives. ## What Was Observed A three-agent pipeline: a planner client (`C`), a remote analysis agent (`R`), and a downstream renderer (`D`). At `t0`, `C` fetched `R`'s card via `agent/authenticatedExtendedCard` and cached it: ``` AgentCard.skills[0].outputModes = ["application/json", "text/markdown"] AgentCard.capabilities.stateTransitionHistory = true ``` `C` dispatched a long-running task with `message/send`, received a `Task` in state `submitted`, then polled `tasks/get`. At `t1` the task entered `working`. At `t2`, ~40s later, `R` (a model-backed agent) decided mid-execution—based on a probabilistic classification of its own intermediate output—that the result was better expressed as `text/markdown` than `application/json`. It emitted: ``` Task.status.state = "completed" Task.artifacts = [{ artifactId: "a1", parts: [{ kind: "text", metadata: { mimeType: "text/markdown" } }] }] ``` `C` had no `text/markdown` deserializer wired for this skill because its *dispatch-time* contract—derived from the cached card and from the input schema it sent—assumed `application/json`. It raised a deserialization error, marked the task failed locally, and **re-dispatched the same task**. `R`, being non-deterministic, this time returned `application/json`. `C` now held two terminal artifacts for one logical task and no way to reconcile them: the A2A `Task.id` differed, and `contextId` matching was the only correlation key available. The deeper observation: the `completed` state is terminal and the artifact set is frozen, but the *interpretation* of the artifact depends on a card that may no longer match. There is no protocol-level signal that the card changed. `stateTransitionHistory` returned the state timeline but not the *negotiation* timeline. ## Condition of Validity This failure requires all of the following to co-occur; remove any one and the trace does not fire: 1. **Card caching without revalidation.** `C` did not re-fetch the card or send `If-None-Match` on the cached ETag before reading the terminal artifact. 2. **Multi-valued `outputModes`.** If the skill declared exactly one output mode, the peer could not legally drift. Ambiguity in the declared set is the precondition for silent selection. 3. **Model-mediated mode selection.** The peer chose the concrete `Part` type via probabilistic reasoning over its own output, not via a deterministic function of the request. A rule-based peer that echoes `C`'s requested mode cannot drift. 4. **Terminal-state artifact immutability.** Once `completed`, A2A v1.0 forbids the peer from amending `artifacts[]`. The client cannot ask the peer to "re-emit as JSON" within the same task; it must re-dispatch, which introduces the duplicate-terminal-artifact hazard. 5. **No idempotency key on dispatch.** `C`'s re-dispatch did not carry a client-generated dedup key in `metadata`, so `R` treated it as a fresh task. The condition is *valid* (the system behaved per spec) and *broken* (the client's contract assumption was false). That is the boundary: spec-compliant behavior that violates a reasonable client invariant. ## Decision Boundary The client must choose, at the moment it reads a terminal artifact, between two policies: - **Trust-the-card:** deserialize strictly against the cached `outputModes` and fail closed on mismatch. Cheap, but converts a benign peer choice into a client-side task failure and a re-dispatch loop. - **Trust-the-artifact:** deserialize against the `Part.metadata.mimeType` actually present, and treat the cached card as a *hint* for pre-dispatch validation only. Accepts the artifact, but requires the client to carry deserializers for the *union* of all declared modes, not the intersection it planned for. The correct boundary is asymmetric: **use the card to validate inputs and to pre-provision deserializers at dispatch time; use the artifact's own declared type to validate at completion time; never let the completion-time check reference the dispatch-time card as authority.** The card is a *capability advertisement*, the artifact is a *commitment*, and the commitment wins. A secondary boundary: on mismatch, do **not** re-dispatch blindly. Re-dispatch is only safe if the client mints a stable `contextId`-scoped idempotency key and the peer honors it (which A2A v1.0 does not mandate). Absent that guarantee, the client must either (a) accept the artifact under a permissive deserializer, or (b) fail the task *without* re-dispatch and surface the mismatch to a human/auditor, because re-dispatch is non-idempotent against a non-deterministic peer. ## Operational Effect The observable effect is a **duplicate-terminal-artifact divergence**: one logical task, two terminal `Task` records with different `Task.id`, different artifact media types, and no protocol-level reconciliation. Downstream `D` receives two artifacts for one intent. If `D` is itself an LLM agent, it will attempt to reconcile them probabilistically and may synthesize a third, hallucinated merge. The failure compounds across the swarm because each hop re-derives its contract from a card that was cached at a different time. The guardrail that bounds it: **pin the artifact contract at dispatch, not at discovery.** At dispatch, the client records the *exact* `outputModes` it is prepared to accept for this task (a subset of the card's declared set), transmits that subset in the request `metadata` as a requested-mode constraint, and at completion validates the artifact's `Part.metadata.mimeType` against that *dispatch-pinned* subset—not the cached card. If the peer returns a type outside the pinned subset, the client fails the task *once*, records the card-version hash and the offending `mimeType`, and refuses to re-dispatch until the card is re-fetched and the pin is recomputed. This converts a silent, compounding divergence into a single, attributable, non-retrying failure. The invariant to enforce in code: **a terminal artifact may only be deserialized against a contract that was fixed at dispatch time and whose card-version hash is still current at completion time.** Any read of the card between dispatch and completion is a stale-read hazard. ```python import hashlib from dataclasses import dataclass, field from typing import Optional class ArtifactNegotiationDrift(RuntimeError): """Raised when a terminal artifact's media type falls outside the dispatch-pinned output-mode subset, or when the cached AgentCard version changed between dispatch and completion.""" pass @dataclass class DispatchPin: task_context_id: str card_version_hash: str accepted_mime_types: frozenset[str] idempotency_key: str def _hash_card(card: dict) -> str: # Canonical hash of the capability envelope we actually relied on. payload = repr(sorted((card.get("skills") or [{}])[0].get("outputModes", []))).encode() return hashlib.sha256(payload).hexdigest() def pin_contract(card: dict, requested_modes: list[str], context_id: str) -> DispatchPin: declared = set((card.get("skills") or [{}])[0].get("outputModes", [])) accepted = declared.intersection(requested_modes) if not accepted: raise ArtifactNegotiationDrift( f"requested modes {requested_modes} disjoint from declared {declared}" ) return DispatchPin( task_context_id=context_id, card_version_hash=_hash_card(card), accepted_mime_types=frozenset(accepted), idempotency_key=hashlib.sha256(context_id.encode()).hexdigest(), ) def validate_terminal_artifact( pin: DispatchPin, current_card: dict, artifact_part: dict, task_state: str, ) -> None: if task_state != "completed": return # only terminal artifacts are frozen and validated here if _hash_card(current_card) != pin.card_version_hash: # Card drifted mid-flight; the pin is no longer anchored to a live card. raise ArtifactNegotiationDrift( f"card version changed between dispatch and completion for " f"context {pin.task_context_id}; refusing to trust artifact" ) mime = (artifact_part.get("metadata") or {}).get("mimeType") if mime not in pin.accepted_mime_types: # Peer selected a declared-but-unpinned mode; do NOT re-dispatch. raise ArtifactNegotiationDrift( f"artifact mimeType {mime!r} outside dispatch-pinned subset " f"{sorted(pin.accepted_mime_types)} for context {pin.task_context_id}" ) ```