fix: BlockingPortal thread leak in sync stream iteration#239
Merged
Kamilbenkirane merged 2 commits intomainfrom Mar 27, 2026
Merged
fix: BlockingPortal thread leak in sync stream iteration#239Kamilbenkirane merged 2 commits intomainfrom
Kamilbenkirane merged 2 commits intomainfrom
Conversation
Replace __iter__/__next__ with generator-based __iter__ using try/finally. Python guarantees generator finally blocks run on exhaustion, break, exception, and GC — fixing the portal leak that caused CI to hang. Also fix Pydantic V2.11 deprecation: tool.model_fields → type(tool).model_fields in 4 tool mapper files.
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. |
DeepSeek sends "tool_calls": null instead of omitting the key.
dict.get("tool_calls", []) returns None (key exists, value null).
Changed to `or []` to handle both missing and null.
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #238
Summary
__iter__/__next__with generator-based__iter__usingtry/finallyfor guaranteed portal cleanup on exhaustion, break, exception, and GCtool.model_fields→type(tool).model_fieldsin 4 tool mapper filesProblem
CI hung for 19 minutes after tests finished. The
BlockingPortalthread leaked when sync stream iteration ended by exception (Anthropic billing error),break, or abandonment — only natural exhaustion triggered cleanup.Files changed
src/celeste/streaming.py— generator-based__iter__, removed__next__and_cleanup_portalsrc/celeste/protocols/openresponses/tools.py— pydantic fixsrc/celeste/providers/google/generate_content/tools.py— pydantic fixsrc/celeste/providers/groq/chat/tools.py— pydantic fixsrc/celeste/providers/moonshot/chat/tools.py— pydantic fixTest plan