Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding fixing save chat session overwriting (#6457)
[Linear Issue ](https://linear.app/sourcegraph/issue/QA-216/jetbrains-clicking-on-delete-button-does-nothing-in-first-attempt-for) ### Problem Previously, whenever a user deleted a chat, disposeChat would call clearAndRestartSession(), which in turn triggered saveSession(). This saved the just-deleted chat back into local storage, negating the deletion. ## Solution Introduce a skipSave boolean to conditionally skip the clearAndRestartSession() flow during deletion. If skipSave is true (e.g., for a deletion), clearAndRestartSession() is not called. This prevents the race condition of re-saving an already-deleted chat. ## Why It Works 1. Avoid Conflicts – If the user explicitly wants to remove a chat, we no longer re-create or re-save the session. 2. Maintain Clean State – Normal operations (skipSave = false) still clear and restart sessions. Deletions (skipSave = true) skip that path to maintain data consistency. 3. Prevent Race Conditions – The skip logic ensures no stale data overwrites the freshly updated local storage. Using the skipSave flag to conditionally skip clearAndRestartSession() is safe because: 1. During normal operations (when skipSave is false), you want to clear and restart the session to maintain a clean state 2. During deletion (when skipSave is true), you want to skip this step because: The chat is being deleted anyway clearAndRestartSession() includes a saveSession() call which could race with the deletion 3. There's no need to create a new session when we're removing the chat The condition helps prevent potential issues where: - The deletion operation is trying to remove chat history - While simultaneously, clearAndRestartSession() might try to save the session - Which could lead to inconsistent state or race conditions So yes, using the skipSave flag to conditionally skip clearAndRestartSession() during deletion is a good practice for maintaining data consistency. ## Test plan Run this code in Vscode/Jetbrains debugger and delete a chat from history <!-- Required. See https://docs-legacy.sourcegraph.com/dev/background-information/testing_principles. --> ## Changelog <!-- OPTIONAL; info at https://www.notion.so/sourcegraph/Writing-a-changelog-entry-dd997f411d524caabf0d8d38a24a878c -->
- Loading branch information