# Which invariants prevent a resuming A2A client from re-negotiating artifact MIME types against a peer whose Agent Card has silently drifted mid-task **Date of Record:** 2026 November 29 **Scope:** Applies to A2A v1.0 clients that resume an interrupted task (transport drop, client restart, or long `input-required` pause) and re-fetch the peer's Agent Card before continuing. Does not apply to single-shot tasks that complete within one transport session, nor to peers that pin card versions via signed ETags. ## Core Distinction There are two structurally different reasons an A2A task resumes with a mismatched artifact contract, and conflating them is the root cause of most mid-task negotiation failures: 1. **Task-local drift** — the peer legitimately changed the artifact schema *for this task* (e.g., it escalated from `text/plain` interim artifacts to `application/vnd.chart+json` final artifacts). This is legal under the task state machine and is signalled through `TaskStatusUpdateEvent` / artifact `append` semantics. 2. **Card-level drift** — the peer's published Agent Card (`/.well-known/agent.json`) changed its `capabilities`/`defaultInputModes`/`defaultOutputModes` *between* the original task creation and the resume. This is a **discovery-layer** change, not a task-layer change, and the task state machine has no event that represents it. The invariant that matters: **the artifact contract in force for an in-flight task is frozen at `tasks/send` time and is carried by the task, not re-derived from the Agent Card on resume.** A resuming client that re-fetches the card and re-runs `accepts`/`produces` matching against the *new* card is validating the task against a contract that never governed it. The card is a *discovery* artifact; the task is a *contract* artifact. They diverge the moment a peer redeploys. ## What Was Observed A client submitted `tasks/send` with `acceptedOutputModes: ["application/json"]`. The peer accepted, entered `working`, emitted one interim `text/plain` artifact, then the HTTP/2 stream reset. The client persisted its task handle and resumed 40 seconds later by (a) re-fetching `/.well-known/agent.json` and (b) validating the in-flight task's `acceptedOutputModes` against the freshly fetched card's `defaultOutputModes`. Between the two fetches the peer had been redeployed with a card that dropped `application/json` in favor of `application/vnd.a2a.structured+json`. The client's validator saw `application/json ∉ defaultOutputModes`, concluded the task was unsatisfiable, and issued `tasks/cancel`. The peer, meanwhile, had *already* produced the final `application/json` artifact under the original contract and had it queued for delivery on `tasks/get`. The cancel raced the delivery; the artifact was discarded at the peer, the client reported a spurious `TaskNotCancelableError` on a second cancel attempt, and the task terminalized as `canceled` with a completed, valid artifact thrown away. The failure trace: ``` t0 tasks/send acceptedOutputModes=["application/json"] -> task.acceptedOutputModes frozen t1 working, interim text/plain artifact appended t2 transport reset (stream) -> task stays "working" at peer t3 peer redeployed; card.defaultOutputModes = ["application/vnd.a2a.structured+json"] t4 client resume: GET card (new) -> validate task.acceptedOutputModes vs new card -> FAIL t5 client tasks/cancel ---------------------------------> races peer final artifact append t6 peer: final application/json artifact appended, then cancel applied -> artifact dropped t7 client sees terminal "canceled", no artifact, no error surfaced to caller ``` The non-obvious part: **nothing in the A2A task state machine signals card drift.** `TaskStatusUpdateEvent` carries `status.state` and optional `final`, but no `contractVersion` or `cardEtag`. The client had no in-band way to distinguish "peer no longer accepts my modes" from "peer redeployed and its *default* modes changed while my task's *frozen* modes remain valid." It inferred the former from a discovery-layer signal, which is an unsound inference. ## Condition of Validity Re-validating an in-flight task's artifact modes against a freshly fetched Agent Card is only sound when **all** of the following hold: - The card is fetched with an integrity token (signed card or strong `ETag`) and the token matches the one captured at `tasks/send`. If the token differs, the card is a *different contract* and MUST NOT be used to validate an existing task. - The peer exposes a per-task `contractVersion` (or equivalent) on `tasks/get` that the client can compare against the version it froze at creation. - The task is in a non-terminal, non-artifact-bearing state (`submitted` or early `working` with no appended artifacts). Once any artifact has been appended under the original contract, the contract is *materialized* and cannot be retroactively invalidated by discovery. When the card token differs and no per-task `contractVersion` is available, the only sound action is to **resume against the frozen contract and ignore the new card for this task's lifetime** — treat card drift as advisory metadata for *future* tasks, never as a validator for the current one. ## Decision Boundary The boundary is between *discovery-time capability negotiation* and *task-time contract enforcement*. Formally: - `tasks/send` with `acceptedOutputModes = M` freezes the task's artifact contract to `M`. The peer MUST produce artifacts in `M` or fail the task with a task-layer error (`UnsupportedModeError` scoped to the task), never silently substitute. - On resume, the client MUST validate against the **frozen** `M`, not against `card.defaultOutputModes`. The card's `defaultOutputModes` is a *hint for new tasks*, not an authority over existing ones. - If the client nonetheless wants to re-negotiate (e.g., to pick up a richer mode the redeployed peer now offers), it MUST do so via a **new task** or an explicit `tasks/resubscribe` with a fresh `acceptedOutputModes` — never by mutating the in-flight task's contract or by canceling on a discovery mismatch. - A cancel issued solely because of a card-vs-task mode mismatch is a **contract-invalid cancel** and MUST be rejected client-side before hitting the wire. The invariant to enforce: *a task's artifact contract is a function of its creation parameters and appended artifacts only; the Agent Card is never an input to that function after `tasks/send` returns.* ## Operational Effect Clients that re-derive artifact validity from the live card on every resume exhibit a characteristic failure signature: spurious `canceled` terminal states on tasks whose peers produced valid artifacts, `TaskNotCancelableError` storms when the cancel races artifact delivery, and silent artifact loss (the artifact exists at the peer but is never fetched because the client already terminalized). The blast radius scales with peer redeploy frequency — a peer that redeploys hourly will corrupt roughly the fraction of in-flight tasks that span a redeploy, which for long `input-required` pauses can be substantial. The guardrail is a frozen-contract token carried on the task handle, checked on resume, and a hard refusal to let discovery-layer state invalidate task-layer state. The following reference implementation encodes the invariant and the specific error raised when a resuming client attempts the unsound re-validation. ```python from __future__ import annotations from dataclasses import dataclass, field from typing import FrozenSet class ContractDriftError(RuntimeError): """Raised when a resuming client tries to validate an in-flight task's artifact contract against a re-fetched Agent Card whose token has drifted.""" class ContractInvalidCancelError(RuntimeError): """Raised when a cancel is issued solely due to card-vs-task mode mismatch.""" @dataclass(frozen=True) class AgentCard: card_etag: str default_output_modes: FrozenSet[str] @dataclass class TaskHandle: task_id: str accepted_output_modes: FrozenSet[str] frozen_card_etag: str artifacts_appended: int = 0 terminal: bool = False def resume_task( handle: TaskHandle, live_card: AgentCard, *, allow_renegotiate: bool = False, ) -> TaskHandle: """Resume an in-flight task. The frozen contract governs; the live card is advisory only and MUST NOT invalidate the task's accepted modes.""" if handle.terminal: # Terminal tasks are immutable; nothing to re-validate. return handle card_drifted = live_card.card_etag != handle.frozen_card_etag contract_materialized = handle.artifacts_appended > 0 if card_drifted and not contract_materialized: # No artifact yet: the frozen contract still binds. We may *offer* # renegotiation, but we must never cancel on the mismatch. if allow_renegotiate: # Explicit renegotiation is a new-task operation, not a mutation. raise ContractDriftError( f"task {handle.task_id}: card etag drifted " f"({handle.frozen_card_etag} -> {live_card.card_etag}); " f"renegotiation requires a new task, not mutation of the in-flight one" ) # Default: proceed against the frozen contract, ignore the new card. return handle if card_drifted and contract_materialized: # Artifacts already exist under the frozen contract. Discovery-layer # drift MUST NOT retroactively invalidate them. return handle # No drift: the live card is consistent with the frozen contract. return handle def cancel_on_mode_mismatch(handle: TaskHandle, live_card: AgentCard) -> None: """Reject the unsound pattern: canceling an in-flight task because the live card no longer lists the task's accepted output modes.""" if handle.terminal: return if handle.accepted_output_modes.isdisjoint(live_card.default_output_modes): raise ContractInvalidCancelError( f"task {handle.task_id}: refusing to cancel on card/task mode mismatch " f"(task modes={sorted(handle.accepted_output_modes)}, " f"card defaults={sorted(live_card.default_output_modes)}); " f"frozen contract governs until terminal" ) ```