fix(stream): close callback coroutines when task submission fails - #929
Conversation
|
The callback cleanup passes all upstream CI checks. The full macOS suite reports 7,821 passed, 14 skipped and 26 warnings; quality and Windows encoding checks also pass. The new cleanup regressions pass, and the handler-specific coroutine warnings are absent. CI actually used Python 3.14.7 despite the 3.13 job label; local qualification used 3.13.13. Remaining warning categories were inspected (plugin httpx deprecations, SQLite resources, deprecated config APIs and unrelated test coroutines), not suppressed; not every CI warning has an independent base reproduction. No warning-free or release-qualification claim. Run: https://github.com/mpfaffenberger/code_puppy/actions/runs/34231189528 |
|
Accidentally merged this lol... feel free to reopen. It's reverted. |
Stream callback scheduling failures currently leave an unawaited coroutine behind. Close the callback only when task submission fails, avoiding resource warnings while preserving cancellation and normal asynchronous delivery.
Problem and change
_fire_stream_eventconstructs a callback coroutine beforeasyncio.create_taskcan accept it. If scheduling raises, no task owns that coroutine. Retain it locally, close it on failed submission, and re-raise into the existing error handling. Successfully scheduled callbacks remain task-owned.The tests also use synchronous mocks for synchronous import/lookup failures rather than manufacturing unrelated unawaited mock coroutines.
Related upstream work
Validation
Base:
ce1fe372(0.0.827). Linux / Python 3.13.13, dedicated environment using PydanticAI 2.35.0 and core plugins 0.0.44. Disposable HOME/XDG; socket connect/DNS/bind blocked.No dependency changes, renderer changes, or live-provider claims. Public CI results will be added after completion.