You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix: properly close streaming messages when finish_reason is present
Add fallback logic to detect streaming completion using finish_reason
when is_final_response returns False but finish_reason is set.
**Problem:**
Gemini returns events with partial=True and is_final_response()=False
even on the final chunk that contains finish_reason="STOP". This caused
streaming messages to remain open and require force-closing, resulting
in warnings.
**Solution:**
Enhanced should_send_end logic to check for finish_reason as a fallback:
- Check if finish_reason attribute exists and is truthy
- If streaming is active and finish_reason is present, emit TEXT_MESSAGE_END
- Formula: should_send_end = (is_final_response and not is_partial) or
(has_finish_reason and self._is_streaming)
**Testing:**
✅ All 277 tests pass
✅ Added test_partial_with_finish_reason to verify the fix
✅ Eliminates "Force-closing unterminated streaming message" warnings
✅ Properly emits TEXT_MESSAGE_END for events with finish_reason
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>
0 commit comments