Issue: 3930, Fix MessageChatMemoryAdvisor to handle message updates correctly #3940
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.
Summary
Fixes issue where MessageChatMemoryAdvisor incorrectly handles modified and resent messages by appending them as new messages
instead of replacing the original message and its response.
Fixes #3930
Problem
When a user modifies and resends an existing message, the current implementation:
This leads to inconsistent conversation history with duplicate/conflicting information.
Solution
Enhanced MessageChatMemoryAdvisor and related components to:
Key Changes
Backward Compatibility
✅ Fully backward compatible - existing functionality unchanged:
Test Coverage
Usage Example
// User sends initial message
UserMessage original = UserMessage.builder()
.text("What is the capital of France?")
.metadata(Map.of("messageId", "msg-001"))
.build();
// Later, user modifies and resends with same messageId
UserMessage updated = UserMessage.builder()
.text("What is the capital of Italy?")
.metadata(Map.of("messageId", "msg-001"))
.build();
// Result: Old message + response removed, new message added
Test Plan
Signed-off-by: Mattia Pasetto [email protected]
I am still pretty new to contributions, please double check and let me know of any errors.