Skip to content

Conversation

@corvid-agent
Copy link
Contributor

Summary

Replaces console.error/console.warn calls with thrown errors when a JSON-RPC response id does not match the request id. Per the JSON-RPC 2.0 specification, this is a protocol invariant violation — continuing execution with a mismatched response can lead to silent data corruption.

Changes

  • _sendRpcRequest: console.errorthrow new Error on id mismatch
  • _processSseEventData: console.warnthrow new Error on id mismatch
  • _processSseEventData catch block: Added the new error message to the pass-through condition so it is not swallowed and re-wrapped as a parse error

Context

From the code review on PR #169: "Go SDK doesn't perform any validation, but I'd probably be throwing in case of a mismatch"@yarolegovich

Fixes #176

🤖 Generated with Claude Code

Per the JSON-RPC 2.0 specification, a response id must match the
request id. A mismatch indicates a broken protocol invariant.

Previously, mismatches were logged via console.error/console.warn
but execution continued, potentially causing silent data corruption.

Now throws an error in both the unary (_sendRpcRequest) and
streaming (_processSseEventData) code paths.

Fixes a2aproject#176

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@corvid-agent corvid-agent requested a review from a team as a code owner February 9, 2026 20:06
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @corvid-agent, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the robustness of the JSON-RPC transport by strictly adhering to the JSON-RPC 2.0 specification regarding response ID matching. Instead of merely logging warnings or errors, the system now throws exceptions when a response ID does not correspond to the original request ID. This critical change prevents potential silent data corruption and ensures that protocol invariant violations are immediately surfaced, leading to more predictable and reliable communication.

Highlights

  • RPC Response ID Mismatch Handling: Changed console.error to throw new Error in _sendRpcRequest when a JSON-RPC response ID does not match the request ID, enforcing strict protocol compliance.
  • SSE Event ID Mismatch Handling: Replaced console.warn with throw new Error in _processSseEventData for SSE event JSON-RPC response ID mismatches, ensuring immediate failure on protocol violations.
  • Error Propagation: Modified the catch block in _processSseEventData to correctly re-throw the new ID mismatch error, preventing it from being silently swallowed or re-wrapped.
Changelog
  • src/client/transports/json_rpc_transport.ts
    • Replaced console.error with throw new Error when an RPC response ID does not match the expected request ID in the _sendRpcRequest method.
    • Replaced console.warn with throw new Error when an SSE event's JSON-RPC response ID does not match the original request ID in the _processSseEventData method.
    • Updated the _processSseEventData catch block to explicitly re-throw errors related to "SSE Event's JSON-RPC response ID mismatch", ensuring these critical errors are not suppressed.
Activity
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@github-actions
Copy link

github-actions bot commented Feb 9, 2026

🧪 Code Coverage

⬇️ Download Full Report

Main PR Delta
src/client/transports/json_rpc_transport.ts 60.62% 62.57% 🟢 +1.95%
Total 80.04% 80.22% 🟢 +0.18%

Generated by coverage-comment.yml

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request effectively addresses the critical issue of JSON-RPC response ID mismatches by transitioning from logging errors to throwing explicit errors. This change aligns with the JSON-RPC 2.0 specification, treating protocol invariant violations as critical failures, which is a significant improvement for client robustness. The corresponding update to the SSE event processing catch block ensures that these new, specific errors are correctly propagated, preserving valuable context for debugging and handling.

…Data

Move validation logic (ID mismatch, error response, missing result)
outside the try/catch block so errors no longer need to be caught and
re-thrown based on message string matching.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Member

@ishymko ishymko left a comment

Choose a reason for hiding this comment

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

🚀

@ishymko ishymko merged commit 5ea1c94 into a2aproject:main Feb 11, 2026
14 checks passed
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]: Throw in case of JSON-RPC request id mismatch

2 participants