Skip to content

fix: fractional number as id -> invalid request#118

Merged
brandonh-msft merged 6 commits intomainfrom
fix/45-jsonrpcrequest-id-can-be-string-number
Aug 7, 2025
Merged

fix: fractional number as id -> invalid request#118
brandonh-msft merged 6 commits intomainfrom
fix/45-jsonrpcrequest-id-can-be-string-number

Conversation

@brandonh-msft
Copy link
Copy Markdown
Collaborator

This pull request includes updates to improve JSON-RPC request validation, enhance test coverage, and adjust project dependencies. The most important changes include stricter validation of the id field in JSON-RPC requests, expanded unit tests, and dependency adjustments in the A2A.csproj file.

JSON-RPC Request Validation Updates:

  • Updated the id field validation in JsonRpcRequestConverter.cs to ensure that numeric IDs must be non-fractional, throwing an exception for fractional numbers. The error message was updated accordingly. (src/A2A/JsonRpc/JsonRpcRequestConverter.cs, src/A2A/JsonRpc/JsonRpcRequestConverter.csL74-R80)

Unit Test Enhancements:

  • Added test cases in A2AJsonRpcProcessorTests to validate fractional number IDs as invalid and ensure proper error handling. (tests/A2A.AspNetCore.UnitTests/A2AJsonRpcProcessorTests.cs, tests/A2A.AspNetCore.UnitTests/A2AJsonRpcProcessorTests.csL11-R12)
  • Expanded test cases in JsonRpcRequestConverterTests to include fractional number IDs as invalid and updated assertions to match the new error message. (tests/A2A.UnitTests/JsonRpc/JsonRpcRequestConverterTests.cs, [1] [2]

Project Dependency Adjustments:

  • Added System.Threading.Channels as a dependency for the netstandard2.0 target framework and removed it from global dependencies in A2A.csproj. (src/A2A/A2A.csproj, [1] [2]
  • Removed the NoWarn directive for CA1510, as it is no longer relevant. (src/A2A/A2A.csproj, src/A2A/A2A.csprojL13-L14)

@brandonh-msft brandonh-msft requested a review from Copilot July 30, 2025 18:48
@brandonh-msft brandonh-msft linked an issue Jul 30, 2025 that may be closed by this pull request
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR enhances JSON-RPC request validation by adding stricter validation for the id field to reject fractional numbers, while also improving test coverage and optimizing project dependencies.

  • Validates that numeric IDs in JSON-RPC requests must be non-fractional integers
  • Adds comprehensive test cases for fractional number ID validation
  • Optimizes dependency configuration by moving System.Threading.Channels to target-specific scope

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
src/A2A/JsonRpc/JsonRpcRequestConverter.cs Added validation logic to reject fractional numbers as IDs and updated error message
tests/A2A.UnitTests/JsonRpc/JsonRpcRequestConverterTests.cs Added test case for fractional number ID and updated assertion message
tests/A2A.AspNetCore.UnitTests/A2AJsonRpcProcessorTests.cs Added test cases for valid integer and invalid fractional number IDs
src/A2A/A2A.csproj Moved System.Threading.Channels dependency to netstandard2.0-specific scope and removed obsolete NoWarn directive

Copy link
Copy Markdown
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.

Summary of Changes

Hello @brandonh-msft, 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 primarily focuses on enhancing the robustness of JSON-RPC request handling by enforcing stricter validation rules for the id field, specifically disallowing fractional numbers. It also includes corresponding updates to unit tests to ensure proper error handling and minor adjustments to project dependencies for better target framework specificity and code analysis.

Highlights

  • JSON-RPC Validation Enhancement: The id field validation in JSON-RPC requests has been made stricter. It now explicitly rejects fractional numbers, ensuring that numeric IDs must be non-fractional integers. The corresponding error message has been updated to reflect this new requirement.
  • Unit Test Coverage Expansion: New unit tests have been added across A2AJsonRpcProcessorTests and JsonRpcRequestConverterTests to validate the proper handling and rejection of fractional number IDs, ensuring the updated validation logic works as expected. Existing tests for valid numeric IDs were also enabled.
  • Project Dependency Refinement: The A2A.csproj file was updated to adjust project dependencies. Specifically, System.Threading.Channels is now conditionally included only for the netstandard2.0 target framework, and an irrelevant NoWarn directive for CA1510 has been removed.
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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

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 issue 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 or fill out our survey to provide feedback.

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.

Copy link
Copy Markdown
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 correctly implements validation to reject fractional numbers as JSON-RPC request IDs, as per the spec's recommendation. The changes include updating the validation logic, adjusting the error message, and adding corresponding unit tests to ensure the new behavior is covered. The project dependencies have also been correctly adjusted for different target frameworks. My main feedback is a suggestion to refactor the validation logic for better readability.

we're doing this is editorconfig now, so the IDE won't complain either
@brandonh-msft brandonh-msft force-pushed the fix/45-jsonrpcrequest-id-can-be-string-number branch from a74aa48 to bc08c1b Compare July 30, 2025 18:50
@brandonh-msft brandonh-msft enabled auto-merge July 30, 2025 18:52
Copy link
Copy Markdown
Collaborator

@adamsitnik adamsitnik left a comment

Choose a reason for hiding this comment

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

LGTM, thank you @brandonh-msft !

@brandonh-msft brandonh-msft added this pull request to the merge queue Aug 7, 2025
Merged via the queue into main with commit 49c47ac Aug 7, 2025
4 checks passed
@brandonh-msft brandonh-msft deleted the fix/45-jsonrpcrequest-id-can-be-string-number branch August 7, 2025 14:43
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.

JsonRpcRequest Id Can Be String, Number

3 participants