fix(openai): preserve native v1 stream contract #1627
+674
−46
Claude / Claude Code Review
completed
Apr 15, 2026 in 32m 39s
Code review timed out
The review session exceeded its time limit. Push another commit to retrigger.
Annotations
Check failure on line 928 in langfuse/openai.py
claude / Claude Code Review
Langfuse generation leaked when user breaks from stream loop without calling close()
The new native stream instrumentation introduces a regression: breaking from a `for chunk in stream:` loop without calling `stream.close()` leaves the Langfuse generation un-finalized until GC. This happens because `openai.Stream.__iter__` iterates `self._iterator` (an external attribute reference), and Python does not propagate `close()` to externally-referenced sub-generators when the outer generator is closed by a `break`. The previous `LangfuseResponseGeneratorSync.__iter__` had a `try/final
Loading