Skip to content

fix(openai): record stream iteration errors - #2056

Open
Boulea7 wants to merge 1 commit into
langfuse:mainfrom
Boulea7:fix/2039-stream-generation-errors
Open

Boulea7 wants to merge 1 commit into
langfuse:mainfrom
Boulea7:fix/2039-stream-generation-errors

Conversation

@Boulea7

@Boulea7 Boulea7 commented Oct 23, 2026 •

Copy link
Copy Markdown

What does this PR do?

When an OpenAI stream yields partial output and then raises, record the generation as ERROR with the exception message. Keep partial output and usage, re-raise the original exception, and finalize once across native and fallback sync/async streams. Normal exhaustion, early closing, and cancellation retain their existing behavior.

Fixes #2039.

Type of change

  • Bug fix
  • New feature
  • Breaking change
  • Refactor
  • Documentation update
  • Tooling, CI, or repo maintenance

Verification

python -m pytest -p pytest_asyncio.plugin -p pytest_timeout tests/unit/test_openai.py tests/unit/test_openai_prompt_extraction.py -q --timeout=30
ruff check .
ruff format --check langfuse/openai.py tests/unit/test_openai.py
mypy langfuse --no-error-summary

68 tests passed; Ruff and mypy passed. The SSE regression tests use the real OpenAI client with httpx.MockTransport and an in-memory exporter. Verified with locked OpenAI 2.29.0; live-provider tests were not run.

Checklist

  • I self-reviewed the diff using code_review.md.
  • I added or updated tests for behavior changes.
  • I updated docs, examples, or .env.template if needed. (Not applicable.)
  • I did not hand-edit generated files; if generated files changed, I used the upstream regeneration path.
  • I did not commit secrets or credentials.

RetriggerView in GreptileConfidence Score: 5/5

This PR appears safe to merge; no actionable issues were found.

Summary

Records OpenAI stream iteration failures as ERROR with the exception message.

  • OpenAI streams record errors without losing the response chunks they already yielded.

No actionable issues were found. Tests were inspected but not run during this review.

Reviews (1) · Last reviewed commit: "fix(openai): record stream iteration err..." · Reviewed by Greptile

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

This branch has not been deployed

No deployments
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.

bug(openai): a stream that fails mid-iteration ends the generation without level ERROR

1 participant