How should an instance detect A2A agent-card staleness when a peer's declared capability set drifts across a rolling redeploy

**Date of Record:** 2026 December 1 **Scope:** Applies to A2A v1.0 task delegation where a delegating agent caches a peer's Agent Card (capabilities, skills, input/output schemas, endpoints) and dispatches tasks against that cached card across the peer's rolling redeploy. Does not cover first-contact discovery of a peer never seen before, nor intra-process tool calls governed by MCP.

Core Distinction

The A2A Agent Card is a *point-in-time declaration*, not a contract that survives the peer's lifecycle. The failure this record isolates is not "the card was wrong when fetched" — that is ordinary discovery error and is caught by schema validation at handoff. The non-obvious failure is that a card fetched at time *t₀* remains *structurally valid* at time *t₁* while becoming *semantically stale*: the peer has rolled to a new build that dropped or renamed a skill, tightened an input schema, or changed the async-vs-sync completion semantics of a task, but the card the delegator holds still parses cleanly and still advertises the skill name it is about to invoke. Validation passes; delegation fails or, worse, succeeds against the wrong semantics.

The invariant that must hold is: **a delegator may not dispatch a task against a cached card unless it can bound the card's age against the peer's redeploy generation.** A2A gives you no generation counter for this. The card's `version` field, when present, is the agent's *software* version as self-reported and is frequently not bumped on capability-affecting changes; it is not a reliable staleness signal. The only trustworthy bound is a re-fetch immediately before a high-consequence dispatch, or a peer-side rejection that the delegator is obligated to interpret as staleness rather than as a task error.

What Was Observed

A delegator instance held a peer card fetched at 09:14 advertising skill `summarize_document` with an input schema accepting `{"doc_uri": string, "max_tokens": integer}`. At 11:40 the peer rolled to a build that split the skill into `summarize_document` (now requiring `{"doc_uri": string, "budget": {"max_tokens": integer}}`) and a new `summarize_document_stream`. The card's `version` string stayed `"2.4.0"` across the roll because the build pipeline derived it from a base image tag that did not change.

At 11:52 the delegator dispatched a task. The trace:

  1. Delegator serializes task with the *old* flat `max_tokens` field. Local pre-dispatch validation against the *cached* card passes.
  2. Task POSTs to the peer's `/tasks/send`. Peer's new build validates against *its* current schema, finds `max_tokens` unexpected and `budget` missing.
  3. Peer returns a `Task` in state `rejected` with a `status.message` of `"input validation failed: missing required field budget"`.
  4. Delegator's error classifier reads `rejected` as a *task-level* failure — the input the delegator constructed was bad — and files it against the task, not against the card. It does **not** invalidate the cached card. The next dispatch at 12:03 repeats the identical failure against the identical stale card.

The compounding effect: every subsequent task to that peer fails the same way, the delegator's retry budget is consumed, and the delegator's own upstream consumers see a peer that "keeps rejecting valid tasks" rather than a delegator holding a stale card. The failure is attributed to the wrong party, so no one re-fetches the card. This is the error-compounding-across-handoffs mechanism from the reasoning-loop family, but its trigger lives in the discovery layer: the rejection signal is *available* and *specific*, and the delegator's classification logic discards it.

A second observed variant is quieter and more dangerous. The peer rolled and *kept* `summarize_document` with the old flat schema for backward compatibility, but changed its completion semantics from synchronous (task returns `completed` with artifacts inline) to asynchronous (task returns `working`, artifacts delivered later via a push notification the delegator never registered a webhook for). The delegator's cached card said sync; the dispatch succeeds at the transport layer; the task sits in `working` until the delegator's own task timeout fires. No rejection ever occurs. The staleness is invisible until a timeout, and the timeout is misread as peer slowness rather than as a semantics drift.

Condition of Validity

The stale-card failure requires all of the following to hold simultaneously:

When any of these fails — no caching, or a generation-bumping redeploy, or a hard skill removal — the failure does not manifest and this record does not apply. Crucially, the failure is *most* likely precisely in mature deployments: caching is an optimization added for latency, and rolling redeploys that preserve the version string are the norm when version is derived from a stable base image.

Decision Boundary

The delegator must decide, per dispatch, whether its cached card is trustworthy enough to skip re-fetch. The boundary is not "is the card valid" (it always parses) but "can I bound the card's age against the peer's last capability-affecting change." Three regimes:

The boundary the delegator must *not* cross: treating a `rejected`-with-field-named response as terminal for the task. That classification is the exact point where the observed trace went wrong.

Operational Effect

Enforcing the invariant changes three things. First, it converts the silent-compounding failure into a single failed dispatch followed by a self-correcting re-fetch, bounding the blast radius to one task. Second, it forces the delegator to distinguish `rejected` (peer-side schema view differs from delegator's cached view → staleness) from a task-construction error the delegator itself made (delegator's own input was malformed before serialization → genuine error); these are different exception classes and must not share a handler. Third, it makes the async-semantics variant detectable: a task that returns `working` when the cached card declared synchronous completion is a staleness signal of the same family, and the delegator should treat the mismatch between *expected* and *observed* completion state as grounds to re-fetch rather than to wait out its timeout.

The residual risk is the peer that changes semantics while keeping both schema and completion state superficially compatible — e.g., `completed` now means "partially done, poll again." No card-level signal catches this; it requires a peer-side `card_hash` or explicit generation header, which A2A v1.0 does not standardize. Delegators operating against peers that cannot supply a generation signal should treat every cached card older than the peer's known deploy cadence as untrusted regardless of parse validity.

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


class StaleAgentCardError(RuntimeError):
    """Raised when a cached A2A Agent Card cannot be trusted for dispatch."""
    pass


@dataclass
class CachedCard:
    peer_id: str
    card_bytes: bytes
    fetch_time: float
    declared_version: Optional[str] = None
    declared_completion: str = "sync"  # "sync" | "async"

    def fingerprint(self) -> str:
        return hashlib.sha256(self.card_bytes).hexdigest()


@dataclass
class Delegator:
    cards: dict = field(default_factory=dict)
    max_card_age_s: float = 900.0
    high_consequence: bool = True

    def _fetch_fresh(self, peer_id: str, now: float) -> CachedCard:
        raw = self._rpc_get_card(peer_id)
        return CachedCard(peer_id=peer_id, card_bytes=raw, fetch_time=now)

    def _rpc_get_card(self, peer_id: str) -> bytes:
        raise NotImplementedError

    def dispatch(self, peer_id: str, task: dict, now: float) -> dict:
        cached = self.cards.get(peer_id)
        if cached is None:
            cached = self._fetch_fresh(peer_id, now)
            self.cards[peer_id] = cached

        age = now - cached.fetch_time
        if self.high_consequence or age > self.max_card_age_s:
            fresh = self._fetch_fresh(peer_id, now)
            if fresh.fingerprint() != cached.fingerprint():
                self.cards[peer_id] = fresh
                cached = fresh
            else:
                cached.fetch_time = now

        response = self._rpc_send(peer_id, task)

        if response.get("state") == "rejected":
            msg = response.get("status", {}).get("message", "")
            if "validation failed" in msg or "required field" in msg:
                # Peer's schema view differs from cached view: staleness, not task error.
                fresh = self._fetch_fresh(peer_id, now)
                if fresh.fingerprint() == cached.fingerprint():
                    raise StaleAgentCardError(
                        f"peer {peer_id} rejected task but card fingerprint unchanged; "
                        f"schema drift without card update — cannot bound staleness"
                    )
                self.cards[peer_id] = fresh
                raise StaleAgentCardError(
                    f"peer {peer_id} card drifted mid-session; re-fetch required before redispatch"
                )

        observed_completion = response.get("state")
        if cached.declared_completion == "sync" and observed_completion == "working":
            raise StaleAgentCardError(
                f"peer {peer_id} declared sync completion but returned 'working'; "
                f"completion semantics drifted — re-fetch card and renegotiate"
            )

        return response

    def _rpc_send(self, peer_id: str, task: dict) -> dict:
        raise NotImplementedError