Skip to content

fix: BlockingPortal thread leak in sync stream iteration#239

Merged
Kamilbenkirane merged 2 commits intomainfrom
fix/238-portal-leak
Mar 27, 2026
Merged

fix: BlockingPortal thread leak in sync stream iteration#239
Kamilbenkirane merged 2 commits intomainfrom
fix/238-portal-leak

Conversation

@Kamilbenkirane
Copy link
Copy Markdown
Member

Closes #238

Summary

  • Replace __iter__/__next__ with generator-based __iter__ using try/finally for guaranteed portal cleanup on exhaustion, break, exception, and GC
  • Fix Pydantic V2.11 deprecation: tool.model_fieldstype(tool).model_fields in 4 tool mapper files

Problem

CI hung for 19 minutes after tests finished. The BlockingPortal thread 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_portal
  • src/celeste/protocols/openresponses/tools.py — pydantic fix
  • src/celeste/providers/google/generate_content/tools.py — pydantic fix
  • src/celeste/providers/groq/chat/tools.py — pydantic fix
  • src/celeste/providers/moonshot/chat/tools.py — pydantic fix

Test plan

  • 475 unit tests pass
  • All pre-commit/pre-push hooks pass
  • Integration tests exit cleanly (no hang)

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.
@claude
Copy link
Copy Markdown

claude bot commented Mar 27, 2026

Code review

No 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.
@Kamilbenkirane Kamilbenkirane merged commit 8789c28 into main Mar 27, 2026
11 checks passed
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.

Fix BlockingPortal thread leak in sync stream iteration

1 participant