Skip to content

refactor: extract shared SSE event handling into SPI module#624

Merged
kabir merged 1 commit intoa2aproject:mainfrom
ehsavoie:issue_623
Feb 5, 2026
Merged

refactor: extract shared SSE event handling into SPI module#624
kabir merged 1 commit intoa2aproject:mainfrom
ehsavoie:issue_623

Conversation

@ehsavoie
Copy link
Collaborator

@ehsavoie ehsavoie commented Feb 5, 2026

Create client-transport-spi module with AbstractSSEEventListener to eliminate code duplication between jsonrpc and rest transport implementations.

  • Add AbstractSSEEventListener with common event/error handling logic
  • Refactor jsonrpc and rest SSEEventListener to extend base class
  • Add comprehensive test coverage for shared functionality

Fixes #623 🦕

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @ehsavoie, 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 significantly improves the maintainability and consistency of Server-Sent Events (SSE) handling across different client transport mechanisms. By extracting common logic into a new Service Provider Interface (SPI) module, it centralizes event processing, error management, and connection auto-closure, reducing redundant code and simplifying future enhancements.

Highlights

  • New SPI Module for SSE Event Handling: A new client-transport-spi module has been introduced, containing an AbstractSSEEventListener to centralize common Server-Sent Events (SSE) handling logic.
  • Refactored SSE Event Listeners: Both the JSON-RPC and REST transport implementations of SSEEventListener have been refactored to extend the new AbstractSSEEventListener, eliminating code duplication for error handling and connection lifecycle management.
  • Enhanced Test Coverage: Comprehensive test coverage has been added for the shared functionality in the new SPI module, and existing tests for the JSON-RPC SSE listener have been updated to reflect the changes.
Changelog
  • .gitignore
    • Added .bob/ to the ignore list.
  • client/transport/jsonrpc/src/main/java/io/a2a/client/transport/jsonrpc/sse/SSEEventListener.java
    • Refactored to extend AbstractSSEEventListener.
    • Removed duplicated fields (eventHandler, errorHandler) and the onError method, now inherited from the base class.
    • Updated onComplete and message parsing logic to delegate to the abstract base class methods.
  • client/transport/jsonrpc/src/test/java/io/a2a/client/transport/jsonrpc/sse/SSEEventListenerTest.java
    • Added a new test case (testFinalTaskStatusUpdateEventCancels) to verify the auto-cancellation of futures for final events, now handled by the base class.
  • client/transport/rest/src/main/java/io/a2a/client/transport/rest/RestTransport.java
    • Updated imports and instantiation to use the refactored SSEEventListener (which now extends AbstractSSEEventListener).
  • client/transport/rest/src/main/java/io/a2a/client/transport/rest/sse/RestSSEEventListener.java
    • This file has been removed, as its functionality has been absorbed by the new abstract base class and the new SSEEventListener.
  • client/transport/rest/src/main/java/io/a2a/client/transport/rest/sse/SSEEventListener.java
    • New file: This is the new REST-specific SSE event listener, extending AbstractSSEEventListener and implementing REST-specific message parsing, while delegating common event handling to the base class.
  • client/transport/rest/src/test/java/io/a2a/client/transport/rest/sse/SSEEventListenerTest.java
    • New file: Provides comprehensive test coverage for the new REST SSE event listener, including JSON parsing and verification of delegated common logic.
  • client/transport/spi/src/main/java/io/a2a/client/transport/spi/sse/AbstractSSEEventListener.java
    • New file: Defines the abstract base class for SSE event listeners, centralizing eventHandler, errorHandler, onError, handleEvent (including auto-close logic for final events), and shouldAutoClose methods.
  • client/transport/spi/src/main/java/io/a2a/client/transport/spi/sse/package-info.java
    • New file: Added for package-level annotations within the new SPI module.
  • client/transport/spi/src/test/java/io/a2a/client/transport/spi/sse/SSEEventListenerTest.java
    • New file: Contains dedicated tests for the AbstractSSEEventListener, ensuring its common logic for error handling and auto-closing on final events functions correctly.
Activity
  • The author, ehsavoie, created this pull request to refactor SSE event handling, aiming to reduce code duplication between JSON-RPC and REST transport implementations.
  • A new client-transport-spi module was introduced to house the shared AbstractSSEEventListener.
  • Existing SSEEventListener classes in jsonrpc and rest modules were updated to extend this new abstract class.
  • Extensive new test files were added for the abstract base class and the refactored REST SSE listener, ensuring the new architecture is robust.
  • An existing test in the jsonrpc module was modified to align with the new inheritance structure.
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 the Server-Sent Events (SSE) listener implementation by introducing an AbstractSSEEventListener in a new spi package. This abstract class centralizes common logic for event handling, error handling, and auto-closing SSE connections when final task events are received. The existing SSEEventListener in the jsonrpc transport and a newly created SSEEventListener in the rest transport (replacing the deleted RestSSEEventListener) now extend this abstract base class, delegating common responsibilities to it while retaining their transport-specific message parsing logic. Corresponding test files were added for the abstract class and updated/created for the concrete implementations to ensure the new structure and auto-close behavior function correctly. A minor change also added .bob/ to the .gitignore. A review comment suggested adding a @Nullable annotation to the errorHandler parameter in the rest package's SSEEventListener constructor for API consistency.

Create client-transport-spi module with AbstractSSEEventListener to eliminate
code duplication between jsonrpc and rest transport implementations.

- Add AbstractSSEEventListener with common event/error handling logic
- Refactor jsonrpc and rest SSEEventListener to extend base class
- Add comprehensive test coverage for shared functionality

fix: issue a2aproject#623

Signed-off-by: Emmanuel Hugonnet <ehugonne@redhat.com>
@kabir kabir merged commit 168ff2d into a2aproject:main Feb 5, 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.

Look at unifying the SSE client auto-close code in the SSEListeners

2 participants