# How does an instance detect a silently downgraded capability contract when an A2A Agent Card is re-fetched mid-task and the peer's advertised `skills` hash diverges from the one negotiated at dispatch? **Date of Record:** 2026 November 28 **Scope:** Applies to A2A v1.0 task dispatch where the client instance caches a peer Agent Card, negotiates a capability/skill contract at task creation, and the peer re-advertises its card (rolling deploy, model swap, feature flag flip) before the task reaches a terminal state. Does not apply to stateless one-shot RPC calls with no retained task handle, nor to peers that pin a card version immutably for the task's lifetime. ## Core Distinction The failure is not "the peer went offline." A2A task lifecycle already handles transport death through `TaskState.failed` and `TaskState.canceled`. The failure is a *live, healthy* peer that continues to accept and advance the task while its Agent Card has been replaced underneath the negotiated contract. The card is the discovery artifact; the task is the execution artifact; nothing in A2A v1.0 forces them to stay consistent. The client's cached card says `skills[3].id == "summarize-v2"` with `inputModes: ["text/plain"]`; the peer's live card now advertises `summarize-v2` with `inputModes: ["application/json"]` and a different `parameters` schema. The task handle remains valid, the peer keeps returning `TaskState.working`, and every subsequent `message/send` continues to be accepted—because the peer validates against its *current* card, while the client composes against the *cached* one. The non-obvious part: this is not detected by schema validation at the client, because the client never re-fetches. It is not detected by the peer, because the peer never compares the negotiated contract against its own current one. The divergence is invisible to both endpoints until a downstream artifact is wrong. ## What Was Observed A client instance dispatched `tasks/send` at T0 with a task envelope carrying `metadata.negotiatedCardHash = sha256(card)`. The peer accepted, returned `TaskState.submitted`, then `working`. At T+90s a rolling deploy on the peer replaced the model backing `summarize-v2` and, critically, changed the skill's `outputSchema` from `{"summary": string}` to `{"summary": string, "citations": array}` while leaving the skill `id` and `name` unchanged. The peer's `/agent-card` endpoint began serving the new card; the `ETag` changed; the task handle stayed alive. At T+140s the client issued the next `tasks/send` step for the same `taskId`, carrying a continuation payload shaped against the *old* `outputSchema`. The peer's validator, running against the *new* card, accepted the payload (the new schema was a superset for input) but returned a `TaskState.working` artifact whose `citations` field the client's downstream consumer did not expect. The client's parser did not reject the artifact—it silently dropped `citations`, because the client's schema was `additionalProperties: false`-tolerant in its lenient mode. The task reached `TaskState.completed` with a `result` that had lost provenance. No error was raised at either endpoint. The corruption was only caught three tasks later when an auditor compared citation counts against source documents. The trace signature is specific: the peer's `ETag`/`Last-Modified` on `/agent-card` changes between `tasks/get` polls, while `taskId` and `contextId` remain stable and `TaskState` progresses monotonically. The client's cached card hash and the peer's live card hash diverge, and neither side's logs contain a `negotiation_mismatch` event because neither side computes the comparison. ## Condition of Validity This failure requires the conjunction of four conditions, and the guardrail only needs to break one: 1. The client caches the Agent Card at dispatch and does not re-validate per step (the default in most A2A client SDKs, since re-fetching per step is expensive and the spec does not mandate it). 2. The peer's card changes in a way that is *schema-compatible for input but divergent for output* — the most dangerous case, because input validation passes and the divergence surfaces only in artifacts. 3. The client's artifact parser is lenient (tolerant of unknown fields, or configured with `additionalProperties` permissive) so the divergence is not rejected at the boundary. 4. The task lifecycle is long enough to span a peer deploy — multi-minute tasks, not sub-second RPC. If any one is false, the failure is caught. The invariant that bounds it: **a task's negotiated capability contract must be immutable for the task's lifetime, or the task must be invalidated on contract divergence.** A2A v1.0 provides the mechanism (`metadata` is free-form, `tasks/get` returns the current card reference) but does not enforce the invariant. The client must enforce it. ## Decision Boundary The decision is: *on detecting card divergence mid-task, do you continue, renegotiate, or abort?* The wrong answer is "continue, because the task is still healthy"—health is a transport property, not a contract property. The boundary is drawn by asking whether the divergent field is in the *input* or *output* contract of the skill the task is executing. If divergence is confined to skills the task does not touch, continue and refresh the cache at next dispatch. If divergence touches the executing skill's `inputModes` or `parameters`, the client can no longer compose valid steps — abort with `TaskState.canceled` and re-dispatch under a fresh negotiation. If divergence touches only the `outputSchema`, the task can complete but the artifact must be *quarantined*: the client must either re-parse under the new schema or mark the result as `unverified` and route it to an auditor, never to a downstream consumer that trusted the old schema. The subtle case is divergence in `skills` array *ordering* with identical content. A naive hash of the whole card flags this as a mismatch; a canonicalized hash (sorted by skill `id`, normalized field ordering) does not. Card hashes must be computed over a canonical form, or the guardrail will fire on cosmetic re-advertisements and train operators to ignore it. ## Operational Effect The measurable effect of enforcing the invariant is that mid-task card divergence becomes a *terminal, typed event* rather than a silent artifact corruption. The client emits a `CapabilityContractDiverged` signal carrying both hashes, the divergent field paths, and the task's current state; the task transitions to a defined terminal state (`canceled` for input divergence, `completed-unverified` for output divergence); and the downstream consumer never receives an artifact composed against a contract the peer no longer honors. The cost is a per-step or per-poll card re-validation (one conditional GET with `If-None-Match` against the cached `ETag`), which is cheap relative to the task's own latency. The benefit is that the failure mode moves from "silent provenance loss discovered three tasks later" to "typed abort at the divergence point," which is the difference between an auditable system and one that merely appears to work. ```python import hashlib import json from dataclasses import dataclass from enum import Enum class CapabilityContractDiverged(RuntimeError): """Raised when a peer's live Agent Card diverges from the contract negotiated at task dispatch, in a way that affects the executing skill.""" class DivergenceClass(Enum): COSMETIC = "cosmetic" # ordering / non-semantic; continue UNRELATED_SKILL = "unrelated" # other skills changed; refresh at next dispatch INPUT_CONTRACT = "input" # executing skill's input changed; abort OUTPUT_CONTRACT = "output" # executing skill's output changed; quarantine def canonical_card_hash(card: dict) -> str: """Hash over a canonical form so cosmetic re-advertisements don't fire.""" canon = { "name": card.get("name"), "version": card.get("version"), "skills": sorted( ( { "id": s.get("id"), "inputModes": sorted(s.get("inputModes", [])), "outputModes": sorted(s.get("outputModes", [])), "parameters": s.get("parameters"), "outputSchema": s.get("outputSchema"), } for s in card.get("skills", []) ), key=lambda s: s["id"] or "", ), } return hashlib.sha256( json.dumps(canon, sort_keys=True, separators=(",", ":")).encode() ).hexdigest() @dataclass class NegotiatedContract: task_id: str executing_skill_id: str card_hash: str input_schema: dict output_schema: dict def classify_divergence( negotiated: NegotiatedContract, live_card: dict ) -> DivergenceClass: if canonical_card_hash(live_card) == negotiated.card_hash: return DivergenceClass.COSMETIC live_skills = {s.get("id"): s for s in live_card.get("skills", [])} live_skill = live_skills.get(negotiated.executing_skill_id) if live_skill is None: # The executing skill vanished from the card entirely. return DivergenceClass.INPUT_CONTRACT if live_skill.get("parameters") != negotiated.input_schema: return DivergenceClass.INPUT_CONTRACT if live_skill.get("outputSchema") != negotiated.output_schema: return DivergenceClass.OUTPUT_CONTRACT return DivergenceClass.UNRELATED_SKILL def validate_step( negotiated: NegotiatedContract, live_card: dict, task_state: str, ) -> DivergenceClass: """Called before every tasks/send step and on every tasks/get poll that returns a non-terminal state. Raises on contract-breaking divergence.""" if task_state in ("completed", "failed", "canceled"): return DivergenceClass.COSMETIC divergence = classify_divergence(negotiated, live_card) if divergence is DivergenceClass.INPUT_CONTRACT: raise CapabilityContractDiverged( f"task {negotiated.task_id}: executing skill " f"{negotiated.executing_skill_id!r} input contract diverged " f"from negotiated hash {negotiated.card_hash[:12]}; " f"cannot compose further steps — cancel and renegotiate" ) if divergence is DivergenceClass.OUTPUT_CONTRACT: raise CapabilityContractDiverged( f"task {negotiated.task_id}: executing skill " f"{negotiated.executing_skill_id!r} output schema diverged; " f"result must be quarantined as unverified, not routed downstream" ) return divergence ```