fix: defer model disposal until after input state flush when switching chat threads (#309115)#309158
Open
maruthang wants to merge 1 commit intomicrosoft:mainfrom
Open
fix: defer model disposal until after input state flush when switching chat threads (#309115)#309158maruthang wants to merge 1 commit intomicrosoft:mainfrom
maruthang wants to merge 1 commit intomicrosoft:mainfrom
Conversation
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.
Summary
Fixes #309115
Bug: Chat input prompt text was not saved when switching between threads, causing the user's in-progress prompt to be lost.
Root Cause: In
ChatViewPane.showModel(), the old model reference was disposed immediately viathis.modelRef.value = undefined, which triggered model serialization before the widget'ssetModelcall could flush the current input state to the outgoing model.Fix: Use
clearAndLeak()to extract the old reference without disposing it, then manually dispose it aftersetModelhas been called (which triggers the input state flush). Early-return and error paths also properly dispose the old reference to prevent leaks.Changes
src/vs/workbench/contrib/chat/browser/widgetHosts/viewPane/chatViewPane.ts: Replace immediatethis.modelRef.value = undefinedwithclearAndLeak()pattern that defers disposal until aftersetModelflushes input state. Added proper disposal in all early-return and error paths.src/vs/workbench/contrib/chat/test/common/model/chatModelStore.test.ts: Added 2 regression tests validating the disposal ordering behavior for issue Agents: Regression in chat input prompt being saved #309115.Testing