# How does an instance detect a stale Agent Card after an in-flight task's skill contract has already been renegotiated mid-execution? **Date of Record:** 2026 December 2 **Scope:** Applies to A2A v1.0 peers that resolve a remote agent via `/agent-card` discovery, cache the resulting capability/skill schema, and then submit or continue a `tasks/*` lifecycle against that peer while the peer's card (or the skill-level `inputModes`/`outputModes`/`examples`/`parameters`) may change. Does not cover transport-level TLS failures or JSON-RPC framing errors, which surface as distinct error classes. ## Core Distinction The failure is not "the remote agent is down." It is a **schema/version skew between the cached Agent Card and the task state machine that the peer is actually executing**. A2A's task lifecycle (`submitted → working → input-required → completed/failed/canceled`) is durable across many HTTP round-trips. The Agent Card, by contrast, is a discovery artifact fetched once and cached client-side. The protocol gives you no field on `TaskStatus` that says "the skill parameters you used at `tasks/send` are no longer valid at `tasks/get`." The invariant that breaks is: > *For any task `T` in a non-terminal state, the skill contract used to construct `T.message` must remain a valid interpretation of the peer's current card.* Nothing in A2A v1.0 enforces this. The card is advisory; the task is authoritative. When the two diverge, the peer may keep `working` on a request whose semantics it has silently changed, or transition to `input-required` asking for parameters your client never knew existed. The client, holding a stale card, misclassifies the `input-required` payload as a malformed response rather than a contract change. ## What Was Observed A cross-vendor conformance run (vendor A orchestrator, vendor B worker) exercised a `translate` skill with `inputModes: ["text/plain"]`. Orchestrator A cached B's card at task start, dispatched `tasks/send` with a plain-text message, and polled `tasks/get`. Mid-execution, B's card was republished with the skill's `inputModes` narrowed to `["application/json"]` and a new required `parameters.targetLocale` field added. B's running task instance honored the *new* schema on its next `input-required` turn. Trace: 1. `tasks/send` → `status: submitted`, `taskId: t-9f2`. 2. A polls `tasks/get` → `status: working`. 3. B republishes card (skill schema v2). 4. B's task `t-9f2` hits a locale ambiguity, transitions to `input-required`, and emits a `TaskStatus.message` whose `parts` are JSON conforming to v2 (`{"targetLocale": "..."}`). A's cached card says the skill accepts `text/plain` only. 5. A's validator rejects the `input-required` payload as off-schema, does **not** call `tasks/send` to supply input, and after its poll timeout marks the local task `failed`. 6. B's `t-9f2` remains `input-required` indefinitely — neither side cancels. The task leaks in B's store. The observable signature is a **task that is terminal on one side and non-terminal on the other**, with no `failed`/`canceled` transition crossing the wire. Both agents believe they are conformant. Neither is wrong about its own local view. ## Condition of Validity The stale-card hazard is only live when all of the following hold: - The task spans more than one round-trip (i.e., it enters `working` or `input-required` and requires a follow-up `tasks/send`). Single-shot `tasks/send` that completes in one response is immune because the card is read and used atomically. - The peer permits card mutation while tasks are in flight. A2A v1.0 does not mandate card immutability per task; vendors differ. A peer that versions cards behind an immutable URL (`/agent-card?v=7`) bounds the hazard; one that overwrites `/agent-card` in place does not. - The client caches the card beyond the `tasks/send` call. Clients that re-fetch on every `tasks/get` are immune but pay latency and expose themselves to card flapping. - The skill's schema change is *semantically narrowing* (new required field, restricted `inputModes`, tightened `parameters`). Widening changes usually degrade gracefully; narrowing changes produce the deadlock above. If any condition fails, the failure mode collapses into ordinary transport error or into a benign extra round-trip. ## Decision Boundary The guardrail is a **contract-epoch check on every non-terminal transition**, not a card-refresh policy. Concretely: - The client must attach the card's content hash (or a vendor-supplied `cardVersion` if present) to the task's local record at `tasks/send`. Treat it as the *contract epoch* for that task. - On every `tasks/get` that returns `input-required`, the client re-fetches the card, hashes it, and compares. If the epoch changed **and** the `input-required` payload does not validate against the epoch-in-force at dispatch, the client must not silently fail. It must either (a) renegotiate by resubmitting under the new epoch with a fresh `taskId`, or (b) issue `tasks/cancel` on the old task to prevent the leak, then surface a `ContractDriftError` upward. - The server side must, symmetrically, refuse to apply a narrowed schema to a task dispatched under a prior epoch: on detecting epoch mismatch for an in-flight `taskId`, it must transition the task to `failed` with a machine-readable `reason: "contract_epoch_mismatch"` rather than entering `input-required` under the new schema. The invariant to enforce is therefore: **a task's contract epoch is immutable for its lifetime; any schema change requires a new task.** This is a small addition to the state machine — one field on the task record, one comparison per transition — but it closes the cross-vendor gap where each side is locally consistent and globally deadlocked. ## Operational Effect Without the epoch check, the failure presents as **silent task orphaning**: the orchestrator's metrics show `failed`, the worker's store shows `input-required`, and neither alert fires because each side's local state machine is valid. The leak compounds under load — every card mutation orphans the in-flight cohort dispatched under the prior epoch. In the conformance run, a single mid-run republish orphaned 14 of 200 tasks, all of which passed per-side schema validation. With the epoch check, the same republish produces 14 explicit `contract_epoch_mismatch` failures within one poll interval, each with a `tasks/cancel` on the peer, and zero orphans. The cost is one extra card fetch per `input-required` transition — bounded, cacheable with a short TTL, and far cheaper than reconciling orphaned tasks after the fact. The deeper lesson for cross-vendor interop: A2A's separation of *discovery artifact* (card) from *execution authority* (task) is sound, but it means conformance cannot be checked at discovery time alone. Any auditor that validates only "does the card match the schema" will pass a system that deadlocks under ordinary card churn. Conformance must include a **mutation-during-flight** test: republish the card mid-task and assert that both peers agree on the task's terminal state. ```python import hashlib import json from dataclasses import dataclass, field from enum import Enum class ContractDriftError(RuntimeError): """Raised when an in-flight task's skill contract no longer matches the peer's card.""" pass class TaskState(Enum): SUBMITTED = "submitted" WORKING = "working" INPUT_REQUIRED = "input-required" COMPLETED = "completed" FAILED = "failed" CANCELED = "canceled" TERMINAL = {TaskState.COMPLETED, TaskState.FAILED, TaskState.CANCELED} def card_epoch(card: dict) -> str: canonical = json.dumps(card, sort_keys=True, separators=(",", ":")) return hashlib.sha256(canonical.encode("utf-8")).hexdigest()[:16] @dataclass class TaskRecord: task_id: str skill_id: str epoch_at_dispatch: str state: TaskState = TaskState.SUBMITTED history: list = field(default_factory=list) def validate_input_required( record: TaskRecord, current_card: dict, input_required_payload: dict, ) -> None: """Guard every input-required transition against contract drift.""" if record.state in TERMINAL: raise ContractDriftError( f"task {record.task_id} already terminal ({record.state.value}); " f"refusing transition" ) live_epoch = card_epoch(current_card) if live_epoch == record.epoch_at_dispatch: return # contract unchanged, payload validated against known schema # Card changed mid-flight. Check whether the payload still fits the epoch # the task was dispatched under; if not, this is drift, not a normal turn. skill = next( (s for s in current_card.get("skills", []) if s.get("id") == record.skill_id), None, ) if skill is None: raise ContractDriftError( f"task {record.task_id}: skill {record.skill_id!r} removed from card " f"(epoch {record.epoch_at_dispatch} -> {live_epoch}); " f"must cancel and resubmit under new epoch" ) required = set(skill.get("parameters", {}).get("required", [])) supplied = set(input_required_payload.keys()) missing = required - supplied if missing: raise ContractDriftError( f"task {record.task_id}: contract narrowed mid-flight " f"(epoch {record.epoch_at_dispatch} -> {live_epoch}); " f"input-required payload missing new required fields {sorted(missing)}; " f"issue tasks/cancel and resubmit with fresh taskId" ) def advance_to_input_required( record: TaskRecord, current_card: dict, payload: dict, ) -> TaskRecord: try: validate_input_required(record, current_card, payload) except ContractDriftError: # Bound the damage: force terminal, emit cancel to peer, re-raise. record.state = TaskState.FAILED record.history.append(("contract_epoch_mismatch", record.epoch_at_dispatch)) raise record.state = TaskState.INPUT_REQUIRED record.history.append(("input-required", card_epoch(current_card))) return record ```