sessions: restore last active session on reload#315312
Merged
Conversation
On reload, the agents window now restores the last active session instead of showing the new-session view. - Add `restoreLastActiveSession()` to `ISessionsManagementService` and call it from `Workbench.restore()` during startup. - Switch away from the new-session view synchronously (before any await) to prevent `NewChatViewPane` from rendering and accidentally cancelling the restore token via `createNewSession`. - Wait for the session provider to register if the session isn't available immediately, then delegate to `_doOpenSession`. - Show a progress indicator on `ChatViewId` during restore (200ms delay to avoid flicker on fast restores); cancel it immediately if the user navigates to the new-session view. - `_startOpenSession` cancels any in-flight open/restore and returns a fresh token; all navigation paths (openSession, openChat, createNewSession, openNewSessionView, openNewChatInSession) now call it so concurrent operations are safely cancelled. - Fire `_onDidOpenNewSessionView` in `openNewSessionView` so the restore progress promise can race against it and dismiss early. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves the Agents window startup experience by restoring the last active session on reload, rather than briefly showing the new-session view first. The changes live in the vs/sessions layer and extend the sessions management service to coordinate restore/open navigation with cancellation and progress.
Changes:
- Add
restoreLastActiveSession()toISessionsManagementServiceand implement restore logic inSessionsManagementService. - Introduce centralized cancellation for concurrent navigation/open actions and show restore progress in the Chat view location.
- Trigger restore during
Workbench.restore()so session restoration happens automatically on reload.
Show a summary per file
| File | Description |
|---|---|
| src/vs/sessions/services/sessions/common/sessionsManagement.ts | Extends the sessions management service contract with restoreLastActiveSession(). |
| src/vs/sessions/services/sessions/browser/sessionsManagementService.ts | Implements restore logic, adds navigation cancellation, and adds progress handling tied to restore. |
| src/vs/sessions/browser/workbench.ts | Initiates last-session restore during workbench restore. |
Copilot's findings
- Files reviewed: 3/3 changed files
- Comments generated: 3
Comment on lines
+600
to
+604
| const tryRestore = () => { | ||
| if (token.isCancellationRequested) { | ||
| cancel(); | ||
| return; | ||
| } |
| // another existing session (which should show its own progress). | ||
| const progressPromise = Promise.race([ | ||
| restorePromise, | ||
| new Promise<void>(resolve => this._onDidOpenNewSessionView.event(() => resolve())) |
| this.restoreParts(); | ||
|
|
||
| // Restore the last active session (progress is shown inside the service). | ||
| this.sessionsManagementService.restoreLastActiveSession(); |
roblourens
approved these changes
May 8, 2026
wpfleger96
added a commit
to wpfleger96/vscode
that referenced
this pull request
May 8, 2026
…2-not-clearing-terminal-title * upstream/main: chat: hide plugin actions for synced customization items (microsoft#315320) fixes microsoft#291188 (microsoft#314713) sessions: restore last active session on reload (microsoft#315312) Replace "Agents app" with "Agents window" in user-facing strings (microsoft#315302) chat: remove 'Bridged' badge from MCP servers in AI Customizations UI (microsoft#315319) Add proposal for custom editor diff/merge priority agentHost: revert undefined-field omission, update tests instead sessions: fix Customizations single-entry width overflow (microsoft#315125) agentHost: rewrite Resource attachments and omit undefined fields agentHost: support image and blob user-message attachments
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
On reload, the agents window now restores the last active session instead of flashing the new-session view.
Changes
ISessionsManagementService/SessionsManagementServicerestoreLastActiveSession()to the service interface and implementation._startOpenSession()— cancels any in-flight open/restore and returns a freshCancellationToken. All navigation paths (openSession,openChat,createNewSession,openNewSessionView,openNewChatInSession) now call it so concurrent operations are safely cancelled.openSessioninto a public entry point + private_doOpenSession(token)so restore can reuse the same logic._onDidOpenNewSessionViewinopenNewSessionViewso the restore progress promise can race against it and dismiss early.ChatViewIdduring restore (200 ms delay to avoid flicker on fast restores); cancel it immediately if the user navigates to the new-session view.Workbench.restore()sessionsManagementService.restoreLastActiveSession()during startup (fire-and-forget — progress is managed inside the service).Behaviour