fix(python): drain requests after repeated cancellation
Calling cancel() again while an async Python SDK request is still acknowledging its first cancellation can let the caller finish before its request worker has drained. Reuse the existing _await_cleanup helper so repeated cancellation still waits for that worker, then raises CancelledError. The regression uses client.session(...).terminal(...).wait() over a real local Unix socket, holds the cancellation acknowledgment, and confirms the same client can still ping afterward.
Testing
The focused regression fails on the rebased test-only commit dcfb31e186c700effcef0d73872adaccbc255d6a with request worker was not drained, and passes on head 01c92e9330400f97f7b168ce07798ae10a3b80b5. From cmux-tui/bindings/python/tests, the same command executes one test with no skips:
PYTHONPATH=.. python3 -m unittest test_resource_api.ResourceApiTests.test_aio_repeated_cancellation_drains_request_before_returning
Observed / Not run
- The full Python SDK suite passed 119 tests, zero skips on Python 3.9 in the current-head CI package job, including the regression and package-install test. The audit also passed all 119 tests locally on Python 3.13.3 using an isolated environment with the declared build prerequisite installed (
setuptools>=77). Command:PYTHONPATH=cmux-tui/bindings/python python3 -m unittest discover -v -s cmux-tui/bindings/python/tests. - Hosted Fast static checks passed all 16 checks on this head. Its project-normalizer suite has one existing platform skip; the local project-normalizer suite ran all 16 tests without skips. A separate local preflight with a 45-second command budget passed 12 checks and interrupted four unrelated checks; the full hosted recipe completed them. No test timeout or assertion was changed.
- Rebased onto
mainat36540f6194b746d48d47aa8963adbd0f1cd35cdbwithout conflicts. The published ancestry is retained for a plain push.git diff --checkpasses; the diff remains the two Python files. - No native app build, signing run, physical-device check, or live app check was performed for this Python SDK change. The regression exercises a disposable local Unix socket. Native app, CLI, packaging configuration, and signing files are unchanged.
Changelog
Fixed: Python async request cancellation waits for cleanup even when the caller is cancelled repeatedly.
AI-assisted with OpenAI Codex.
![View with [code]smith](https://pr-comments-assets.blacksmith.sh/codesmith/view-with-codesmith-dark-v3-3x.png)
![Autofix with [code]smith](https://pr-comments-assets.blacksmith.sh/codesmith/autofix-with-codesmith-dark-3x.png)
Need help on this PR? Tag @codesmith-bot with what you need.
Summary by CodeRabbit
- Bug Fixes
- Improved handling of repeated cancellation during terminal waits, ensuring cleanup finishes before cancellation completes.
- Added regression coverage for cancellation acknowledgment and subsequent client responsiveness.