Skip to content

fix: properly handle errors in list_tasks JSON-RPC#698

Draft
ishymko wants to merge 1 commit into1.0-devfrom
ishymko/fix-list-tasks-error
Draft

fix: properly handle errors in list_tasks JSON-RPC#698
ishymko wants to merge 1 commit into1.0-devfrom
ishymko/fix-list-tasks-error

Conversation

@ishymko
Copy link
Member

@ishymko ishymko commented Feb 17, 2026

Fixes #697 (comment).

Follow-up for #697.

Re #559.

@ishymko ishymko requested a review from a team as a code owner February 17, 2026 16:28
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @ishymko, 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 deficiency in the list_tasks JSON-RPC endpoint's error handling mechanism. Previously, ServerError exceptions were caught but resulted in an empty or incomplete error response. The updated implementation ensures that when such an error occurs, a structured and informative error message is returned to the client, improving the robustness and debuggability of the API.

Highlights

  • Improved Error Handling: The list_tasks JSON-RPC endpoint now correctly handles ServerError exceptions by constructing a proper error response using _build_error_response, ensuring that specific error details or a generic InternalError are returned.
Changelog
  • src/a2a/server/request_handlers/jsonrpc_handler.py
    • Modified the list_tasks function to properly handle ServerError exceptions by calling _build_error_response with the specific error or an InternalError.
Activity
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 aims to fix error handling in the list_tasks JSON-RPC method. While it correctly identifies a part of the code that needed fixing, the implementation introduces a NameError because request_id is not defined. Additionally, it creates a type inconsistency where the method is declared to return a ListTasksResponse but would return a dict on error. My review provides a suggestion to fix the NameError and recommends a more thorough refactoring to align list_tasks with other methods in the class for consistency and correctness.

Comment on lines +403 to 406
except ServerError as e:
return _build_error_response(
request_id, e.error if e.error else InternalError()
)
Copy link
Contributor

Choose a reason for hiding this comment

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

critical

This change introduces a NameError because request_id is not defined in this scope. It also creates a type inconsistency: this method is declared to return ListTasksResponse, but _build_error_response returns a dict. This will cause issues with static type checking and potentially at runtime depending on how the return value is used.

The list_tasks method seems inconsistent with other methods in this class, which return a dict for the JSON-RPC response on both success and failure. To fix this properly, list_tasks should be refactored to align with the others. This would involve:

  1. Changing the return type hint to dict[str, Any].
  2. Getting request_id at the start of the method.
  3. Wrapping the success result in _build_success_response.

The suggestion below provides a minimal fix for the NameError. The type inconsistency will remain and should be addressed.

Suggested change
except ServerError as e:
return _build_error_response(
request_id, e.error if e.error else InternalError()
)
except ServerError as e:
request_id = self._get_request_id(context)
return _build_error_response(
request_id, e.error if e.error else InternalError()
)

@ishymko ishymko marked this pull request as draft February 17, 2026 16:33
self,
request: ListTasksRequest,
context: ServerCallContext | None = None,
) -> ListTasksResponse:
Copy link
Member

Choose a reason for hiding this comment

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

You might need to add another option for an error. Note, the other methods like on_get_task() return dicts.

Suggested change
) -> ListTasksResponse | JSONRPCError:

Double check what the correct type is for _build_error_response

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.

3 participants