Skip to content

[release/10.8] Fix ImageGeneratingChatClient duplicating preceding content and dropping following content - #7624

Merged
jeffhandley merged 3 commits into
release/10.8from
backport/pr-7622-to-release/10.8
Jul 13, 2026
Merged

[release/10.8] Fix ImageGeneratingChatClient duplicating preceding content and dropping following content#7624
jeffhandley merged 3 commits into
release/10.8from
backport/pr-7622-to-release/10.8

Conversation

@github-actions

@github-actions github-actions Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Backport of #7622 to release/10.8

/cc @jeffhandley @copilot

Summary

ReplaceImageGenerationFunctionResults iterated the content list in reverse.
CopyList(contents, i) captured the items before an image-generation match, then
the reverse loop re-appended those same preceding items (duplicating them) and
silently dropped items after the match (visited while newContents was still
null). 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
ImageGeneratingChatClient in Microsoft.Extensions.AI (opt-in behind the
MEAI001 diagnostic). When an assistant message mixes an image-generation call
with any other content (FunctionResultContent, UsageContent, text), preceding
content is duplicated and following content is dropped — [A, ImageGenCall, B]
produced [A, ImageGenerationToolCallContent, A], losing B and duplicating
A. Hits both streaming and non-streaming paths. Limited to preview users on the
experimental 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 the
content 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-ci is running (CLA green); no lab
testing 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

Copilot AI and others added 3 commits July 13, 2026 21:26
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@github-actions
github-actions Bot requested a review from a team as a code owner July 13, 2026 21:26
@jeffhandley
jeffhandley enabled auto-merge (squash) July 13, 2026 21:43
@jeffhandley
jeffhandley disabled auto-merge July 13, 2026 21:46
@jeffhandley
jeffhandley merged commit 3c7051e into release/10.8 Jul 13, 2026
1 of 4 checks passed
@jeffhandley
jeffhandley deleted the backport/pr-7622-to-release/10.8 branch July 13, 2026 21:46
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 13, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants