spring-projects / spring-projects/spring-ai

MessageChatMemoryAdvisor does not handle user message modification correctly

Open
#3,930 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

status: waiting-for-triage
Dominant language
Java
Stars
9.5k
Forks
2.9k
Avg merge
1d 7h
Merged PRs (30d)
6

Description

Please do a quick search on GitHub issues first, there might be already a duplicate issue for the one you are about to create.
If the bug is trivial, just go ahead and create the issue. Otherwise, please take a few moments and fill in the following sections:

Bug description
The MessageChatMemoryAdvisor.before method does not properly handle the case when a user modifies an existing user message that has already received a response from the AI model.
Currently, when a user resends a modified message:
The old user message remains in the chat memory
The corresponding assistant response to that old message also remains in the chat memory
The new user message is simply appended to the memory
This leads to inconsistent chat history where both the old and new versions of a message (and their respective responses) exist in the conversation.

Environment
version: 1.0.0 and main

Steps to reproduce

  1. in before method add log for example:chatClientRequest.prompt().getInstructions();
  2. send userMessage and modify it;
  3. see log old userMessage is exist ;

Expected behavior
When a user sends a message that already exists in the chat history:
The existing user message should be removed from memory
The assistant response to that message should also be removed from memory
The new user message should be added to the memory
A new assistant response should be generated and added to the memory

Minimal Complete Reproducible example
in before method add log for example:chatClientRequest.prompt().getInstructions();
send userMessage and modify it; see log old userMessage is exist ;

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in MessageChatMemoryAdvisor.before and reproduce the behavior by logging chatClientRequest.prompt().getInstructions() while modifying and resending a user message. Trace how the existing user message and assistant response are handled in chat memory. Done means the old pair is removed, the modified user message is retained, and a new assistant response can be added without duplicate history.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
ai, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.