[release/10.8] Fix ImageGeneratingChatClient duplicating preceding content and dropping following content - #7624
Merged
Conversation
…dd regression tests
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
jozkee
approved these changes
Jul 13, 2026
jeffhandley
enabled auto-merge (squash)
July 13, 2026 21:43
jeffhandley
approved these changes
Jul 13, 2026
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Backport of #7622 to release/10.8
/cc @jeffhandley @copilot
Summary
ReplaceImageGenerationFunctionResultsiterated the content list in reverse.CopyList(contents, i)captured the items before an image-generation match, thenthe reverse loop re-appended those same preceding items (duplicating them) and
silently dropped items after the match (visited while
newContentswas stillnull). The fix switches to forward iteration, so the prefix is captured once and
the remaining items are appended in order. One-line logic change in a single
method of an experimental client.
Customer Impact
Reported by a customer in #7620. Affects the experimental
ImageGeneratingChatClientinMicrosoft.Extensions.AI(opt-in behind theMEAI001diagnostic). When an assistant message mixes an image-generation callwith any other content (
FunctionResultContent,UsageContent, text), precedingcontent is duplicated and following content is dropped —
[A, ImageGenCall, B]produced
[A, ImageGenerationToolCallContent, A], losingBand duplicatingA. Hits both streaming and non-streaming paths. Limited to preview users on theexperimental feature, with no clean workaround short of post-processing the
result.
Regression?
Not a regression from a stable release. The defect existed since the feature was
introduced in #6749 ("Image generation tool", merged 2025-11-07) and has shipped
in every build carrying the experimental
ImageGeneratingChatClient.Testing
Added regression tests in
ImageGeneratingChatClientTests.cs(148 lines):[Theory]cases placing the image call at the start, middle, and end of thecontent list with mixed surrounding items, for both the non-streaming and
streaming paths. They assert exact content count, order, and cardinality; they
fail pre-fix and pass post-fix.
extensions-ciis running (CLA green); no labtesting beyond unit tests.
Risk
Low. A single loop-direction change (4 added / 3 deleted) in one method of an
experimental, opt-in client. No public API surface or package-authoring changes.
New start/middle/end tests cover the corrected ordering on both paths; no other
components are touched.
Microsoft Reviewers: Open in CodeFlow