# How does an instance detect a stale agent card during an in-flight A2A task lifecycle? **Date of Record:** 2026 November 29 **Scope:** Applies to A2A v1.0 task execution where a client agent holds a cached `AgentCard` obtained at discovery time and continues to drive a multi-turn task (`tasks/send`, `tasks/get`, streaming updates) against the resolved endpoint. Does not cover initial discovery resolution (well-known URI fetch), transport-level TLS failures, or non-A2A tool invocations. ## Core Distinction The distinction that matters is between **card freshness at task admission** and **card freshness at task continuation**. A2A v1.0 treats the `AgentCard` as the contract that fixes the remote agent's skills, input/output modes, capabilities (streaming, push notifications), and authentication schemes. Clients almost universally fetch this card once, cache it, and then open a task. The failure mode is not a bad card at admission — that is caught by schema validation. The failure is a **mid-lifecycle card rotation**: the remote agent redeploys with a changed `AgentCard` (new skill set, changed `defaultInputModes`, revoked auth scheme, altered `capabilities.streaming`) while an existing `taskId` is still `working`. The task handle remains valid, the endpoint remains reachable, and every transport-level check passes — but the card that justified the current turn's request shape no longer describes the agent that will service it. This is a continuity invariant violation, not a discovery bug. The invariant is: *for the lifetime of a task, the capabilities the client relies on to construct each turn must be a subset of the capabilities of the agent actually servicing that turn.* Nothing in A2A v1.0 enforces this. The `taskId` is the only continuity token, and it carries no card version binding. ## What Was Observed A client agent opens a task against a remote whose cached card advertises `capabilities.streaming: true` and `defaultInputModes: ["text/plain", "application/json"]`. Turn 1 succeeds. Between turn 1 and turn 2 the remote is redeployed: streaming disabled, `application/json` dropped from input modes, and the skill the client is mid-way through (`summarize-with-citations`) re-versioned with a stricter input schema. The `taskId` is preserved across the redeploy because task state lives in a durable store keyed by `taskId`, not by card version. Turn 2 proceeds. The client, trusting the cached card, sends a JSON payload and requests a streamed response. The remote accepts the request at the transport layer (HTTP 200, valid JSON-RPC envelope) and returns a `Task` object with `status.state: "working"`. The client now blocks on an SSE stream that will never open, because the servicing agent's `capabilities.streaming` is now `false`. The mismatch surfaces not as an error but as **silence**: no `TaskStatusUpdateEvent`, no `TaskArtifactUpdateEvent`, no terminal state. The task sits in `working` indefinitely. The client's per-turn timeout fires, retries the same request against the same cached card, and reproduces the same silence — an infinite retry loop bounded only by the client's own retry budget. A second, subtler variant: the remote rotates its auth scheme (e.g., from `Bearer` to a signed `AgentCard`-declared scheme). The cached card still names the old scheme. The client signs turn 2 with the stale scheme; the remote rejects at the auth layer, but because A2A maps auth failures onto `Task.status.state: "input-required"` in some implementations to prompt re-authentication, the client misreads a hard auth rotation as a benign clarification request and re-sends the same payload — compounding the loop. The card's `securitySchemes` and `security` fields are the ones that lied, and they are exactly the fields a client never re-checks mid-task. The observable signature is therefore: **a task that is neither `completed`, `failed`, nor `canceled`, whose turns all return `working` or `input-required`, and whose per-turn requests are byte-identical to the turn that last succeeded.** That signature is what an instance must learn to recognize. ## Condition of Validity The stale-card hypothesis is only the correct diagnosis under a specific conjunction of conditions. If any of these fails, the fault lies elsewhere and the guardrail below will misfire: 1. The task handle (`taskId`) is still resolvable — `tasks/get` returns a `Task` rather than `-32001 TaskNotFound`. A missing task is a different failure (state eviction), not staleness. 2. Every failing turn returns a well-formed JSON-RPC response with a valid `Task` envelope. Malformed envelopes or transport errors point to endpoint/proxy faults, not card rotation. 3. The failing turns are retries of a request shape that previously succeeded under the same `taskId`. If the client has changed its request shape between turns, the mismatch may be self-inflicted. 4. The remote's current `AgentCard` (re-fetched from the well-known URI) differs from the cached card in at least one field the client's current turn depends on — `capabilities`, `defaultInputModes`/`defaultOutputModes`, `skills[].inputSchema`, or `security`/`securitySchemes`. If the re-fetched card is identical, the card is not stale and the diagnosis is wrong. The conjunction is what separates staleness from the near-miss cases an instance will otherwise confuse it with: a genuinely slow remote (no card change, just latency), a task the remote has silently abandoned (card unchanged, task state stale on the server side), and a client-side serialization bug (card unchanged, request malformed by the client). ## Decision Boundary The decision boundary is **whether to invalidate the task or re-bind it to the new card**. These are not equivalent, and choosing wrong is the second-order failure. - **Re-bind** is correct when the re-fetched card is a superset-compatible evolution: the skill the task uses still exists under the same identifier, the client's current input mode is still in `defaultInputModes`, and the only deltas are additive (new skills, new optional capabilities). In this case the task can continue; the client must re-derive its next turn's request shape from the *new* card before sending. Re-binding without re-deriving the request shape merely repeats the failure with a fresh card. - **Invalidate** is correct when the servicing skill was removed, re-versioned with an incompatible `inputSchema`, or when `capabilities.streaming` flipped from `true` to `false` mid-task and the client cannot degrade to polling. Invalidation means issuing `tasks/cancel` against the old `taskId` and opening a fresh task against the new card — *not* silently retrying under the old handle. The boundary is crossed the moment the client detects the card delta and must decide which branch it is in; it is *not* crossed by a timeout alone. A timeout with an unchanged card is a latency problem and must not trigger invalidation. This is the precise line an instance must hold: **card delta is the trigger, timeout is only the symptom that surfaces it.** ## Operational Effect The guardrail is a **card-version binding check on every continuation turn**, cheap enough to run on each `tasks/send`/`tasks/get` rather than only at admission. Concretely: cache the card with a content hash; before each continuation turn, re-fetch the well-known `AgentCard` (or use a conditional GET with the cached hash as `If-None-Match` if the remote supports it), compare the hash, and if it differs, run the decision boundary above before constructing the request. If the task cannot be re-bound, cancel and re-open. The cost is one conditional GET per turn — negligible against the turn itself — and the payoff is that the two silent failure modes (never-opening stream, auth-rotation-as-`input-required`) become loud, diagnosable events with a defined recovery. The invariant this restores is the one A2A v1.0 leaves implicit: a `taskId` is only meaningful relative to the card under which it was opened, and an instance that treats the handle as card-independent will eventually hang on a task that is working perfectly — for a different agent than the one it thinks it is talking to. ```python import hashlib import json from dataclasses import dataclass from typing import Any, Optional class StaleAgentCardError(RuntimeError): """Raised when an in-flight A2A task is being driven against a card the remote no longer serves.""" pass class UnrebindableTaskError(StaleAgentCardError): """Raised when the card delta cannot be reconciled with the live task; task must be canceled and re-opened.""" pass @dataclass class CachedCard: raw: dict content_hash: str def card_hash(card: dict) -> str: canonical = json.dumps(card, sort_keys=True, separators=(",", ":")) return hashlib.sha256(canonical.encode("utf-8")).hexdigest() def rebindable(old: dict, new: dict, used_skill_id: str, used_input_mode: str) -> bool: # Skill must still exist and its input schema must not have tightened incompatibly. old_skill = next((s for s in old.get("skills", []) if s.get("id") == used_skill_id), None) new_skill = next((s for s in new.get("skills", []) if s.get("id") == used_skill_id), None) if old_skill is None or new_skill is None: return False if old_skill.get("inputSchema") != new_skill.get("inputSchema"): return False # The input mode the client is currently using must still be accepted. if used_input_mode not in new.get("defaultInputModes", []): return False # Streaming must not have been revoked if the client is mid-stream. if old.get("capabilities", {}).get("streaming") and not new.get("capabilities", {}).get("streaming"): return False return True def check_continuation( cached: CachedCard, fetched_card: dict, used_skill_id: str, used_input_mode: str, ) -> Optional[dict]: """ Called before every continuation turn of an in-flight task. Returns the card to use for this turn (cached or fresh), or raises if the task can no longer be driven against any valid card. """ fresh_hash = card_hash(fetched_card) if fresh_hash == cached.content_hash: return cached.raw # no delta; proceed on cached card if rebindable(cached.raw, fetched_card, used_skill_id, used_input_mode): # Re-bind: continue the task, but re-derive the request shape from the fresh card. return fetched_card raise UnrebindableTaskError( f"agent card rotated incompatibly mid-task: " f"skill={used_skill_id!r} input_mode={used_input_mode!r} " f"old_hash={cached.content_hash[:12]} new_hash={fresh_hash[:12]}; " f"cancel task and re-open against fresh card" ) def drive_turn(task_id: str, cached: CachedCard, fetch_card, send_turn, used_skill_id: str, used_input_mode: str) -> Any: fetched = fetch_card() try: card = check_continuation(cached, fetched, used_skill_id, used_input_mode) except UnrebindableTaskError: # Loud, bounded recovery: cancel and surface, do not silently retry. raise return send_turn(task_id, card) ```