Skip to content

feat: Check transports in AgentCard match those on classpath#251

Merged
fjuma merged 3 commits intoa2aproject:mainfrom
kabir:transport-warning
Sep 4, 2025
Merged

feat: Check transports in AgentCard match those on classpath#251
fjuma merged 3 commits intoa2aproject:mainfrom
kabir:transport-warning

Conversation

@kabir
Copy link
Collaborator

@kabir kabir commented Sep 3, 2025

Fixes #246 🦕

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.

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 addresses a potential runtime issue by implementing a robust validation system for AgentCards. It ensures that any transport protocols declared within an AgentCard are genuinely supported and available on the classpath, thereby improving the reliability and preventing errors related to missing transport dependencies. The changes involve new interfaces, a dedicated validator, and integration points within existing transport handlers.

Highlights

  • AgentCard Transport Validation: Introduced a new validation mechanism to ensure that the transport protocols specified in an AgentCard are actually available on the application's classpath. This prevents misconfigurations and ensures runtime stability.
  • New TransportMetadata Interface: Defined a new TransportMetadata interface that transport implementations must implement to expose their supported protocols, enabling dynamic discovery via Java's ServiceLoader.
  • Integration with Existing Handlers: Integrated the new validation logic into the GrpcHandler and JSONRPCHandler initialization processes, ensuring that AgentCards are validated when handlers are set up.
  • Enhanced Test Coverage: Added new unit tests for the AgentCardValidator and updated existing test infrastructure to support the new transport discovery and validation, including the use of properties files for preferred transport configuration in tests.
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. 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.

@kabir kabir force-pushed the transport-warning branch from 523f593 to c8a14af Compare September 3, 2025 13:51
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 a validation mechanism to ensure that transports specified in an AgentCard are available on the classpath. This is achieved by using Java's ServiceLoader to discover TransportMetadata implementations. The core logic is in the new AgentCardValidator class, which is then integrated into the gRPC and JSON-RPC transport handlers.

The implementation is solid, but I've identified a potential design issue with how ServiceLoader interacts with dependency injection, which could lead to NullPointerExceptions in the future. I've left comments with suggestions on how to make this more robust. I also noticed some code duplication in test helper methods that could be refactored for better maintainability.

Comment on lines +55 to 72
private static String loadPreferredTransportFromProperties() {
URL url = AgentCardProducer.class.getResource(A2A_REQUESTHANDLER_TEST_PROPERTIES);
if (url == null) {
return null;
}
Properties properties = new Properties();
try {
try (InputStream in = url.openStream()){
properties.load(in);
}
} catch (IOException e) {
throw new RuntimeException(e);
}

String preferredTransport = properties.getProperty(PREFERRED_TRANSPORT);
Assertions.assertNotNull(preferredTransport);
return preferredTransport;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

This loadDefaultTransportFromProperties method is nearly identical to the one in AbstractA2ARequestHandlerTest. To improve maintainability and avoid code duplication, consider extracting this logic into a shared test utility class.

The two implementations also have a slight difference in handling a missing properties file (url == null): one returns null while the other fails with an assertion. Consolidating them would also unify this behavior.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't think this makes sense. It is only test code, and dependencies between those is a bit tricky

@kabir kabir force-pushed the transport-warning branch from 438d08d to 6e13ad6 Compare September 3, 2025 15:51
@kabir
Copy link
Collaborator Author

kabir commented Sep 3, 2025

/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 a valuable feature for validating AgentCard transport configurations against available transports on the classpath. The implementation correctly uses the ServiceLoader pattern for discovering transport metadata, making it extensible. The validation logic is sound, and the integration into the transport handlers is well-thought-out. I've identified one potential race condition in the GrpcHandler's initialization logic that should be addressed to ensure thread safety.

@kabir kabir force-pushed the transport-warning branch from 6e13ad6 to 9ac1e19 Compare September 3, 2025 15:57
@kabir
Copy link
Collaborator Author

kabir commented Sep 3, 2025

/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 a valuable feature to validate that the transports specified in an AgentCard are available on the classpath, improving the robustness of agent configurations. The implementation correctly uses Java's ServiceLoader for discovering transport metadata, and includes a good set of unit tests. My review found a logical error in the one-time validation for the gRPC handler and a minor case of code duplication in the test helpers. Overall, this is a solid contribution.

Comment on lines +55 to 72
private static String loadPreferredTransportFromProperties() {
URL url = AgentCardProducer.class.getResource(A2A_REQUESTHANDLER_TEST_PROPERTIES);
if (url == null) {
return null;
}
Properties properties = new Properties();
try {
try (InputStream in = url.openStream()){
properties.load(in);
}
} catch (IOException e) {
throw new RuntimeException(e);
}

String preferredTransport = properties.getProperty(PREFERRED_TRANSPORT);
Assertions.assertNotNull(preferredTransport);
return preferredTransport;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The loadPreferredTransportFromProperties method is very similar to the one in server-common/src/test/java/io/a2a/server/requesthandlers/AbstractA2ARequestHandlerTest.java. To improve maintainability and avoid code duplication, consider extracting this logic into a shared test utility class.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Won't fix

@kabir kabir force-pushed the transport-warning branch from 9ac1e19 to d186f8c Compare September 3, 2025 16:01
@kabir kabir force-pushed the transport-warning branch from d186f8c to 8c6c718 Compare September 4, 2025 10:41
@kabir
Copy link
Collaborator Author

kabir commented Sep 4, 2025

@fjuma Should be fixed now

@fjuma fjuma merged commit 8e70e48 into a2aproject:main Sep 4, 2025
3 of 4 checks passed
kabir added a commit to kabir/a2a-java that referenced this pull request Dec 23, 2025
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.

Log a warning if the transports specified in the AgentCard don't match the transports that are available on the classpath

2 participants