Skip to content

Fix ChatResponseUpdate.Clone dropping ContinuationToken - #7699

Merged
jozkee merged 1 commit into
dotnet:mainfrom
dfedoryshchev:fix/chatresponseupdate-clone-continuationtoken
Oct 7, 2026
Merged

jozkee merged 1 commit into
dotnet:mainfrom
dfedoryshchev:fix/chatresponseupdate-clone-continuationtoken

Conversation

@dfedoryshchev

@dfedoryshchev dfedoryshchev commented Aug 13, 2026 •

Copy link
Copy Markdown
Contributor

ChatResponseUpdate.Clone() assigns every settable property on the type except ContinuationToken, so the token is silently dropped from the clone. The doc comment says the result is "a new ChatResponseUpdate object with the same property values as the current instance", and ContinuationToken predates Clone(), so this reads as an omission rather than a deliberate exclusion.

It is reachable in the box. ImageGeneratingChatClient.GetStreamingResponseAsync clones an update whenever it rewrites that update's contents, and yields the clone in place of the original, so for those updates the consumer sees ContinuationToken == null. The remarks on ChatResponseUpdate.ContinuationToken tell callers to pass the token from the latest received update to ChatOptions.ContinuationToken in order to resume an interrupted background stream, which a clone cannot support.

Fix: copy ContinuationToken in Clone().

Validation: extended the existing Clone_CreatesShallowCopy test to set and assert ContinuationToken. Against unmodified sources it fails with

Assert.Same() Failure: Values are not the same instance
Expected: ResponseContinuationToken { }
Actual:   null

and passes with the change. Microsoft.Extensions.AI.Abstractions.Tests: 1642 passed, 0 failed, 1 skipped. Microsoft.Extensions.AI.Tests: 761 passed, 0 failed.

Microsoft Reviewers: Open in CodeFlow

Clone() copied every settable property except ContinuationToken, so a
cloned update lost the token needed to resume a background streaming
response.

Extended Clone_CreatesShallowCopy to cover the property.
@dfedoryshchev

Copy link
Copy Markdown
Contributor Author

@dotnet-policy-service agree

@github-actions github-actions Bot added the area-ai Microsoft.Extensions.AI libraries label Sep 24, 2026
@jozkee
jozkee merged commit 0f17b7d into dotnet:main Oct 7, 2026
7 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 6, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-ai Microsoft.Extensions.AI libraries

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants