-
Notifications
You must be signed in to change notification settings - Fork 326
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: race condition in saving history before switching accounts #6487
base: main
Are you sure you want to change the base?
Conversation
@abeatrix So I want to make a test for this but the test for the account switching is flaky? Since this test would be built on top that test so what do i dO? |
Oh is it still flaky? I forgot to remove the skip after I updated it since switch account now works. Update: I marked it as flaky when switch account didn't work |
@abeatrix So I changed this to a test that technically works
This test checks for the condition that we want to test and when I run this with the debugger it runs slowly and gives me the right response
But the part where it switches the accounts happens so fast without the debugger that the frames get detched etc so that's why this is flaky. So we have 3 options
For now my recommendation is to go with Option 2 and if this ever bothers us again we skip these tests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left some commands inline that are not merge blocker.
this.activeEditor = undefined | ||
const oldEditors = this.editors | ||
this.editors = [] | ||
for (const editor of oldEditors) { | ||
if (editor.webviewPanelOrView) { | ||
disposeWebviewViewOrPanel(editor.webviewPanelOrView) | ||
} | ||
editor.dispose() | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this.activeEditor = undefined | |
const oldEditors = this.editors | |
this.editors = [] | |
for (const editor of oldEditors) { | |
if (editor.webviewPanelOrView) { | |
disposeWebviewViewOrPanel(editor.webviewPanelOrView) | |
} | |
editor.dispose() | |
} | |
this.disposeAllChats() |
This looks like it does the same thing as disposeAllChats method? On account switch, the new ChatBuilder(undefined) will be recreated, so it should be safe to saveSession? We should also look into not invoking saveSession when the chat is empty (unrelated to this PR) 👀
@@ -81,11 +81,31 @@ export class ChatsController implements vscode.Disposable { | |||
const hasSwitchedAccount = | |||
this.currentAuthAccount && | |||
this.currentAuthAccount.endpoint !== authStatus.endpoint | |||
if (hasLoggedOut || hasSwitchedAccount) { | |||
if (hasLoggedOut) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (hasLoggedOut) { | |
if (hasLoggedOut) { | |
this.disposeAllChats() | |
return |
Can we return early since the code below is doing the same thing without saving the session?
@@ -1912,10 +1912,11 @@ export class ChatController implements vscode.Disposable, vscode.WebviewViewProv | |||
}) | |||
} | |||
|
|||
public async clearAndRestartSession(chatMessages?: ChatMessage[]): Promise<void> { | |||
public async clearAndRestartSession(chatMessages?: ChatMessage[], shouldSave = true): Promise<void> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Q: Should we separate the secession step from this method if this has been causing issues?
Linear issue
Problem
When switching between Cody accounts, the last active chat would incorrectly appear in both accounts' chat histories. This happened because:
disposeAllChats()
was called which attempts to save the current chat statedisposeAllChats()
runs, thecurrentAuthAccount
had already been updated to the new accountSolution
Separated the logout and account switch logic:
disposeAllChats()
to properly save and clear chatsdisposeAllChats()
and directly dispose UI elements without savingsaveSession()
Test plan
Changelog