fix(grpc): normalize extension metadata header key to lowercase#673
fix(grpc): normalize extension metadata header key to lowercase#673cchinchilla-dev wants to merge 5 commits intoa2aproject:mainfrom
Conversation
Summary of ChangesHello @cchinchilla-dev, 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 resolves a critical issue where gRPC services failed due to metadata header keys containing uppercase characters, a violation of gRPC's strict lowercase requirement. By systematically applying a lowercase transformation to the extension metadata header key across the gRPC client and server components, the system now adheres to gRPC specifications, preventing runtime errors and ensuring robust communication. The Highlights
Changelog
Activity
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
Code Review
This pull request correctly addresses the issue of gRPC metadata keys needing to be lowercase by applying .lower() where HTTP_EXTENSION_HEADER is used in gRPC contexts. The changes are logical and the added tests provide good coverage for the fix.
I've added a few minor suggestions to improve code clarity and reduce duplication. While the current implementation is correct, these refactorings could enhance long-term maintainability.
Also, as you mentioned in the description, introducing a constant for the lowercase header key (e.g., _GRPC_EXTENSION_HEADER = HTTP_EXTENSION_HEADER.lower()) within the gRPC-related modules could be a good way to make the code more DRY and the intent clearer, without polluting the public API. This is something to consider.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request correctly addresses the issue of gRPC metadata keys needing to be lowercase. The changes are applied consistently across client and server code, and the test suite has been updated accordingly, including the addition of a new regression test. The code is clear and the fix is effective. I have one minor suggestion to improve the robustness of the new test case.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Description
CONTRIBUTINGGuide.fix:which represents bug fixes, and correlates to a [SemVer](https://semver.org/) patch.feat:represents a new feature, and correlates to a SemVer minor.feat!:, orfix!:,refactor!:, etc., which represent a breaking change (indicated by the!) and will result in a SemVer major.bash scripts/format.shfrom the repository root to format)Fixes #656 🦕
Problem
gRPC requires metadata keys to be lowercase ASCII. The SDK uses the constant
HTTP_EXTENSION_HEADER = 'X-A2A-Extensions'when attaching metadata in both the gRPC client transport and the server handler, causing a runtime error:This casing is valid for HTTP/REST (headers are case-insensitive per RFC 7230), but gRPC enforces lowercase and rejects anything with uppercase characters.
Fix
Applied
.lower()to the metadata key at each gRPC boundary:src/a2a/client/transports/grpc.py→_get_grpc_metadata: normalize key when attaching extension metadata to outgoing requests.src/a2a/server/request_handlers/grpc_handler.py→_get_metadata_value: normalize key when reading extension metadata from incoming requests.src/a2a/server/request_handlers/grpc_handler.py→_set_extension_metadata: normalize key when writing extension metadata to trailing response metadata.The
HTTP_EXTENSION_HEADERconstant incommon.pyremains unchanged — it is still correct for HTTP/REST usage.Alternative Considered
A dedicated constant in
common.py(GRPC_EXTENSION_METADATA_KEY = HTTP_EXTENSION_HEADER.lower()) would make the intent more explicit. However, the inline.lower()approach is less invasive: it avoids introducing a new public constant, doesn't change the module's API surface, and keeps the fix tightly scoped to the gRPC paths. Happy to switch if maintainers prefer it.Testing
Updated existing test assertions and added two new tests that explicitly verify the lowercase invariant:
test_grpc_metadata_key_is_lowercasetest_grpc_metadata_key_from_default_extensions_is_lowercaseAll tests pass.