Skip to content

fix(client)!: validate JSON-RPC response correlation - #560

Merged
muscariello merged 4 commits into
a2aproject:mainfrom
Linux2010:codex/validate-jsonrpc-response-id
Nov 24, 2026
Merged

muscariello merged 4 commits into
a2aproject:mainfrom
Linux2010:codex/validate-jsonrpc-response-id

Conversation

@Linux2010

@Linux2010 Linux2010 commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The JSON-RPC client generates a request ID but did not verify it on responses. A response for a different request could therefore be accepted as the current result or error.

Validate the ID for normal responses, stream preflight errors, SSE envelopes, unframed stream tails and push-config deletion. Preserve null-ID errors and existing bare StreamResponse SSE compatibility. Reject malformed envelopes rather than treating them as bare events, and stop and release the stream after locally detected protocol failures. Server-returned errors with the same numeric code are distinguished from local correlation failures. Test servers explicitly choose whether to echo a request ID or send the supplied ID. The PR title marks the stricter success-response validation as a breaking change for the generated release notes.

Validation

  • Confirmed a mismatched ID was accepted before the fix using a real HTTP response.
  • Confirmed a server-returned error using the same code incorrectly ended the stream before the review fix; the new test verifies a following event is still consumed.
  • cargo test -p a2a-client-lf --locked --offline: 144 unit tests and 10 integration tests passed.
  • cargo clippy -p a2a-client-lf --all-targets --features fuzzing --locked --offline -- -D warnings.
  • cargo fmt --all -- --check and git diff --check.

Tests used the local cached registry mirror and a temporary macOS SDK wrapper.

@codecov

codecov Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.08153% with 8 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
a2a-client/src/jsonrpc.rs 98.08% 8 Missing ⚠️

📢 Thoughts on this report? Let us know!

@Linux2010
Linux2010 force-pushed the codex/validate-jsonrpc-response-id branch from 1ac021a to 53edcdb Compare November 19, 2026 11:33

@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.

Checking the response ID against the request ID is what JSON-RPC 2.0 requires, and the shape is right: a mismatched ID, or a null ID on a success, is INVALID_AGENT_RESPONSE; a null ID on an error is accepted, since a server that could not read the request has nothing to echo; and a bad ID ends the stream. Both commits are signed off now, and the multiline SSE tests cover the data-line joining.

  1. The stream ends by reading the error code back. parse_stream_tail marks an item terminal when err.code == INVALID_AGENT_RESPONSE. That is the client's own mismatch error, but a server can send the same code in an error event (this repo's apply_event_to_task produces it), and that would be treated as a mismatch too. Harmless if the server closes the stream after an error anyway, but a flag from the parse step avoids the coupling.
  2. The mock server rewrites every canned response ID to the request's, unless it is null or "another-request". That keeps the existing tests green but hides which of them depend on a fixed ID. Passing the ID explicitly in the tests that need it would keep the intent visible.
  3. A server that sends "id": null with a success result now fails on unary and streaming calls. That is correct per the spec, but it is a behaviour change that needs a release note.

The a2a-client unit tests pass locally on this head.

@muscariello

Copy link
Copy Markdown
Member

The dedicated stream flag, the explicit response IDs in the tests and the release note are all in, thanks. Two changes to how the behaviour change is recorded:

  1. Put a scope and ! in the title: fix(client)!: validate JSON-RPC response correlation. A success response with a null or mismatched ID used to be accepted and is now an error, which is a break for a client talking to such a server. fix(a2a-pb)!: reject a part with no content and a request with no message #510 marked the same kind of change this way (fix(a2a-pb)!:), and the title is what lands on main.
  2. Please drop the hand-edited [Unreleased] entry in a2a-client/CHANGELOG.md. This repo does not hand-edit its changelogs: the release PR generates them (release-plz.toml says so for the root one), and the only commits that touch them on main are the release bot's. The sentence in the description about the client changelog can then say the title carries it.

@Linux2010 Linux2010 changed the title fix: validate JSON-RPC response correlation fix(client)!: validate JSON-RPC response correlation Nov 24, 2026

@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
muscariello added this pull request to the merge queue Nov 24, 2026
Merged via the queue into a2aproject:main with commit 31652ef Nov 24, 2026
22 checks passed
@github-actions github-actions Bot mentioned this pull request Nov 24, 2026
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