Bound direct subscription cleanup without delaying remote exits

KL
2mo ago
+209-28

Extract subscription cleanup from #3511. Direct connections wait up to five seconds for handler cleanup, including when the closing task is cancelled; remote subscription exits leave courtesy cancellation writes to the session-owned driver instead of waiting for them.

Keep the behavior, regression tests, and documentation together. Slot reuse and cross-task cancellation run on both AnyIO backends; timeout and blocked-write cases use Trio's mock clock.

Validation

macOS, Python 3.14: ./scripts/test passes with 6,019 passed, 9 skipped, 1 xfailed, 100% line/branch coverage, and strict-no-cover passing. Ruff lint/format and Pyright pass.

Also validated independently on main: 5,975 passed with 100% coverage and strict-no-cover. The subscription module passes all 37 cases on Python 3.10.

Stack

Part 3 of 5, stacked on #3541 for a focused review diff. The subscription change is independent of the preceding server fixes and does not require an HTTPX2 update.

AI Disclaimer

This PR was developed with the assistance of either Claude or Codex. I've reviewed and verified the changes.