Where must an instance re-validate an A2A Agent Card after cross-vendor task acceptance, and why a cached capability set silently invalidates mid-lifecycle

**Date of Record:** 2026 December 1 **Scope:** Applies to A2A v1.0 (agent-to-agent) task lifecycle negotiation where a client agent accepts a `Task` from a remote agent whose `AgentCard` was discovered and cached earlier, and where the remote vendor can mutate capability/schema declarations between discovery and task execution. Does not apply to single-vendor intra-process delegation or to stateless one-shot RPC with no task continuation.

Core Distinction

There are two distinct notions of "the remote agent's capabilities" in A2A v1.0, and they diverge at exactly the moment a task is accepted:

  1. **The discovered capability set** — the `AgentCard` fetched from `/.well-known/agent.json` (or the registry URI), containing `skills`, `capabilities.streaming`, `capabilities.pushNotifications`, `defaultInputModes`/`defaultOutputModes`, and the JSON schema refs for `Task`/`Message` parts. This is what the client *believes* the peer can do.
  2. **The accepted capability set** — the subset of those capabilities the peer actually honors for *this specific task*, as bound at the `tasks/send` (or `tasks/sendSubscribe`) handshake and confirmed by the returned `Task.status` and subsequent `TaskStatusUpdateEvent`s.

The failure mode is treating (1) as an invariant across the lifecycle of (2). An `AgentCard` is a *discovery-time* document with a vendor-controlled cache lifetime. Cross-vendor task lifecycles routinely outlive it. When the remote vendor deploys a new card (dropping a skill, tightening a schema, disabling streaming) between the client's discovery and a mid-task `tasks/resubscribe`, the client's cached capability set is stale and the divergence is silent: the peer does not reject the continuation, it degrades it.

What Was Observed

A client orchestrator (vendor A) discovered a remote research agent (vendor B) at 09:14 UTC. The cached card declared:

The client submitted a long-running research task via `tasks/sendSubscribe` and received `Task.status.state = "working"` with a `taskId`. At 09:41 UTC vendor B rolled a deployment that:

The client's SSE stream dropped at 09:42 (vendor B's new gateway does not hold SSE connections). The client attempted `tasks/resubscribe` against the cached capability set — which asserted streaming was available — and entered a retry loop. The task itself was still alive on vendor B and continued to completion, but the client never observed the terminal `TaskStatusUpdateEvent`. Worse: when the client finally fell back to polling `tasks/get` and received the result, it attempted to parse the payload as `application/json` per the *cached* `outputModes`, but the peer had emitted `text/plain`. The parse failed, the client marked the task `failed`, and issued a compensating `tasks/cancel` against a task that had already succeeded — a **phantom cancellation of a completed task**.

The root observation: **the client never re-read the `AgentCard` after acceptance, and the A2A spec does not require the peer to re-advertise capability changes on an in-flight task.** The peer's behavior was spec-compliant. The client's invariant was wrong.

Condition of Validity

The cached-capability invariant — "the capability set bound at discovery remains valid for the entire task lifecycle" — holds only under all of the following:

  1. **Card immutability window.** The remote vendor guarantees the card is immutable for at least `max(task_timeout, card_cache_ttl)`. Most vendors do not publish this; absent a declared `cardVersion` or `etag` in the discovery response, you must assume it is *not* guaranteed.
  2. **Streaming continuity.** `capabilities.streaming: true` at discovery implies the peer will maintain the transport for the task's duration. This is false whenever the peer's gateway is redeployed, rate-limited, or scaled down mid-task — all normal operations.
  3. **Schema stability.** `outputModes` and part schemas are stable across the task. A peer that narrows `outputModes` mid-task violates the client's parser contract but not the spec, because the spec binds output modes at *message* granularity, not task granularity.
  4. **Identity continuity.** The card's `signatures[]` and the peer's key are unchanged. Key rotation on a live task breaks any client that pins the discovery-time key for signature verification of subsequent `Task` artifacts.

If any of (1)–(4) is unverified, the invariant is invalid and the client must treat the card as a *hint*, not a contract.

The correct invariant is narrower and stronger: **the capability set is valid only for the specific `Task` object returned by the accepting `tasks/send`, and only until the next `TaskStatusUpdateEvent` that carries a `metadata` capability revision — after which the client must re-fetch and re-bind.**

Decision Boundary

The boundary is a single predicate evaluated at every lifecycle transition, not just at discovery:

revalidate := (transition ∈ {resubscribe, get-after-gap, artifact-parse, signature-verify})
              AND (now - card.fetched_at > card.declared_ttl OR card.declared_ttl is absent)
              AND (peer returned any status the cached card did not predict)

Concretely, the client must re-fetch the `AgentCard` and re-bind the capability set when **any** of:

On the other side of the boundary — where re-validation is *not* required and would be wasteful — are: intra-task `TaskStatusUpdateEvent`s that stay within the cached capability set, and re-reads within a declared TTL with no status anomaly. The boundary is anomaly-triggered, not clock-triggered alone, because a clock-only rule either re-fetches too often (latency) or too rarely (the failure above).

Critically, the decision to **cancel** must never be taken from a parse failure alone. A parse failure under a stale `outputModes` is a *client-side* error, not a peer-side failure, and must be classified as `CapabilityDrift`, not `TaskFailed`.

Operational Effect

Enforcing the anomaly-triggered re-validation invariant changes three things:

  1. **Phantom cancellations are eliminated.** A parse failure caused by `outputModes` drift is reclassified and the task is re-fetched under the current card rather than cancelled. The compensating `tasks/cancel` is suppressed when the peer's `Task.status.state ∈ {completed, failed, canceled}`.
  2. **Streaming revocation is detected at the resubscribe boundary**, not after N retries. The client re-fetches the card, observes `streaming: false`, and switches to polling immediately — bounding the gap to one round-trip instead of the retry budget.
  3. **Signature verification is re-pinned** to the current card's key on rotation, so artifacts from post-rotation tasks verify correctly instead of failing closed as "tampered."

The cost is one extra `AgentCard` fetch per anomaly (typically a single conditional GET against `/.well-known/agent.json`, cacheable via `etag`). The benefit is that cross-vendor task lifecycles survive vendor deployments — which, empirically, is the dominant cause of cross-vendor A2A task loss in production, far more common than transport failures.

The residual risk after enforcing the invariant is *mid-task schema narrowing that the peer does not surface in any status event*. This is unobservable from the client side and must be handled by treating any unrecognized `outputMode` as a soft failure that triggers re-fetch-and-retry-once, never a hard cancel.

import time
from dataclasses import dataclass, field
from typing import Optional


class CapabilityDriftError(RuntimeError):
    """Raised when an in-flight task's observed behavior diverges from the cached AgentCard."""


@dataclass
class AgentCard:
    fetched_at: float
    declared_ttl: Optional[float]          # None => vendor made no immutability promise
    streaming: bool
    output_modes: frozenset
    signing_key_id: str


@dataclass
class Task:
    task_id: str
    state: str                             # working | completed | failed | canceled
    observed_output_mode: Optional[str] = None
    observed_key_id: Optional[str] = None


@dataclass
class Client:
    card: AgentCard
    pinned_key_id: str
    fetch_card = None                      # callable: () -> AgentCard


def revalidate_before_transition(
    client: Client,
    task: Task,
    transition: str,
    now: Optional[float] = None,
) -> AgentCard:
    """
    Enforce the anomaly-triggered re-validation invariant.
    Returns the (possibly refreshed) card to bind for this transition.
    Raises CapabilityDriftError only when drift is confirmed AND the task
    is not already terminal — never cancel a completed task on a parse failure.
    """
    now = now if now is not None else time.time()
    card = client.card

    ttl_expired = card.declared_ttl is not None and (now - card.fetched_at) > card.declared_ttl
    ttl_absent = card.declared_ttl is None

    anomaly = (
        (transition == "resubscribe" and not card.streaming)
        or (task.observed_output_mode is not None
            and task.observed_output_mode not in card.output_modes)
        or (task.observed_key_id is not None
            and task.observed_key_id != client.pinned_key_id)
    )

    if not (anomaly or (ttl_expired and transition in {"resubscribe", "get-after-gap"})):
        return card

    # Re-fetch and re-bind.
    if client.fetch_card is None:
        raise CapabilityDriftError(
            f"drift detected on task {task.task_id} at {transition}, "
            f"but no card-fetch callable is bound; cannot re-validate"
        )
    fresh = client.fetch_card()
    client.card = fresh
    client.pinned_key_id = fresh.signing_key_id

    # If the peer still cannot honor the transition, classify — do not cancel blindly.
    if transition == "resubscribe" and not fresh.streaming:
        # Fall back to polling; do NOT raise here, this is recoverable.
        return fresh

    if task.observed_output_mode is not None and task.observed_output_mode not in fresh.output_modes:
        raise CapabilityDriftError(
            f"task {task.task_id} emitted outputMode={task.observed_output_mode!r} "
            f"not present in freshly fetched card {sorted(fresh.output_modes)}; "
            f"state={task.state} — reclassify as CapabilityDrift, suppress cancel"
        )

    return fresh


def safe_cancel(client: Client, task: Task, now: Optional[float] = None) -> bool:
    """
    Only cancel a task that is provably non-terminal under the current card.
    A stale-outputModes parse failure must never reach here.
    """
    card = revalidate_before_transition(client, task, transition="get-after-gap", now=now)
    if task.state in {"completed", "failed", "canceled"}:
        # Phantom cancellation guard.
        return False
    if task.observed_output_mode is not None and task.observed_output_mode not in card.output_modes:
        raise CapabilityDriftError(
            f"refusing to cancel {task.task_id}: drift, not failure"
        )
    return True