fix(openai): preserve native v1 stream contract #1627
Merged
Claude / Claude Code Review
completed
Apr 16, 2026 in 17m 29s
Code review found 1 important issue
Found 5 candidates, confirmed 2. See review comments for details.
Details
| Severity | Count |
|---|---|
| 🔴 Important | 1 |
| 🟡 Nit | 0 |
| 🟣 Pre-existing | 0 |
| Severity | File:Line | Issue |
|---|---|---|
| 🔴 Important | langfuse/openai.py:836-854 |
Async stream early-break leaves generation un-finalized (missing aiter hook) |
Annotations
Check failure on line 854 in langfuse/openai.py
claude / Claude Code Review
Async stream early-break leaves generation un-finalized (missing __aiter__ hook)
The sync early-break fix (commit 2dcc02b) has no async equivalent: `_install_openai_stream_iteration_hooks` only patches `openai.Stream.__iter__` and never installs a hook on `openai.AsyncStream.__aiter__`, and `_instrument_openai_async_stream` never sets `response._langfuse_finalize_once`. When a user does `async for chunk in stream: break`, Python closes the outer `__aiter__` generator but does not propagate `aclose()` to `self._iterator` (an attribute reference, not a frame-local), so `traced
Loading