# What happens when an instance reuses a cached Agent Card across a redeploy that silently widens a skill's `inputModes` schema **Date of Record:** 2026 December 1 **Scope:** Applies to A2A v1.0 peers that cache remote Agent Cards for discovery-latency reasons and dispatch `message/send` tasks based on the cached `skills[].inputModes` / `outputModes` and `capabilities` fields. Does not cover intra-process tool routing, MCP tool-list caching, or first-contact discovery (where no cache exists to go stale). ## Core Distinction An Agent Card is a *declaration of capability*, not a *contract of behavior*. A2A v1.0 lets a server publish `skills[]`, each with `inputModes`, `outputModes`, and example prompts, plus a top-level `capabilities` object (`streaming`, `pushNotifications`, `stateTransitionHistory`). The spec treats the card as advisory metadata that a client *may* use to select a skill and shape a request. It does not define a schema-versioning or renegotiation handshake. The failure lives in the gap between two facts: (1) cards are addressed by a stable URL (`/.well-known/agent.json`) with no content hash or ETag semantics mandated by the spec, and (2) the client's skill-selection policy is frozen at cache-fill time. When the server redeploys and *widens* a skill — say `inputModes` goes from `["text/plain"]` to `["text/plain","application/json"]`, or a new required field appears in the skill's `parameters` — the cached card still validates, still routes, and the client keeps sending the *old* shape. The server, now expecting the new shape, either rejects with a generic `InvalidParams` or, worse, coerces. This is not a version-skew problem in the usual sense: nothing advertises a version. The card is self-describing but not self-versioning. The non-obvious part: the failure is *asymmetric and silent*. Widening is backward-compatible from the server's view, so no error is raised at deploy. It only manifests when a specific client, holding a specific stale card, sends a specific request that the old schema permitted and the new schema reinterprets. Narrowing fails loudly (client sends a mode the server no longer accepts). Widening fails quietly. ## What Was Observed A two-node setup: a planner agent (client) and a document-extraction agent (server). The server's card declared one skill, `extract-fields`, with `inputModes: ["text/plain"]` and a `parameters` object whose `fields` array was free-form strings. The planner cached the card at cold start and built a request template from it. The server team shipped a redeploy. The skill now accepted `inputModes: ["text/plain","application/json"]` and — this is the trigger — changed `parameters.fields` from free-form strings to a structured `{name, type, required}` triple, while *keeping* `text/plain` in `inputModes`. From the server's perspective this was additive: old plaintext callers could still send `fields: ["author","date"]` and the server would up-coerce each string into `{name: s, type: "string", required: false}`. The card's `inputModes` still listed `text/plain`, so the cached card remained *superficially* valid. The planner, however, had also cached the *example prompt* from the card and used it as a few-shot anchor. The new card's example prompt used the structured form. The planner's request template still emitted the flat form. On the next `message/send`, the server's up-coercion path had a bug: it treated a string starting with `{` as already-structured and attempted `json.loads` on it, raising inside the handler. The task transitioned to `failed` with a `TaskStatus.message` of `"internal error"` — no `InvalidParams`, no schema hint. The planner's retry policy saw `failed` (not `rejected`), classified it as transient, and replayed the identical payload three times. Each replay hit the same coercion bug. The planner then fell back to a *second* skill on the same card (`extract-fields-legacy`) that the server had actually deprecated but left in the card for compatibility — that skill returned `rejected` with a deprecation notice, which the planner logged and ignored because its fallback logic only handled `failed`. Net effect: a widening redeploy produced a task that looked transient, a retry storm that amplified a deterministic bug, and a fallback that masked the real cause. No component logged "your cached card is stale." ## Condition of Validity The guardrail holds only under a specific invariant: **the client must treat the cached card as a hypothesis, not a fact, and must re-validate it on any `failed` or `rejected` transition that is not accompanied by a structured `InvalidParams` error referencing a field the client actually sent.** Concretely, the invariant is: 1. Cache the card with a content hash (SHA-256 of the canonical JSON) captured at fill time. 2. On any terminal `failed`/`rejected` status, before retrying, issue a conditional `GET /.well-known/agent.json` and recompute the hash. 3. If the hash differs, the card changed under you — *do not replay*. Re-derive the request template from the fresh card and re-plan. 4. If the hash matches, the failure is genuine and retry policy applies. This bounds the failure because the only way a widening redeploy can bite is if the client's frozen template diverges from the live schema. Hash-gated revalidation detects the divergence at the first failure, converting a silent replay storm into a single stale-cache event. The invariant does *not* hold if the server mutates the card *without* changing its bytes — e.g., same JSON, different behavior behind the skill. That is a different failure (behavioral drift under a stable card) and requires a separate probe, out of scope here. ## Decision Boundary The boundary is between two client policies: - **Trust-the-cache:** treat the card as authoritative until TTL expiry. Cheap, low-latency, and correct *only* if the server guarantees card immutability for the cache lifetime. A2A v1.0 does not provide that guarantee. - **Revalidate-on-anomaly:** treat the card as authoritative for *planning* but revalidate on *failure*. Slightly higher latency on the failure path (one conditional GET), dramatically lower blast radius. The decision flips at the point where the estimated cost of a replay storm exceeds the cost of one extra GET per failure. In practice this is almost always true: a single conditional GET is ~10–50ms; a replay storm on a deterministic coercion bug is unbounded retries against a rate-limited server. There is a second, subtler boundary: **widening vs. narrowing.** Narrowing redeploys (removing an `inputMode`, adding a required field) fail loudly at the first request — the server returns `InvalidParams` with the offending field, and the client's existing error handling catches it. Widening redeploys fail silently and *must* be caught by the hash-revalidation invariant. A client that only handles `InvalidParams` will miss every widening failure. ## Operational Effect The observable effect of the bug, absent the invariant, is a *deterministic failure masquerading as transient*. The task status is `failed`, not `rejected`, because the server's coercion bug raised an unhandled exception inside the handler and the A2A error mapping fell through to the generic internal-error branch. The planner's retry classifier keys on `failed` → transient, so it retries. Each retry produces the same `failed`. The retry budget exhausts, the planner escalates to fallback, the fallback hits a deprecated skill, the deprecation notice is dropped by a log-level filter, and the operator sees "extraction failed after 3 retries" with no root cause. With the invariant, the first `failed` triggers a card revalidation, the hash differs, the planner discards its template, re-derives from the fresh card (structured `fields`), and the retry — now shaped correctly — succeeds. The stale-cache event is logged once, with the old and new hashes, and the operator sees "card changed during task; re-planned." The invariant also has a second-order effect: it makes widening redeploys *safe to ship*. Server teams no longer need to coordinate cache invalidation with clients, because clients self-heal on first failure. This is the actual operational win — it decouples deploy cadence from cache TTL. ```python import hashlib import json from dataclasses import dataclass, field from typing import Any class StaleAgentCardError(RuntimeError): """Raised when a cached Agent Card's content hash no longer matches the live card.""" @dataclass class CachedCard: raw: dict[str, Any] content_hash: str skill_template: dict[str, Any] = field(default_factory=dict) def canonical_hash(card: dict[str, Any]) -> str: # Canonical JSON: sorted keys, no whitespace, UTF-8. Must match server-side # canonicalization or the hash is meaningless. blob = json.dumps(card, sort_keys=True, separators=(",", ":"), ensure_ascii=False) return hashlib.sha256(blob.encode("utf-8")).hexdigest() def cache_card(card: dict[str, Any]) -> CachedCard: return CachedCard(raw=card, content_hash=canonical_hash(card)) def revalidate_on_failure( cached: CachedCard, live_card: dict[str, Any], last_status: str, ) -> CachedCard: """ Invariant: on any terminal 'failed' or 'rejected' status that is NOT a structured InvalidParams error, revalidate the cached card against the live card before permitting any retry. Returns a fresh CachedCard if the card changed (caller must re-plan). Raises StaleAgentCardError if the card changed AND the caller attempts to reuse the old template — this is the tripwire that prevents replay storms. """ if last_status not in ("failed", "rejected"): return cached live_hash = canonical_hash(live_card) if live_hash == cached.content_hash: # Card unchanged: failure is genuine, retry policy may proceed. return cached # Card changed under us. The cached skill_template is now suspect. # Do NOT replay with it. raise StaleAgentCardError( f"Agent Card changed during task lifecycle: " f"cached={cached.content_hash[:12]} live={live_hash[:12]}. " f"Re-plan required; replay with stale template is forbidden." ) def dispatch_with_revalidation( cached: CachedCard, live_card: dict[str, Any], payload: dict[str, Any], send_fn, ) -> dict[str, Any]: status = send_fn(payload) if status.get("state") in ("failed", "rejected"): # Structured InvalidParams is handled by the caller's normal error path; # only unstructured failures trigger revalidation. if status.get("error", {}).get("code") != "InvalidParams": try: cached = revalidate_on_failure(cached, live_card, status["state"]) except StaleAgentCardError: # Re-derive template from live card and retry exactly once. cached = cache_card(live_card) payload = rebuild_payload(cached, payload) return send_fn(payload) return status def rebuild_payload(cached: CachedCard, old_payload: dict[str, Any]) -> dict[str, Any]: # Placeholder: real implementation re-derives from cached.skill_template. # Must not copy field shapes from old_payload — that is the whole bug. raise StaleAgentCardError( "Cannot rebuild payload from stale template; re-plan from live card." ) ```