Repository navigation
fix(openai): capture refusals from streamed chat completions - #907
Open
pcbeingused333 wants to merge 2 commits into
Open
pcbeingused333 wants to merge 2 commits into
pcbeingused333 wants to merge 2 commits into
Conversation
A refused chat completion carries its text in `refusal` instead of `content`. The non-streaming path already records it as a text part, but the streaming path ignored `delta.refusal`, so a streamed refusal produced an output message with no parts. Buffer the refusal deltas per choice and emit them as a text part, as the non-streaming path does.
Signed-off-by: Alex Castillo <alex.castillog33@gmail.com>
Pull request dashboard statusWaiting on reviewers · refreshed 2026-10-17 03:25 UTC Review the latest changes. Status above doesn't look right?
|
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The focused fix preserves existing capture behavior and includes regression coverage for both streaming wrappers, with no blocking issues identified.
No open issues 🎉
What changed in this PR
Fixes missing refusal text in OpenAI streamed chat-completion telemetry, matching the existing non-streaming behavior.
Changes:
- Buffers refusal deltas and emits them as a text part.
- Adds buffer and sync/async streaming regression tests.
- Records the fix in the changelog.
| File | Description |
|---|---|
| instrumentation/opentelemetry-instrumentation-genai-openai/tests/test_choice_buffer.py | Tests refusal accumulation. |
| instrumentation/opentelemetry-instrumentation-genai-openai/tests/test_chat_stream_refusal.py | Tests sync/async refusal capture. |
| instrumentation/opentelemetry-instrumentation-genai-openai/src/opentelemetry/instrumentation/genai/openai/chat_wrappers.py | Captures refusal deltas in output messages. |
| instrumentation/opentelemetry-instrumentation-genai-openai/src/opentelemetry/instrumentation/genai/openai/chat_buffers.py | Adds per-choice refusal buffering. |
| instrumentation/opentelemetry-instrumentation-genai-openai/.changelog/907.fixed | Documents the fix. |
Review effort: Balanced
Author
|
/easycla |
pcbeingused333
force-pushed
the
fix/openai-stream-refusal
branch
from
October 17, 2026 03:25
3dbce2a to
05ee0eb
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Streamed chat completions that end in a refusal are now recorded with the refusal text. The non-streaming path already captures
message.refusalas a text part, but the streaming path ignoreddelta.refusal, so a streamed refusal produced an output message with no parts.Type of change
How has this been tested?
tests/test_chat_stream_refusal.py: a refusal streamed throughChatStreamWrapperandAsyncChatStreamWrapperis captured as one text part (fails on main).test_choicebuffer_append_refusalintests/test_choice_buffer.py.tests/of the package (without conformance): 528 passed, 13 skipped (main: 525 passed, 13 skipped).Checklist
This change was made with Claude Code; the tests above were run on main and on this branch.