Enhance draft input persistence for remote chat sessions#311312
Merged
DonJayamanne merged 2 commits intomainfrom Apr 20, 2026
Merged
Enhance draft input persistence for remote chat sessions#311312DonJayamanne merged 2 commits intomainfrom
DonJayamanne merged 2 commits intomainfrom
Conversation
Contributor
Screenshot ChangesBase: Changed (5) |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves draft (unsent) chat input persistence for remote/external chat sessions so that switching away from a session and back restores the user’s pending input state. It also adds a regression test validating draft restoration after disposing/reloading a remote session.
Changes:
- Persist serialized draft
inputStatefor external sessions in session metadata and restore it when loading remote sessions. - Persist external session metadata on dispose when there are requests or an unsent draft.
- Add a unit test covering draft restoration for a remote session after disposal/reload.
Show a summary per file
| File | Description |
|---|---|
| src/vs/workbench/contrib/chat/test/common/chatService/chatService.test.ts | Adds a test to ensure a remote session’s draft input text is restored after dispose/reload. |
| src/vs/workbench/contrib/chat/common/model/chatSessionStore.ts | Extends session metadata to include serialized draft inputState for external sessions. |
| src/vs/workbench/contrib/chat/common/chatService/chatServiceImpl.ts | Persists metadata for external sessions when there’s a draft; restores draft from stored metadata on remote session load. |
| src/vs/workbench/contrib/chat/browser/widget/input/chatInputPart.ts | Adds a public method to flush view input state into the bound input model. |
| src/vs/workbench/contrib/chat/browser/widget/chatWidget.ts | Calls the flush helper before dropping the model reference (currently only in the setModel(undefined) path). |
Copilot's findings
Comments suppressed due to low confidence (1)
src/vs/workbench/contrib/chat/common/chatService/chatServiceImpl.ts:210
- The dispose-time condition
model.getRequests().length > 0 || hasDraftInput(model)can leave stalemetadata.inputStatebehind for empty external sessions. Example: type a draft (persisted), reopen, clear the draft back to empty, switch away ->hasDraftInputbecomes false and metadata is no longer written, so the old draft will be restored again next open. Consider persisting metadata for external sessions when there is any existing storedinputStateto clear, or basing the decision on whetherinputModel.toJSON()has changed rather than only whether it’s currently non-empty.
} else if (!localSessionId && (model.getRequests().length > 0 || hasDraftInput(model))) {
// External sessions: persist metadata when there are requests, OR when the
// user has typed/attached unsent input we need to restore on next open.
await this._chatSessionStore.storeSessionsMetadataOnly([model]);
}
- Files reviewed: 5/5 changed files
- Comments generated: 3
Agent-Logs-Url: https://github.com/microsoft/vscode/sessions/fdcea905-d6d1-42f5-8993-0ead68edb74c Co-authored-by: DonJayamanne <1948812+DonJayamanne@users.noreply.github.com>
roblourens
approved these changes
Apr 20, 2026
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.
Improve the handling of unsent draft inputs in remote chat sessions. Ensure that draft inputs are preserved when switching sessions, allowing users to retain their input state. Add tests to verify that draft inputs are correctly restored after disposing and reloading a session.
Fixes #311310