Skip to content

fix(openai): preserve native v1 stream contract

b818885
Select commit
Loading
Failed to load commit list.
Open

fix(openai): preserve native v1 stream contract #1627

fix(openai): preserve native v1 stream contract
b818885
Select commit
Loading
Failed to load commit list.
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

See this annotation in the file changed.

@claude 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