Skip to content

fix: validate JSON-RPC response correlation - #560

Open
Linux2010 wants to merge 3 commits into
a2aproject:mainfrom
Linux2010:codex/validate-jsonrpc-response-id
Open

Linux2010 wants to merge 3 commits into
a2aproject:mainfrom
Linux2010:codex/validate-jsonrpc-response-id

Conversation

@Linux2010

@Linux2010 Linux2010 commented Nov 14, 2026 •

Copy link
Copy Markdown

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 client changelog calls out the stricter success-response validation.

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 96.23824% with 12 lines in your changes missing coverage. Please review.

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

📢 Thoughts on this report? Let us know!

Signed-off-by: andy <linux2011@qq.com>
Signed-off-by: andy <linux2011@qq.com>
@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.

Signed-off-by: andy <linux2011@qq.com>

This branch has not been deployed

No deployments
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