fix: close unconsumed cloud chat responses - #545
Open
rudycelekli wants to merge 1 commit into
Open
rudycelekli wants to merge 1 commit into
rudycelekli wants to merge 1 commit into
Conversation
Signed-off-by: Rudy Celekli <47457359+rudycelekli@users.noreply.github.com>
This branch has not been deployed
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.
Cloud streams open an HTTP response immediately, but closing their unstarted parser generator never enters its cleanup block. Managed
chat()additionally closes only an already opened view. As a result,.close()before the first iteration leaves the unread response and native socket open.Give cloud streaming iterators explicit ownership of the response and let the managed
ChatStreamclose its owned chunks even before a view starts. Cleanup remains idempotent, exhausted streams stay exhausted, and a parser cleanup exception still closes the response. Own-model streams retain lazy startup.Validation: native HTTP/1.1 tests reproduce four unread-stream failures plus two parser-cleanup failures, with 13 passing controls before the fix. All 19 focused tests pass; removing the owning iterator's final response cleanup makes both exception-path regressions fail. The complete local
python -m pytest -qpasses 604 tests, 218 skipped on macOS/Python 3.12/PDFium 5 without optional agent frameworks. No live provider calls were used; the hosted Python 3.10/3.13/framework/PDFium matrix remains required.