Skip to content

fix(stream): close callback coroutines when task submission fails - #929

Merged
mpfaffenberger merged 1 commit into
mpfaffenberger:mainfrom
breedx:fix/upstream-stream-callback-cleanup
Sep 10, 2026
Merged

fix(stream): close callback coroutines when task submission fails#929
mpfaffenberger merged 1 commit into
mpfaffenberger:mainfrom
breedx:fix/upstream-stream-callback-cleanup

Conversation

@breedx

@breedx breedx commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

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_event constructs a callback coroutine before asyncio.create_task can 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.

  • Unpatched upstream: three failure-path controls fail, successful-task ownership control passes.
  • Candidate focused tests: 44 passed.
  • Agent suite: 468 passed, no warnings.
  • Unpatched existing-handler tests: 40 passed, 2 coroutine warnings, confirming the warning source.
  • Changed-file Ruff lint/format and diff checks pass.

No dependency changes, renderer changes, or live-provider claims. Public CI results will be added after completion.

@breedx

breedx commented Sep 8, 2026

Copy link
Copy Markdown
Contributor Author

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

@mpfaffenberger
mpfaffenberger merged commit 62d6ba9 into mpfaffenberger:main Sep 10, 2026
3 checks passed
@mpfaffenberger

mpfaffenberger commented Sep 10, 2026

Copy link
Copy Markdown
Owner

Accidentally merged this lol... feel free to reopen. It's reverted.

@breedx

breedx commented Sep 11, 2026

Copy link
Copy Markdown
Contributor Author

Following up on the reopen note: the actual revert PR #931 targets #924. This stream callback fix is still present in current main, so I have left it alone and resubmitted the reverted MCP preservation/shutdown patch as #932.

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.

2 participants