feat(a2a): implement standardized normalization and streaming reassembly#21402
feat(a2a): implement standardized normalization and streaming reassembly#21402mattKorwel merged 3 commits intomainfrom
Conversation
|
Hi @alisa-alisa, thank you so much for your contribution to Gemini CLI! We really appreciate the time and effort you've put into this. We're making some updates to our contribution process to improve how we track and review changes. Please take a moment to review our recent discussion post: Improving Our Contribution Process & Introducing New Guidelines. Key Update: Starting January 26, 2026, the Gemini CLI project will require all pull requests to be associated with an existing issue. Any pull requests not linked to an issue by that date will be automatically closed. Thank you for your understanding and for being a part of our community! |
|
This is part of split PR : #21348 |
Summary of ChangesHello, 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 establishes foundational infrastructure for Agent-to-Agent (A2A) communication by introducing robust mechanisms for handling agent card data, securing network connections, and efficiently processing streaming responses. The changes ensure that agent information is consistently structured, URLs are safely resolved, and incremental updates are coherently reassembled, laying the groundwork for reliable agent interactions. 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 introduces significant and well-structured functionality for A2A communication. The addition of agent card normalization, robust URL parsing, and especially the security-focused pinUrlToIp function to prevent DNS rebinding are excellent improvements. The code is well-organized and the refactoring of A2AResultReassembler improves type safety. I've found one critical issue in the new pinUrlToIp function that could lead to an unhandled exception, for which I've left a specific comment.
51e02ec to
04b1ac3
Compare
8d10a1d to
f0ae3af
Compare
04b1ac3 to
0e8c9b6
Compare
f0ae3af to
d841e1f
Compare
0e8c9b6 to
c78e367
Compare
c78e367 to
f43956b
Compare
d841e1f to
7652006
Compare
f43956b to
2742c7c
Compare
|
Size Change: +1.59 kB (+0.01%) Total Size: 26.2 MB
ℹ️ View Unchanged
|
mattKorwel
left a comment
There was a problem hiding this comment.
This PR looks functionally sound (all builds, automated tests, and manual executions pass), but there are a few codebase rule violations that need to be addressed before it can be merged:
1. packages/core/src/agents/a2aUtils.ts (A2AResultReassembler.update)
Issue: The PR replaces an existing switch (chunk.kind) statement with a complex if/else if chain that uses newly introduced custom type guards.
Rule Violation: Avoid complex if statements where switch statements could be used.
2. packages/core/src/agents/a2aUtils.test.ts (Test Cleanup)
Issue: The test file uses beforeEach(() => { vi.clearAllMocks(); }); and mocks node:dns/promises at the top level.
Rule Violation: Always call vi.restoreAllMocks() in afterEach to prevent test pollution.
3. packages/core/src/agents/a2aUtils.test.ts (Typing in Tests)
Issue: The PR introduces multiple instances of // eslint-disable-next-line @typescript-eslint/no-explicit-any followed by ] as any); when mocking DNS lookup results.
Rule Violation: Avoid using any in tests; prefer proper types or unknown with narrowing.
4. packages/core/src/agents/a2aUtils.ts (Strict Typing)
Issue: The code accepts unknown and uses heavy double-casting (e.g., as unknown as AgentCard, as unknown as Record<...>, as unknown as AgentInterface) to bypass the TypeScript compiler, alongside eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion.
Rule Violation: Strictly forbid any and unknown in both CLI and Core packages. unknown is only allowed if it is immediately narrowed using type guards or Zod validation. Using a Zod schema to parse the incoming card is strongly recommended.
Please address these issues to ensure we maintain our codebase standards. Thank you!
…bly (google-gemini#21402) Co-authored-by: matt korwel <matt.korwel@gmail.com>
…bly (google-gemini#21402) Co-authored-by: matt korwel <matt.korwel@gmail.com>
…bly (google-gemini#21402) Co-authored-by: matt korwel <matt.korwel@gmail.com>
…bly (google-gemini#21402) Co-authored-by: matt korwel <matt.korwel@gmail.com>
Summary
This PR introduces the core infrastructure for A2A communication, focusing on standardized agent card normalization, robust URL parsing, and streaming response reassembly. It builds on the security foundation from PR #1 and includes critical fixes for DNS resolution resilience.
Details
a2aUtils.tsthat handles varied agent card formats. It ensurestransportandurlfields are consistently populated and correctly synchronized betweensupportedInterfacesandadditionalInterfaces.splitAgentCardUrlutility to correctly handle both base URLs and full URLs containing the standard.well-knownpath, preventing "path doubling" bugs during agent resolution.A2AResultReassemblerclass to reassemble incremental A2A streaming updates (status, messages, and artifacts) into a coherent, human-readable result.pinUrlToIpto explicitly handle cases where DNS resolution returns no addresses. The logic now correctly distinguishes between a hostname resolving only to private IPs (SSRF block) and a complete resolution failure, preventing potential TypeErrors and process crashes.pinUrlToIpto prevent DNS rebinding by pinning hostnames to their resolved IP addresses during the connection phase.Why this is needed
Remote agents provide information in varied formats depending on the protocol version and implementation (REST vs gRPC). This PR centralizes the "parsing brain" of the A2A system, ensuring that subsequent execution logic (like the Client Manager) can rely on a consistent and safe data structure.
Related Issues
Related to issue #18642.