Skip to content

Conversation

@devesh1011
Copy link

Description

This PR fixes issue #545 where JSON-RPC streaming endpoints were closing prematurely due to Starlette's default 5-second send timeout when agents take longer to respond.

Problem

JSON-RPC streaming connections using EventSourceResponse were being closed after 5 seconds by Starlette's default send_timeout, causing issues when agents need more time to process and respond to requests.

Solution

Added a configurable stream_send_timeout parameter to the JSON-RPC application classes:

Fixes #545 🦕

…uts to JSONRPCApplication, A2AStarletteApplication, and A2AFastAPIApplication to resolve timeout issues
@devesh1011 devesh1011 requested a review from a team as a code owner November 18, 2025 07:44
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @devesh1011, 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 provides a crucial fix for JSON-RPC streaming connections by introducing a configurable stream_send_timeout parameter. This enhancement prevents premature termination of streaming endpoints caused by Starlette's default timeout, ensuring that long-running agent responses can be fully delivered without interruption. The change improves the robustness and flexibility of the streaming architecture.

Highlights

  • Configurable Streaming Timeout: Introduced a new stream_send_timeout parameter to JSON-RPC application classes, allowing users to configure the timeout for streaming responses.
  • Addresses Premature Connection Closure: This change resolves an issue where JSON-RPC streaming endpoints were prematurely closed due to Starlette's default 5-second send_timeout, especially when agents required more time to respond.
  • Enhanced Agent Responsiveness: The new parameter enables support for long-running agents by allowing the timeout to be increased or disabled, preventing connection drops during extended processing.
  • Test Coverage: New test cases have been added for both FastAPI and Starlette applications to ensure the correct behavior and configurability of the stream_send_timeout parameter.
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 introduces a stream_send_timeout parameter to address premature closing of JSON-RPC streaming endpoints. The implementation correctly adds the configurable timeout to JSONRPCApplication and its subclasses for FastAPI and Starlette, and applies it to EventSourceResponse. The changes are accompanied by new unit tests.

My review focuses on improving the clarity of the documentation for the new parameter and enhancing test coverage to ensure the new timeout logic is fully verified. I've identified some inconsistencies in the docstrings and an opportunity to strengthen the tests.

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 added tests for fastapi_app and starlette_app verify that the stream_send_timeout parameter is stored correctly on the application instance. However, they don't test that this value is actually used when creating an EventSourceResponse in this method.

To ensure the core logic of this fix is working as intended, I recommend adding a test that mocks EventSourceResponse and asserts it's called with the correct send_timeout value, covering cases where it's set on the app, None, and overridden via the context.state. This would provide more confidence in the change.

Copy link
Contributor

Choose a reason for hiding this comment

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

low

The phrase 'in default timeout' is unclear. The docstring should also clarify that None disables the timeout, which is a change in the default behavior. For clarity and consistency, could you update it?

            stream_send_timeout: The timeout in seconds for sending events in
              streaming responses. Defaults to `None`, which disables the timeout.
              Set a float value to specify a timeout.

Comment on lines 544 to 210
event_generator(handler_result), headers=headers
event_generator(handler_result),
headers=headers,
send_timeout=send_timeout,
Copy link
Contributor

Choose a reason for hiding this comment

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

low

This docstring is contradictory. It first says Defaults to None, which uses Starlette's default timeout, and then says None to disable. The latter is correct: None disables the timeout. This is also a change in the default behavior (from a 5s timeout to no timeout), which is important to document. Please clarify the docstring.

Suggested change
stream_send_timeout: The timeout in seconds for sending events in
streaming responses. Defaults to None, which uses Starlette's
default timeout. Set to a larger value or None to disable for
long-running agents.
stream_send_timeout: The timeout in seconds for sending events in
streaming responses. Defaults to `None`, which disables the timeout.
This changes the default behavior from using Starlette's 5-second
default. Set a float value to specify a timeout.

Copy link
Contributor

Choose a reason for hiding this comment

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

low

This docstring is contradictory. It first says Defaults to None, which uses Starlette's default timeout, and then says None to disable. The latter is correct: None disables the timeout. This is also a change in the default behavior (from a 5s timeout to no timeout), which is important to document. Please clarify the docstring.

Suggested change
stream_send_timeout: The timeout in seconds for sending events in
streaming responses. Defaults to None, which uses Starlette's
default timeout. Set to a larger value or None to disable for
long-running agents.
stream_send_timeout: The timeout in seconds for sending events in
streaming responses. Defaults to `None`, which disables the timeout.
This changes the default behavior from using Starlette's 5-second
default. Set a float value to specify a timeout.

@devesh1011 devesh1011 changed the title Fix/jsonrpc streaming timeout fix(json-rpc): add stream_send_timeout for JSON-RPC streaming endpoints Nov 18, 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.

[Bug]: JSON-RPC streaming endpoints hard‑close when send() blocks longer than Starlette’s default timeout

1 participant