Repository navigation
fix(sdk-py): keep with_timeout() from cancelling the shared run-completion future (#9609) - #9625
Closed
AaronG (AaronG18) wants to merge 1 commit into
Conversation
Contributor
|
This PR has been automatically closed because you are not assigned to the linked issue. External contributors must be assigned to an issue before opening a PR for it. Please:
Maintainers: reopen this PR or remove the |
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 #9609
Problem
thread.output.with_timeout(s)documents that it returns a fresh awaitable and leaves the originalthread.outputunaffected. It did not:_OutputAwaitable._fetch()passed_wait_for_run_done()straight intoasyncio.wait_for, and_wait_for_run_done()awaits the shared_run_donefuture directly. On timeout,wait_forcancels the task it awaits and that cancellation propagates into_run_doneitself. Every laterawait thread.outputthen raisesCancelledError, and a later run failure is hidden by the cancellation.Fix
Shield the shared future during the bounded wait:
A timeout now cancels only the bounded waiter. This follows the existing pattern in the same module (
stream.py:1849,await asyncio.wait_for(asyncio.shield(gate), timeout=timeout)) and leaves the "a cancelled task is not respawned" behaviour untouched for callers that wrapthread.outputinasyncio.wait_forthemselves. Scope: one line of behaviour plus a comment, no public API change.Regression test
test_output_with_timeout_does_not_cancel_original_outputintests/streaming/test_thread_stream.py:with_timeout(0.01)expire while the lifecycle is still in flight,thread.outputstill resolves to the final state.Red before the fix (
CancelledErroratstream.py:1977,return await self._run_done), green after. No network or credentials are needed (httpx ASGITransport FakeServer).Test results
pytest tests/streaming/test_thread_stream.py tests/streaming/test_lifecycle_watcher.py -q-> 80 passedpytest tests/streaming/test_thread_stream.py -q -k with_timeout-> 4 passed (3 existing + 1 new)Single commit based on current upstream
main(e5e37b5d7).