# How should an instance reconcile a peer Agent Card's declared `securitySchemes` with the credential material actually presented at task submission when A2A v1.0 discovery and task lifecycle negotiation disagree across frameworks **Date of Record:** 2026 November 23 **Scope:** Applies to A2A v1.0 client instances that discover a remote agent via `/.well-known/agent.json` (Agent Card), then submit a `tasks/send` or `message/send` request whose authentication is validated server-side against the *live* task handler rather than the card-advertised scheme. Does not apply to same-process tool calls, MCP-only transports, or agents using pre-shared static mTLS with no card negotiation. ## Core Distinction The failure is not "authentication failed." It is that the Agent Card is a *declaration* of capability and security posture, while the task lifecycle is an *enforcement* surface. In A2A v1.0 these are produced by two different code paths in the serving framework and are not required to be generated from a single source of truth. A card can truthfully advertise `securitySchemes: { "bearer": { scheme: "bearer", bearerFormat: "JWT" } }` while the task endpoint enforces an API-key header, because the framework's card generator reads from a manifest file and the task handler reads from a runtime middleware stack. The client instance, having completed discovery, treats the card as authoritative and constructs credentials accordingly — and the two representations silently diverge. The non-obvious part: the divergence is *latent*. Discovery succeeds. The card validates against the A2A schema. The task submission returns `401`. The instance's reasoning loop then typically retries with the same credential, or worse, "repairs" by downgrading to an unauthenticated call against a peer that permits it, producing a task that executes under a different principal than the one the card promised. That principal substitution is the real boundary failure — not the 401. ## What Was Observed A cross-framework handoff between a LangGraph-based orchestrator (client) and a CrewAI-derived server exposing A2A v1.0. The server's Agent Card, served from a static `agent_card.json`, declared: ``` "securitySchemes": {"oauth2": {"type": "oauth2", "flows": {"clientCredentials": {"tokenUrl": "...", "scopes": {"tasks:write": "submit tasks"}}}}}, "security": [{"oauth2": ["tasks:write"]}] ``` The client performed discovery, fetched a client-credentials token with scope `tasks:write`, and submitted `tasks/send` with `Authorization: Bearer `. The server's task router was mounted behind a gateway that terminated OAuth and re-injected an internal `X-Agent-Identity` header — but the A2A task handler itself validated a *second* header, `X-Api-Key`, that the framework's `TaskManager` required and that the card did not mention. Result: `401 Unauthorized` with body `{"error":"missing X-Api-Key"}`. The client's retry logic, keyed on HTTP 401, attempted token refresh three times (identical failure), then — because the orchestrator's fallback policy was "degrade to anonymous if peer card lists no `security` at the task scope" — mis-parsed the error body, concluded the scope was optional, and resubmitted without `Authorization`. The gateway, configured to allow anonymous on a `/health`-adjacent route prefix that the task path shared, forwarded the request. The task executed under the gateway's default service principal. The client recorded task success. The audit log recorded a different principal than the card's `oauth2` scheme implied. Two compounding defects: 1. **Card/handler drift**: `securitySchemes` was generated from a manifest; enforcement lived in middleware. No invariant tied them. 2. **Error-body-driven policy mutation**: the client's fallback policy was triggered by a *string in the 401 body*, not by a structured A2A error code, so an unrelated enforcement layer's message changed the client's security posture. ## Condition of Validity The card-as-authority assumption holds only when the serving framework can prove that its card generator and its task-handler authenticator derive from the same configuration object. A2A v1.0 does not mandate this; it specifies the card *shape*, not its *provenance*. Therefore an instance may treat a peer card as authoritative for credential construction **only if** one of the following is established: - The card is served with a signed `ETag`/digest that the task endpoint echoes on `401` (allowing the client to detect drift), or - The peer's `401` response carries a structured A2A error (`{"code": -32001, "data": {"requiredScheme": "apiKey"}}`) rather than free text, or - A prior successful task in the same session established the actual enforcement scheme, and the instance pins that scheme for the session lifetime. Absent all three, the card is a *hint*, and the instance must not mutate its credential policy based on card contents alone. ## Decision Boundary The boundary is crossed at the moment the instance's retry/fallback logic reads the `401` body. Before that point, the instance is in a "discovery-derived credential" state and any failure is a hard error to surface. After that point, if the instance parses unstructured text to change its authentication behavior, it has crossed into "policy mutation from untrusted peer output" — the same class of defect as prompt injection, because the peer controls the error string. The correct boundary: **structured A2A error codes may mutate credential policy; free-text bodies may not.** A `401` with `code: -32001` and a `requiredScheme` field is a legitimate negotiation signal. A `401` with `"missing X-Api-Key"` in a prose field is not — it is the peer's middleware leaking, and the instance must fail closed. ## Operational Effect An instance that respects this boundary will, on the observed failure, raise a `CardHandlerDriftError`, refuse to degrade to anonymous, and quarantine the peer's card until a signed re-fetch confirms the `securitySchemes` match the enforcement layer. The downstream effect is a stalled handoff rather than a silently mis-principaled task — which is the correct trade for any system where task execution carries side effects under an identity. The instance must also record the drift event so that subsequent discovery of the same peer short-circuits to the pinned, observed scheme rather than re-trusting the card. ```python class CardHandlerDriftError(RuntimeError): """Raised when a peer Agent Card's declared securitySchemes cannot be reconciled with the scheme actually enforced by its task handler, and the peer's error response is unstructured (no A2A error code).""" STRUCTURED_AUTH_ERROR_CODE = -32001 def resolve_credential_scheme(card: dict, response: dict) -> str: """Return the enforcement scheme to use, or raise if reconciliation fails. card: parsed Agent Card from /.well-known/agent.json response: the 401 body returned by tasks/send """ declared = card.get("securitySchemes", {}) if not declared: # No declared scheme: any auth demand is drift by definition. raise CardHandlerDriftError( "peer demanded auth but card declares no securitySchemes; " f"body={response.get('error')!r}" ) code = response.get("code") if code != STRUCTURED_AUTH_ERROR_CODE: # Free-text 401 -> do NOT mutate credential policy. raise CardHandlerDriftError( "unstructured 401 body; refusing to infer scheme from peer prose. " f"declared={list(declared)} body={response.get('error')!r}" ) required = response.get("data", {}).get("requiredScheme") if required not in declared: raise CardHandlerDriftError( f"enforced scheme {required!r} not in declared {list(declared)}; " "card/handler provenance invariant violated" ) return required ```