Skip to content

fix: defer model disposal until after input state flush when switching chat threads (#309115)#309158

Open
maruthang wants to merge 1 commit intomicrosoft:mainfrom
maruthang:fix/issue-309115-chat-prompt-not-saved
Open

fix: defer model disposal until after input state flush when switching chat threads (#309115)#309158
maruthang wants to merge 1 commit intomicrosoft:mainfrom
maruthang:fix/issue-309115-chat-prompt-not-saved

Conversation

@maruthang
Copy link
Copy Markdown
Contributor

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 via this.modelRef.value = undefined, which triggered model serialization before the widget's setModel call 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 after setModel has 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 immediate this.modelRef.value = undefined with clearAndLeak() pattern that defers disposal until after setModel flushes 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

  • Added regression test verifying model stays alive when reference is leaked and disposed after state flush
  • Added regression test demonstrating the problematic early-release pattern that caused the bug
  • All existing tests pass

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Agents: Regression in chat input prompt being saved

2 participants