`/clear` only clears the UI and keeps previous messages in model context
Description
The /clear slash command makes the current chat look empty, but it only clears the client-side message state. The persisted messages remain in the database and are loaded into the model context again when the user sends the next message in the same chat.
This makes the visible conversation state disagree with the context sent to the model.
Steps to reproduce
- Start a chat and send a memorable fact, for example:
My favorite color is teal. - Run the
/clearslash command. - Confirm that the messages disappear from the UI.
- In the same chat, ask:
What is my favorite color? - Refresh the page and observe that the old messages also return.
Expected behavior
Running /clear should clear the context represented by the UI. A subsequent request in that chat should not include messages that were cleared, and refreshing should not restore them.
Actual behavior
The model still receives the old messages and can answer from the supposedly cleared context. Refreshing restores the old conversation in the UI.
Cause
The command handler only calls setMessages(() => []):
The next request for the same chat reloads all persisted messages and prepends them to the new message:
Possible fix
Either clear the persisted message history for the current chat (including related records where appropriate), or make /clear start a new chat. In either case, the visible state, persisted state, and model context should remain consistent.
Source: vercel/chatbot