Skip to content

Copy message lists when saving in-memory chat history - #6953

Merged
ilayaperumalg merged 1 commit into
spring-projects:mainfrom
pengmoubuaixuexi:fix/chat-memory-input-snapshot
Sep 10, 2026
Merged

ilayaperumalg merged 1 commit into
spring-projects:mainfrom
pengmoubuaixuexi:fix/chat-memory-input-snapshot

Conversation

@pengmoubuaixuexi

Copy link
Copy Markdown
Contributor

Fixes #6952

InMemoryChatMemoryRepository.saveAll retains a caller-owned list, so clearing or reusing that list after saving silently changes the stored conversation. Store a defensive list snapshot and add a regression test that clears the original list after saving and checks that the saved message remains.

The existing null validation and overwrite behavior are preserved. This snapshots the list structure; it does not deep-copy messages.

Validation: the new regression fails against the unmodified implementation. After the fix, all 31 repository/message-window tests pass. The scoped reactor build passes with formatting and Checkstyle checks:

./mvnw.cmd -B -pl spring-ai-model -am -Dtest=InMemoryChatMemoryRepositoryTests,MessageWindowChatMemoryTests -Dsurefire.failIfNoSpecifiedTests=false clean package

This does not include the full repository test suite or external integration tests. Environment: Windows 11, JDK 17.0.20.1, upstream commit 7374b63fcb6fd0e1950e70c9e04192a6826f2f2a.

AI assistance was used for source inspection, implementation, and test preparation. The contributor reviewed and approved the patch before submission.

Snapshot the supplied message list so subsequent caller mutations do not
silently change the saved conversation. Add a regression test that clears
the original list after saving and verifies that the message remains.

Fixes spring-projects#6952

Developed with assistance from Codex.

Signed-off-by: Tao Peng <[email protected]>
@ilayaperumalg ilayaperumalg self-assigned this Sep 10, 2026
@ilayaperumalg ilayaperumalg added this to the 2.0.2 milestone Sep 10, 2026
@ilayaperumalg
ilayaperumalg merged commit c7f7c73 into spring-projects:main Sep 10, 2026
5 checks passed
@ilayaperumalg

Copy link
Copy Markdown
Member

@pengmoubuaixuexi Thanks for the PR fixing the issue.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

InMemoryChatMemoryRepository retains the caller's mutable message list

3 participants