Fix shared mutable state in chat options builder clone()#6498
Open
subhashpolisetti wants to merge 1 commit into
Open
Fix shared mutable state in chat options builder clone()#6498subhashpolisetti wants to merge 1 commit into
clone()#6498subhashpolisetti wants to merge 1 commit into
Conversation
The builder clone() methods in several ChatOptions implementations copied mutable collection fields by reference instead of creating independent copies, so a builder obtained via clone() shared those collections with its source and mutating one affected the other. This mirrors the fix applied to AnthropicChatOptions in spring-projects#6487 and aligns each clone() with the defensive copying these builders already perform in combineWith() and that the base ChatOptions and tool-calling builders already perform in their own clone(). Affected builders: BedrockChatOptions (requestParameters), DeepSeekChatOptions (tools), GoogleGenAiChatOptions (safetySettings, labels), MistralAiChatOptions (tools), and OpenAiChatOptions (customHeaders, logitBias, outputModalities, metadata, and the previously uncopied extraBody). See spring-projects#6487 Signed-off-by: subhash polisetti <subhashr161347@gmail.com>
Member
|
LGTM |
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The builder
clone()methods in severalChatOptionsimplementations copied mutable collection fields by reference instead of creating independent copies. A builder obtained viaclone()therefore shared those collections with its source, so mutating one affected the other.This mirrors the fix applied to
AnthropicChatOptionsin #6487 and aligns eachclone()with the defensive copying these builders already perform incombineWith(), and that the baseChatOptionsbuilder (stopSequences) and the tool-calling builder (toolCallbacks,toolContext) already perform in their ownclone().Affected builders:
BedrockChatOptions—requestParametersDeepSeekChatOptions—toolsGoogleGenAiChatOptions—safetySettings,labelsMistralAiChatOptions—toolsOpenAiChatOptions—customHeaders,logitBias,outputModalities,metadata, and the previously uncopiedextraBodyTesting:
Added regression tests for each builder that explicitly fail on the previous aliasing behavior.
Added null-safety tests for each modified clone() method.
Note: I am happy to split this into per-module PRs if you would prefer separate reviews.
See #6487