Skip to content

Fix BlockingPortal thread leak in sync stream iteration #238

Description

@Kamilbenkirane

Symptom: CI hangs for 19 minutes after tests finish. Process never exits.

Root cause: _cleanup_portal() only fires on natural stream exhaustion (StopAsyncIteration). Exception, break, or abandoned streams leak the BlockingPortal thread.

Fix: Replace __iter__ returning self + __next__ with a generator-based __iter__. Python guarantees generator finally blocks run on exhaustion, break, exception, and GC.

Also fixes Pydantic V2.11 deprecation warning: tool.model_fieldstype(tool).model_fields in 4 tool mapper files.

Files:

  • src/celeste/streaming.py
  • src/celeste/protocols/openresponses/tools.py
  • src/celeste/providers/google/generate_content/tools.py
  • src/celeste/providers/groq/chat/tools.py
  • src/celeste/providers/moonshot/chat/tools.py

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions