fix(#701): persist thread messages before switching to new chat#710
Open
shogun444 wants to merge 1 commit into
Open
fix(#701): persist thread messages before switching to new chat#710shogun444 wants to merge 1 commit into
shogun444 wants to merge 1 commit into
Conversation
Add optional cacheMessages method to ThreadStorage to allow storages to cache current messages before a thread switch. The default in-memory storage implements it by saving to the internal messages map. - ThreadStorage: add cacheMessages?(threadId, messages) — optional - _defaultStorage: implement cacheMessages to persist to in-memory Map - switchToNewThread: save current messages before clearing state - processMessage: persist messages after successful LLM streaming - Tests: verify cacheMessages is called in both paths with correct data
Contributor
Author
|
While testing this a bit more, I noticed another case that may be related. If I send a message and the assistant starts streaming a response (for example, generating a component), then quickly switch to another chat or click New Chat before the response finishes, and later come back to the original thread, the message I originally sent is sometimes gone as well. From what I've seen:
Actual:
I'm not sure if this is the same underlying issue or a separate race condition, but I was able to reproduce it multiple times while testing. |
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.
Closes #701
What
This PR addresses the message persistence issue when switching to a new chat by introducing an optional
cacheMessagesmethod toThreadStorage.The default in-memory storage implements this method by caching the current messages before the local state is cleared, allowing completed conversations to be restored when switching back to the thread.
Changes
cacheMessages(threadId, messages)toThreadStoragecacheMessagesin the default in-memory storageswitchToNewThread()clears the local stateTest Plan
Checklist