Skip to content

Fix OpenAIResponsesChatClient streaming metadata to prevent model output merging into tool messages - #7970

Draft
caigen wants to merge 3 commits into
dotnet:mainfrom
caigen:agent-fix-/fix-openairesponseschatclient-streaming-metadata-3690118926c84f2b909b78b0af06015b
Draft

caigen wants to merge 3 commits into
dotnet:mainfrom
caigen:agent-fix-/fix-openairesponseschatclient-streaming-metadata-3690118926c84f2b909b78b0af06015b

Conversation

@caigen

@caigen caigen commented Nov 20, 2026 •

Copy link
Copy Markdown

Fixes #7954

Summary

Fixes #7954: early Responses streaming output could merge into a preceding tool message.

Changes

Default streaming metadata to Assistant while preserving explicit roles and message boundaries. Add eight deterministic SSE regression cases and update existing role expectations.

Validation

Local build and tests passed.

All eight regressions failed before the fix. Afterward, the affected library build and all 137 OpenAIResponseClientTests passed with normal analyzers enabled. Existing encrypted-reasoning roundtripping and function-call aggregation remain covered. No live API tests were run.

Risks

Early streaming updates intentionally report Assistant instead of null. MessageId handling and shared aggregation are unchanged.

Microsoft Reviewers: Open in CodeFlow

…put merging into tool messages

Request 3690118926c84f2b909b78b0af06015b; repair round 0.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions github-actions Bot added the area-ai Microsoft.Extensions.AI libraries label Nov 20, 2026
@caigen
caigen marked this pull request as ready for review November 21, 2026 05:36
@caigen
caigen requested a review from a team as a code owner November 21, 2026 05:36
Copilot AI balanced review requested due to automatic review settings November 21, 2026 05:36

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

There are no active review issues for the change that defaults early streaming updates to the Assistant role.

No open issues 🎉

What changed in this PR

Fixes #7954 by defaulting early OpenAI Responses streaming updates to the Assistant role, preventing model output from merging into preceding tool messages during aggregation.

Changes:

  • Initializes streaming role metadata to Assistant while preserving explicit roles and existing message boundaries.
  • Adds eight deterministic SSE regression cases covering synchronous and asynchronous aggregation of reasoning and compaction output.
  • Updates existing tests to expect Assistant rather than a null role.
File Description
test/​Libraries/​Microsoft.Extensions.AI.OpenAI.Tests/​OpenAIResponseClientTests.cs Adds aggregation regressions and updates streaming role expectations.
src/​Libraries/​Microsoft.Extensions.AI.OpenAI/​OpenAIResponsesChatClient.cs Defaults streaming role metadata to Assistant.

Review effort: Balanced

@caigen
caigen marked this pull request as draft November 21, 2026 12:39
caigen and others added 2 commits November 23, 2026 01:40
… out of tool messages

Request 3690118926c84f2b909b78b0af06015b; repair round 8.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
… out of tool messages

Request 3690118926c84f2b909b78b0af06015b; repair round 0.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

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

area-ai Microsoft.Extensions.AI libraries

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[MEAI.OpenAI] OpenAIResponsesChatClient streams reasoning and non-message items with Role=null, merging them into preceding Tool messages ```

2 participants