Repository navigation
fix(client)!: validate JSON-RPC response correlation - #560
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Signed-off-by: andy <[email protected]>
Signed-off-by: andy <[email protected]>
1ac021a to
53edcdb
Compare
muscariello
left a comment
There was a problem hiding this comment.
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.
- The stream ends by reading the error code back.
parse_stream_tailmarks an itemterminalwhenerr.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'sapply_event_to_taskproduces 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. - The mock server rewrites every canned response ID to the request's, unless it is
nullor"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. - A server that sends
"id": nullwith 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 <[email protected]>
|
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:
|
Signed-off-by: andy <[email protected]>
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
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 -- --checkandgit diff --check.Tests used the local cached registry mirror and a temporary macOS SDK wrapper.