Skip to content

feat: more robust check for finish reason in OpenAIResponsesChatGenerator - #12465

Open
sjrl wants to merge 1 commit into
mainfrom
fix/openai-responses-stream-metadata
Open

feat: more robust check for finish reason in OpenAIResponsesChatGenerator#12465
sjrl wants to merge 1 commit into
mainfrom
fix/openai-responses-stream-metadata

Conversation

@sjrl

@sjrl sjrl commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Related Issues

  • fixes #issue-number

Proposed Changes:

Like in OpenAIChatGenerator we scan the streaming chunks backwards to look for the last chunk that has a finish reason and usage attached to it instead of assuming its always the last one.

How did you test it?

Added new test.

Notes for the reviewer

Not sure how often this happens in practice, but we have observed it before with the chat completions API so we should bring the same logic over here to keep the responses chat generator similarly robust.

Checklist

  • I have read the contributors guidelines and the code of conduct.
  • I have updated the related issue with new insights and changes.
  • I have added unit tests and updated the docstrings.
  • I've used one of the conventional commit types for my PR title: fix:, feat:, build:, chore:, ci:, docs:, style:, refactor:, perf:, test: and added ! in case the PR includes breaking changes.
  • I have documented my code.
  • I have added a release note file, following the contributors guidelines.
  • I have run pre-commit hooks and fixed any issue.

@sjrl
sjrl requested a review from a team as a code owner August 25, 2026 08:48
@sjrl
sjrl requested review from bogdankostic and removed request for a team August 25, 2026 08:48
@vercel

vercel Bot commented Aug 25, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
haystack-docs Ignored Ignored Aug 25, 2026 8:48am

Request Review

@sjrl sjrl self-assigned this Aug 25, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  haystack/components/generators/chat
  openai_responses.py 934
Project Total  

This report was generated by python-coverage-comment-action

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant