Skip to content

fix(client): report the HTTP status of a non-JSON-RPC error response - #406

Closed
gulldan wants to merge 4 commits into
a2aproject:mainfrom
gulldan:fix/client-jsonrpc-http-status
Closed

gulldan wants to merge 4 commits into
a2aproject:mainfrom
gulldan:fix/client-jsonrpc-http-status

Conversation

@gulldan

@gulldan gulldan commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

Stack: #406 → #405 → #407 → #411 → #395. This is the base; merge it first.

Fixes #404.

Problem

JsonRpcTransport never looked at the HTTP status of a response. When something in front of the agent answers an error itself — an authenticating proxy's 401, a gateway's 429 or 502 — the body is not a JSON-RPC envelope, so the caller got INTERNAL_ERROR "failed to parse JSON-RPC response: …" and could not tell an expired credential or a rate limit from a broken server. A streaming call answered that way without Content-Type went to the SSE parser and came back as Ok with an empty stream.

Fix

  • parse_jsonrpc_response(status, body) replaces the three copies of the envelope parse (call_value_with_payload, the non-SSE branch of call_streaming, delete_push_config). A body that is a JSON-RPC envelope is decoded whatever the status, as before; one that is not is reported with its status — HTTP 429 Too Many Requests: <body> — the same text parse_rest_error gives on the HTTP+JSON transport. A success that fails to parse keeps today's message.
  • In call_streaming, a non-success status is never treated as an event stream, so it reaches that parse instead of the SSE parser.

The error code stays INTERNAL_ERROR, as on the REST transport; mapping statuses to A2A codes would be a separate change.

Tests

  • test_http_error_without_jsonrpc_body_reports_the_status: GetTask answered with 429 Too Many Requests and a plain body. On main: failed to parse JSON-RPC response: expected value at line 1 column 1.
  • test_streaming_http_error_reports_the_status_not_an_empty_stream: SubscribeToTask answered with a bare 401 and no content type. On main it gets a stream (expected error, got a stream).
  • The existing test_subscribe_to_task_surfaces_unparseable_non_streaming_body (a 200 with a non-JSON-RPC body) still passes with its message unchanged.
  • The reproduction from [Bug]: a2a-client: JSON-RPC transport drops the HTTP status of an error response that is not JSON-RPC #404 built on this branch prints HTTP 429 Too Many Requests: {"error":"budget exceeded"}, HTTP 401 Unauthorized: , and HTTP 401 Unauthorized: for the subscription.
  • CI steps on Linux, stable 1.99.1: cargo metadata --locked, cargo hack check --all-targets --each-feature, cargo fmt --check, cargo hack clippy --all-targets --each-feature -- -D warnings, cargo test --workspace --exclude itk-rust-current-agent, copyright headers — all green.

Overlap with the A2A 1.1 stack

#384–#397 also edit a2a-client/src/jsonrpc.rs, and this diff does not apply as is on refs/pull/396/head; the status handling there is unchanged, so the same three call sites need it. Happy to rebase onto the stack once it lands.

🤖 Generated with Claude Code

The JSON-RPC transport never looked at the status of a response. An
error that something in front of the agent answers itself (an
authenticating proxy's 401, a gateway's 429 or 502) carries no
JSON-RPC envelope, so the caller got "failed to parse JSON-RPC
response" and could not tell a credential or rate-limit problem from
a broken server. A streaming call answered that way without a content
type was handed to the SSE parser and came back as an empty stream.

A body that is not a JSON-RPC envelope is now reported with its
status, as the REST transport already does ("HTTP 429 Too Many
Requests: <body>"); a JSON-RPC envelope is still decoded whatever the
status, and a non-success status is never treated as a stream.

Fixes: a2aproject#404

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: gulldan <[email protected]>
@gulldan
gulldan requested a review from a team as a code owner October 31, 2026 10:22
@codecov

codecov Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

The streaming test matched on the result and panicked in an `Ok` arm that a
passing run never reaches, so that line stayed uncovered. Taking the error
with `.err().expect()` keeps the assertion and needs no `Debug` on the stream.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: gulldan <[email protected]>

@muscariello muscariello left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@muscariello

Copy link
Copy Markdown
Member

Superseded by #439, which carries the same commit on an in-repo branch so the stack can be reviewed one commit at a time.

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.

[Bug]: a2a-client: JSON-RPC transport drops the HTTP status of an error response that is not JSON-RPC

2 participants