Skip to content

Fix _SameTaskStreamingResponse disconnect test bypassing __init__ - #6627

Merged
danielhanchen merged 2 commits into
mainfrom
fix-same-task-response-test-unstarted-cleanup
Jun 24, 2026
Merged

danielhanchen merged 2 commits into
mainfrom
fix-same-task-response-test-unstarted-cleanup

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Summary

The Backend CI "Repo tests (CPU)" job currently fails on main with:

FAILED tests/studio/test_stream_cancel_registration_timing.py::test_same_task_response_closes_body_iterator_on_send_disconnect - AttributeError: '_SameTaskStreamingResponse' object has no attribute '_unstarted_cleanup'

The test constructs _SameTaskStreamingResponse via __new__ to bypass Starlette's __init__, then wires body_iterator, background, and stream_response by hand. It never sets _unstarted_cleanup, so when the simulated disconnect fires before the first body chunk, the unstarted-generator branch of __call__ reads self._unstarted_cleanup and raises AttributeError instead of the expected ClientDisconnect.

The implementation is correct; the test was not updated to set the attribute when _unstarted_cleanup was added to __init__.

Change

Set response._unstarted_cleanup = None in the manual construction, matching the default __init__ assigns.

Tests

tests/studio/test_stream_cancel_registration_timing.py passes (25 passed), including the previously failing case.

test_same_task_response_closes_body_iterator_on_send_disconnect builds the
response via __new__ to skip Starlette's __init__, then wires body_iterator,
background, and stream_response by hand. It never set _unstarted_cleanup, so the
disconnect-before-first-chunk branch of __call__ raised AttributeError instead of
ClientDisconnect, failing the Backend CI "Repo tests (CPU)" job on main.

Set response._unstarted_cleanup = None in the manual construction, matching the
default __init__ assigns.
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@danielhanchen
danielhanchen merged commit 7a25266 into main Jun 24, 2026
22 checks passed
@danielhanchen
danielhanchen deleted the fix-same-task-response-test-unstarted-cleanup branch June 24, 2026 10:47
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.

1 participant