-
Notifications
You must be signed in to change notification settings - Fork 285
fix(json-rpc): add stream_send_timeout for JSON-RPC streaming endpoints #549
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
fix(json-rpc): add stream_send_timeout for JSON-RPC streaming endpoints #549
Conversation
…uts to JSONRPCApplication, A2AStarletteApplication, and A2AFastAPIApplication to resolve timeout issues
…APIApplication and A2AStarletteApplication
Summary of ChangesHello @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 Highlights
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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.| event_generator(handler_result), headers=headers | ||
| event_generator(handler_result), | ||
| headers=headers, | ||
| send_timeout=send_timeout, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
| 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
| 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. |
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
EventSourceResponsewere being closed after 5 seconds by Starlette's defaultsend_timeout, causing issues when agents need more time to process and respond to requests.Solution
Added a configurable
stream_send_timeoutparameter to the JSON-RPC application classes:Fixes #545 🦕