Skip to content

Fix OpenAI responses streaming to preserve encrypted reasoning content#7266

Open
stephentoub wants to merge 2 commits intodotnet:mainfrom
stephentoub:fixreasoning
Open

Fix OpenAI responses streaming to preserve encrypted reasoning content#7266
stephentoub wants to merge 2 commits intodotnet:mainfrom
stephentoub:fixreasoning

Conversation

@stephentoub
Copy link
Member

@stephentoub stephentoub commented Feb 5, 2026

Microsoft Reviewers: Open in CodeFlow

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request fixes a bug in OpenAI streaming responses where encrypted reasoning content was being lost during the streaming process. The fix ensures that when a ReasoningResponseItem contains encrypted content in the output_item.done event, that encrypted content is properly preserved and coalesced with the streamed text deltas, enabling correct roundtripping of encrypted reasoning data.

Changes:

  • Added streaming support for encrypted reasoning content by yielding a TextReasoningContent with only ProtectedData when encrypted content is present
  • Added comprehensive unit test for streaming encrypted content preservation
  • Added integration tests for roundtripping encrypted content in both streaming and non-streaming scenarios

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/Libraries/Microsoft.Extensions.AI.OpenAI/OpenAIResponsesChatClient.cs Added new case in streaming handler to yield encrypted content from ReasoningResponseItem when present, ensuring it gets coalesced with text deltas
test/Libraries/Microsoft.Extensions.AI.OpenAI.Tests/OpenAIResponseClientTests.cs Added unit test verifying that encrypted content is preserved through streaming and coalescing
test/Libraries/Microsoft.Extensions.AI.OpenAI.Tests/OpenAIResponseClientIntegrationTests.cs Added integration tests for both streaming and non-streaming roundtrip scenarios with encrypted content

…atClient.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-ai Microsoft.Extensions.AI libraries

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant