Skip to content

refactor(client): allow transport agnostic per invocation timeouts#776

Merged
ishymko merged 3 commits into1.0-devfrom
ishymko/763-client-timeouts
Mar 6, 2026
Merged

refactor(client): allow transport agnostic per invocation timeouts#776
ishymko merged 3 commits into1.0-devfrom
ishymko/763-client-timeouts

Conversation

@ishymko
Copy link
Member

@ishymko ishymko commented Mar 6, 2026

Replace magic http_kwargs key with explicit timeout property on ClientCallContext.

Fixes #763.

Replace magic `http_kwargs` key with explicit `timeout` property on `ClientCallContext`.
@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 refactors the client-side timeout mechanism to provide a more explicit and transport-agnostic way to specify per-invocation timeouts. By introducing a dedicated timeout property on the ClientCallContext, it eliminates the reliance on magic http_kwargs and centralizes timeout handling across gRPC, JSON-RPC, and REST transports, improving clarity and maintainability.

Highlights

  • Per-invocation Timeout: Introduced a dedicated timeout property to ClientCallContext for specifying per-invocation timeouts, replacing the previous reliance on magic http_kwargs.
  • gRPC Transport Refactor: Refactored the gRPC client transport to centralize call logic into new _call_grpc and _call_grpc_stream helper methods, which now consistently apply the ClientCallContext timeout.
  • JSON-RPC and REST Transport Updates: Updated JSON-RPC and REST client transports to utilize the new timeout property from ClientCallContext for HTTP requests.
  • Comprehensive Testing: Added new unit tests and updated existing ones across gRPC, JSON-RPC, and REST transports to ensure the correct propagation and application of the new per-invocation timeout.
Changelog
  • src/a2a/client/middleware.py
    • Added a timeout: float | None field to the ClientCallContext class.
  • src/a2a/client/transports/grpc.py
    • Replaced direct stub calls with new internal _call_grpc and _call_grpc_stream helper methods for all gRPC operations.
    • Implemented _get_grpc_timeout to retrieve the timeout from ClientCallContext.
    • Implemented _call_grpc to handle non-streaming gRPC calls, applying metadata and the new timeout.
    • Implemented _call_grpc_stream to handle streaming gRPC calls, applying metadata and the new timeout, and managing stream reading.
  • src/a2a/client/transports/jsonrpc.py
    • Modified _get_http_args to construct http_kwargs with an httpx.Timeout object based on the ClientCallContext.timeout property, if present.
  • src/a2a/client/transports/rest.py
    • Modified _get_http_args to construct http_kwargs with an httpx.Timeout object based on the ClientCallContext.timeout property, if present.
  • tests/client/transports/test_grpc_client.py
    • Added test_send_message_with_timeout_context to verify that the ClientCallContext timeout is correctly passed to the gRPC stub.
    • Updated several existing test cases to explicitly include timeout=None in the ClientCallContext for consistency.
  • tests/client/transports/test_jsonrpc_client.py
    • Added test_send_message_with_timeout_context to confirm that the ClientCallContext timeout is correctly applied to httpx.build_request.
  • tests/client/transports/test_rest_client.py
    • Added test_send_message_with_timeout_context to confirm that the ClientCallContext timeout is correctly applied to httpx.build_request.
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 how client call timeouts are handled by introducing an explicit timeout property on ClientCallContext, replacing the use of a magic http_kwargs key. The changes are well-implemented across the gRPC, JSON-RPC, and REST transports, including good refactoring in the gRPC transport to reduce code duplication. The new functionality is also well-tested. I have one minor suggestion for the REST transport to ensure type consistency.

@ishymko ishymko force-pushed the ishymko/763-client-timeouts branch from 61d653d to c3ee5f9 Compare March 6, 2026 10:19
@ishymko ishymko force-pushed the ishymko/763-client-timeouts branch from c3ee5f9 to 63e9d74 Compare March 6, 2026 10:22
@ishymko ishymko marked this pull request as ready for review March 6, 2026 10:23
@ishymko ishymko requested a review from a team as a code owner March 6, 2026 10:23
@ishymko ishymko merged commit 3146189 into 1.0-dev Mar 6, 2026
9 checks passed
@ishymko ishymko deleted the ishymko/763-client-timeouts branch March 6, 2026 10:27
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.

2 participants