Skip to content

fix: Reject SendMessage with mismatching contextId and taskId#728

Merged
ehsavoie merged 1 commit intoa2aproject:mainfrom
jmesnil:723_SendMessage_mismatch_contextID
Mar 12, 2026
Merged

fix: Reject SendMessage with mismatching contextId and taskId#728
ehsavoie merged 1 commit intoa2aproject:mainfrom
jmesnil:723_SendMessage_mismatch_contextID

Conversation

@jmesnil
Copy link
Collaborator

@jmesnil jmesnil commented Mar 12, 2026

When a message references an existing task but provides a contextId that doesn't match the task's context, reject it with an InvalidParamsError.

This fixes #723

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, 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 introduces a crucial validation step to enhance the integrity of message processing within the system. It ensures that messages intended for existing tasks are correctly routed by verifying that their contextId aligns with the task's contextId. This prevents potential data corruption or misdirection of messages, improving the robustness of the message handling mechanism.

Highlights

  • Context ID Validation: Implemented a new validation check in DefaultRequestHandler to ensure that when a SendMessage operation references an existing task, the contextId provided in the message matches the contextId of the task.
  • Error Handling: Requests with a contextId mismatch will now be rejected with an InvalidParamsError, preventing messages from being incorrectly associated with tasks.
  • Test Coverage: Added a new unit test (testRejectMismatchingContextId) in DefaultRequestHandlerTest to verify the correct behavior of the contextId mismatch validation and error throwing.
Changelog
  • server-common/src/main/java/io/a2a/server/requesthandlers/DefaultRequestHandler.java
    • Added a check to validate if the contextId in an incoming message matches the contextId of an existing task.
    • Introduced an InvalidParamsError to be thrown when a contextId mismatch is detected.
  • server-common/src/test/java/io/a2a/server/requesthandlers/DefaultRequestHandlerTest.java
    • Imported assertThrows for testing expected exceptions.
    • Imported InvalidParamsError for use in the test.
    • Added testRejectMismatchingContextId to test the new validation logic for mismatched contextIds.
Activity
  • No specific activity (comments, reviews, progress) has been recorded for this pull request yet.
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 correctly implements the validation to reject messages with a mismatched contextId for an existing task. The added logic in DefaultRequestHandler prevents associating a message with a task in a different context, and the new test case in DefaultRequestHandlerTest effectively verifies this behavior. I have a couple of suggestions for minor improvements to enhance code clarity and test robustness.

@jmesnil jmesnil force-pushed the 723_SendMessage_mismatch_contextID branch from d37a5e8 to 073f63c Compare March 12, 2026 09:39
When a message references an existing task but provides a contextId that
doesn't match the task's context, reject it with an InvalidParamsError.

This fixes a2aproject#723

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@jmesnil jmesnil force-pushed the 723_SendMessage_mismatch_contextID branch from 073f63c to 0f4d7a5 Compare March 12, 2026 09:43
@ehsavoie ehsavoie merged commit a667e90 into a2aproject:main Mar 12, 2026
13 of 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]: SendMessage does not return an error when taskId and contextId are mismatched

2 participants