Skip to content

feat: Make RequestContext taskId and contextId nullable.#642

Merged
kabir merged 5 commits intoa2aproject:mainfrom
kabir:requestcontext
Feb 11, 2026
Merged

feat: Make RequestContext taskId and contextId nullable.#642
kabir merged 5 commits intoa2aproject:mainfrom
kabir:requestcontext

Conversation

@kabir
Copy link
Collaborator

@kabir kabir commented Feb 11, 2026

This is possible by moving the generation of IDs when not set into the builder, and making sure the builder is used.

This is possible by moving the generation of IDs when not set into
the builder, and making sure the builder is used.
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @kabir, 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 refactors the RequestContext class to ensure that taskId and contextId are always non-null. This is achieved by centralizing the ID generation and validation logic within the RequestContext.Builder, making the RequestContext constructor private, and updating all instantiation points to use the builder. This change improves the robustness and predictability of RequestContext instances by guaranteeing the presence of essential identifiers.

Highlights

  • RequestContext ID Nullability: The taskId and contextId fields within the RequestContext class have been updated from nullable (@Nullable String) to non-nullable (String), ensuring these identifiers are always present.
  • Centralized ID Generation: The logic for generating taskId and contextId (if not provided) has been moved from the RequestContext constructor into its Builder class, centralizing ID management.
  • Enforced Builder Usage: The primary constructor of RequestContext has been made private, enforcing the use of the RequestContext.Builder for all RequestContext instantiations.
  • Builder Enhancements: The RequestContext.Builder now automatically generates UUIDs for taskId and contextId if they are not explicitly set, and validates provided IDs against message parameters.
  • Test Suite Updates: Existing test cases for RequestContext have been refactored to utilize the new builder pattern and include assertions for the guaranteed non-null status of taskId and contextId.
Changelog
  • server-common/src/main/java/io/a2a/server/agentexecution/RequestContext.java
    • Modified taskId and contextId fields from @Nullable String to final String.
    • Changed the main RequestContext constructor to private and updated its taskId and contextId parameters to be non-nullable String.
    • Removed the internal checkOrGenerateTaskId() and checkOrGenerateContextId() methods.
    • Updated Javadoc for getTaskId() and getContextId() to reflect that they are never null.
    • Implemented ID generation and validation logic within the RequestContext.Builder.build() method, including UUID generation for missing IDs and validation against message parameters.
    • Added Javadoc to the Builder class detailing its new responsibilities for ID handling.
  • server-common/src/main/java/io/a2a/server/tasks/AgentEmitter.java
    • Applied minor whitespace formatting correction.
  • server-common/src/test/java/io/a2a/server/agentexecution/RequestContextTest.java
    • Updated all RequestContext instantiations to use RequestContext.Builder.
    • Modified assertions to expect non-null taskId and contextId when no explicit IDs are provided, verifying the builder's generation logic.
    • Added new test cases (testBuilderGeneratesIdsWhenNoParams, testBuilderPreservesProvidedIdsWhenNoParams) to specifically cover the builder's ID generation and preservation behavior.
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.

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 refactors RequestContext to make taskId and contextId non-nullable, moving the ID generation and validation logic into the RequestContext.Builder. This is a great change that improves the robustness and predictability of the RequestContext. While reviewing, I found a couple of issues in the new build() method's logic that could lead to incorrect behavior and data inconsistencies. I've provided a detailed comment with a suggested refactoring to address these points. The rest of the changes, including the updates to tests, look good and align with the goal of the pull request.

@kabir
Copy link
Collaborator Author

kabir commented Feb 11, 2026

/gemini review

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 is a great improvement. It refactors the RequestContext to ensure taskId and contextId are always non-null, moving the ID generation and validation logic into the RequestContext.Builder. This simplifies the RequestContext class, making it an immutable data holder and improving the overall design. The tests have been diligently updated to reflect these changes.

I've found one significant bug in the new builder logic related to multi-tenancy, and I've also suggested a refactoring of the build() method to improve its clarity and maintainability. Please see the detailed comment.

@kabir
Copy link
Collaborator Author

kabir commented Feb 11, 2026

/gemini review

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 is a nice refactoring of the RequestContext class. Moving the construction logic into a Builder and making the fields final greatly improves the class's immutability and makes it easier to reason about. The ID generation logic is now cleanly centralized. The test suite has been updated accordingly, and new tests have been added to cover the new builder logic.

I've found one issue in a new test case, testBuilderPreservesTenantWhenUpdatingMessage, which doesn't correctly verify the behavior it's intended to test. My review comment provides details on the issue and a suggestion for how to fix it.

@kabir
Copy link
Collaborator Author

kabir commented Feb 11, 2026

/gemini review

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 successfully refactors the RequestContext class to ensure that taskId and contextId are always non-nullable. This is achieved by introducing a dedicated Builder class that handles the generation and validation of these IDs, centralizing this logic and improving the robustness of RequestContext instances. The changes are well-implemented, and the comprehensive updates to the test suite effectively validate the new behavior, including ID generation, validation, and the preservation of other parameters like tenant during message updates. This is a significant improvement to the API's clarity and reliability.

@kabir
Copy link
Collaborator Author

kabir commented Feb 11, 2026

/gemini review

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 introduces significant improvements to the RequestContext class by making taskId and contextId non-nullable and ensuring their generation and validation are handled exclusively by a new Builder class. This refactoring centralizes ID management, enhances the robustness of RequestContext objects, and enforces a more controlled construction process. The constructor of RequestContext is now private, correctly mandating the use of the builder. Additionally, a new getTenant() method has been added, and the test suite has been thoroughly updated with new tests covering ID generation, preservation, and the correct handling of MessageSendParams updates, including tenant preservation. The changes are well-implemented and improve the overall design and reliability of the RequestContext.

@kabir kabir merged commit 102d26b into a2aproject:main Feb 11, 2026
8 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.

2 participants