fix: catch CancelledError in agent router streaming functions#7323
Open
metaphorics wants to merge 1 commit intoagno-agi:mainfrom
Open
fix: catch CancelledError in agent router streaming functions#7323metaphorics wants to merge 1 commit intoagno-agi:mainfrom
metaphorics wants to merge 1 commit intoagno-agi:mainfrom
Conversation
The agent router streaming generators catch `except Exception` but not `asyncio.CancelledError` (a BaseException subclass). When Starlette cancels a disconnected client's SSE stream, CancelledError propagates unhandled through the agent generator. Handle CancelledError separately from Exception: clean return (client is gone, no error event needed) vs error event for real failures. This is more correct than the team router's broad `except BaseException` which also swallows SystemExit/KeyboardInterrupt. Fixes agno-agi#7320
Contributor
PR TriageMissing tests: This PR modifies source code but does not include any test changes. Please add or update tests to cover your changes. |
15 tasks
16 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #7320
Summary
except asyncio.CancelledError: returnbeforeexcept Exceptionin bothagent_response_streamerandagent_continue_response_streamerCancelledError(BaseException subclass) was propagating unhandled through agent router generators when Starlette cancels a disconnected client's SSE streamException: cleanreturnfor disconnections (client is gone, no error event needed) vs error event for real failuresexcept BaseExceptionwhich also swallowsSystemExit/KeyboardInterruptTest plan