Skip to content

feat(a2aclient): expose response metadata on client errors - #595

Merged
yarolegovich merged 1 commit into
mainfrom
mykytanetipa/a2a-error-metadata
Nov 16, 2026
Merged

yarolegovich merged 1 commit into
mainfrom
mykytanetipa/a2a-error-metadata

Conversation

@mykytanetipa

@mykytanetipa mykytanetipa commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Adds the metadata of the response that carried an error to a2a.Error, as a new ServiceParams field, and makes the JSON-RPC, REST and gRPC client transports fill it. Callers that need more than the error, such as an OAuth client plugin that reads WWW-Authenticate after a refused call, can now get it without wrapping the HTTP client.

_, err := client.GetTask(ctx, req)
var ae *a2a.Error
if errors.Is(err, a2a.ErrUnauthenticated) && errors.As(err, &ae) {
    challenges := ae.ServiceParams["www-authenticate"]
    // ...
}

Key changes

  • a2a.Error gets a ServiceParams field with the response's HTTP headers, or its gRPC header and trailer metadata, under lowercase keys. Errors that never reached a server, like connection failures, have none, and servers don't send it.
  • JSON-RPC and REST, in v1 and v0.3, attach the headers to errors from non-200 responses, to error bodies in 200 responses and to SSE error events. gRPC, in v1 and v0.3, collects the metadata of unary calls and streams. The v0.3 JSON-RPC transport now also returns a JSON-RPC error that comes back with 200 instead of a stream, as v1 does, rather than reading it as an empty stream.
  • A non-200 JSON-RPC response without a JSON-RPC error body is now an a2a.Error, as REST already does: ErrUnauthenticated for 401, ErrUnauthorized for 403 and ErrServerError otherwise. 404, 405 and 501 stay ErrServerError, since JSON-RPC has a single endpoint and those mean the endpoint is wrong. A body only counts as a JSON-RPC error if it's a JSON-RPC 2.0 response, so a gateway's own JSON on a 401 still maps to ErrUnauthenticated. Messages are unchanged.

Compatibility
A new struct field; gorelease against v2.8.0 reports compatible changes only. a2a.Error was already not comparable, since it holds a map and a slice. Callers that classify errors by type see JSON-RPC status errors as *a2a.Error now; their messages are the same.

Tested

  • Transport tests for each binding: 401 with and without a JSON error body, JSON-RPC errors in 200 responses, SSE error events, and gRPC header and trailer metadata.

Callers sometimes need the response that carried an error, not only the
error itself. An OAuth client plugin, for example, has to read
WWW-Authenticate from a failed call to find the authorization server.
The client transports dropped HTTP response headers and gRPC metadata
when they converted an error response, so this was impossible.

a2a.Error gets a ServiceParams field holding that metadata with
lowercase keys. It is a plain map[string][]string because package a2a
cannot import a2aclient. Servers never send it.

The JSON-RPC transports (a2aclient and a2av0) attach a copy of the
response headers to every error built from a response: a non-200
status, a JSON-RPC error in a 200 response, a JSON-RPC error answered
instead of an SSE stream, and a JSON-RPC error event in an SSE stream.
The REST transports do the same for google.rpc.Status bodies, the HTTP
status fallback and SSE error events. A trailing-data decode failure in
a REST error body is now an *a2a.Error wrapping the same error chain,
so it can carry the headers. The gRPC transports pass grpc.Header and
grpc.Trailer to unary calls, and read the stream header and trailer
after a streaming call fails, and attach both. Errors that were not
received from a server, such as connection failures, are unchanged.

The v0.3 JSON-RPC transport now checks the Content-Type of a 200
response to a streaming call, as the v1 one does, so a JSON-RPC error
answered instead of a stream is returned rather than read as an empty
stream.

A non-200 JSON-RPC response without a JSON-RPC error body used to be an
untyped error. It is now an *a2a.Error wrapping ErrUnauthenticated for
401, ErrUnauthorized for 403 and ErrServerError otherwise, like the
REST fallback. Unlike REST, 404, 405 and 501 are not mapped to
ErrMethodNotFound: JSON-RPC sends every method to one endpoint, so
these statuses mean the endpoint URL is wrong, not that the method is
unknown. A JSON body counts as a JSON-RPC error only when it is a
JSON-RPC 2.0 response, so a gateway's own JSON on a 401, such as
{"error":{"code":401}}, still maps to ErrUnauthenticated. Error messages
are unchanged, but callers that classify errors by type see these
status errors as *a2a.Error now.

The change is backwards compatible. It adds a struct field, and
a2a.Error was already not comparable because it holds a map and a
slice.
@yarolegovich
yarolegovich added this pull request to the merge queue Nov 16, 2026
Merged via the queue into main with commit d6a1d26 Nov 16, 2026
7 of 8 checks passed
@yarolegovich
yarolegovich deleted the mykytanetipa/a2a-error-metadata branch November 16, 2026 12:26
mykytanetipa added a commit that referenced this pull request Nov 16, 2026
Resolves the docs/ai/OVERVIEW.md conflict with #583 and picks up the
squash-merged #595 and #568.
ickeep pushed a commit to HuashiCloud/a2a-go that referenced this pull request Nov 18, 2026
🤖 I have created a release *beep* *boop*
---


## [2.9.0](a2aproject/a2a-go@v2.8.0...v2.9.0)
(2026-11-17)


### Features

* **plugins:** extend clients and servers with `a2aclient.WithPlugins`
and `a2asrv.WithPlugins`. Client plugins wrap calls; server plugins wrap
calls, the agent executor, the task store and push delivery. The
`a2aplugin` package builds plugins from hooks
([a2aproject#572](a2aproject#572),
[a2aproject#581](a2aproject#581))
([5216340](a2aproject@5216340),
[b25d155](a2aproject@b25d155))
* **a2aclient/oauth:** OAuth 2.0 client support. `oauth.Manager`
discovers authorization servers from agent cards and Protected Resource
Metadata, signs users in (authorization code or device grant), and its
plugin attaches and refreshes tokens
([a2aproject#568](a2aproject#568),
[a2aproject#570](a2aproject#570))
([c42999a](a2aproject@c42999a),
[50dd177](a2aproject@50dd177))
* **a2aclient:** errors received from a server carry the response HTTP
headers or gRPC metadata in `a2a.Error.ServiceParams`
([a2aproject#595](a2aproject#595))
([d6a1d26](a2aproject@d6a1d26))
* **a2asrv:** pass the client's accepted output modes to agents in
`ExecutorContext.AcceptedOutputModes`
([a2aproject#603](a2aproject#603))
([57ee56c](a2aproject@57ee56c))


### Behavior Changes

* **a2asrv:** `SendMessage` and `SendStreamingMessage` return at most
`Config.HistoryLength` messages of task history
([a2aproject#603](a2aproject#603))
([57ee56c](a2aproject@57ee56c))
* **a2asrv:** `NewAgentCardEnforcer` rejects messages with a push config
when the card doesn't support push notifications
([a2aproject#603](a2aproject#603))
([57ee56c](a2aproject@57ee56c))
* **a2asrv:** a message reply gets the execution's contextId when the
agent doesn't set one, and its taskId is cleared
([a2aproject#577](a2aproject#577),
[a2aproject#609](a2aproject#609))
([eee75ec](a2aproject@eee75ec),
[97de334](a2aproject@97de334))
* **a2asrv:** getting a missing push config returns `TaskNotFound`
instead of an internal error, and a REST push config delete returns `{}`
([a2aproject#578](a2aproject#578),
[a2aproject#600](a2aproject#600))
([ff3fcf8](a2aproject@ff3fcf8),
[0d1ac2a](a2aproject@0d1ac2a))
* **a2aclient:** a JSON-RPC HTTP error without a JSON-RPC body is an
`*a2a.Error` (`ErrUnauthenticated` for 401, `ErrUnauthorized` for 403,
`ErrServerError` otherwise) instead of a plain error
([a2aproject#595](a2aproject#595))
([d6a1d26](a2aproject@d6a1d26))
* **a2aclient:** stream responses of an unknown type are skipped instead
of ending the stream with an error
([a2aproject#532](a2aproject#532))
([212512b](a2aproject@212512b))


### Bug Fixes

* **a2a:** accept pointer OAuth flow types when marshalling
([a2aproject#541](a2aproject#541))
([fe407e3](a2aproject@fe407e3))
* **a2aacp:** don't count exited agents in makeRoom
([a2aproject#563](a2aproject#563))
([6b0c5bd](a2aproject@6b0c5bd))
* **a2aacp:** drop empty parts instead of sending a block without
content ([a2aproject#594](a2aproject#594))
([d8323ce](a2aproject@d8323ce))
* **a2aacp:** fail turns of a stopped agent with `AgentStoppedError`
([a2aproject#573](a2aproject#573))
([4acb390](a2aproject@4acb390))
* **a2aacp:** release the context lock before reporting the end of a
turn, so `RejectBusyContext` accepts the next message
([a2aproject#601](a2aproject#601))
([964e814](a2aproject@964e814))
* **a2aacp:** reserve pool capacity during startup
([a2aproject#587](a2aproject#587))
([621d73b](a2aproject@621d73b))
* **a2av0:** keep unset ListTasks history length unset
([a2aproject#527](a2aproject#527))
([9b4435f](a2aproject@9b4435f))
* **pbconv:** leave an unset ListTasks page size unset
([a2aproject#576](a2aproject#576))
([5a3d99d](a2aproject@5a3d99d))
* **sse:** support carriage-return event line endings
([a2aproject#487](a2aproject#487))
([ecaea9c](a2aproject@ecaea9c))
* **taskexec:** don't end remote subscriptions at the caller's message
([a2aproject#575](a2aproject#575))
([d0710f5](a2aproject@d0710f5))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

---------

Co-authored-by: Yaroslav Shevchuk <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants