Skip to content

Fix ChatResponseUpdate.Clone dropping ContinuationToken - #7699

Open
dfedoryshchev wants to merge 1 commit into
dotnet:mainfrom
dfedoryshchev:fix/chatresponseupdate-clone-continuationtoken
Open

Fix ChatResponseUpdate.Clone dropping ContinuationToken#7699
dfedoryshchev wants to merge 1 commit into
dotnet:mainfrom
dfedoryshchev:fix/chatresponseupdate-clone-continuationtoken

Conversation

@dfedoryshchev

@dfedoryshchev dfedoryshchev commented Aug 13, 2026

Copy link
Copy Markdown

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
Author

@dotnet-policy-service agree

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant