Skip to content

sessions: restore last active session on reload#315312

Merged
sandy081 merged 1 commit intomainfrom
sandy081/session-restore
May 8, 2026
Merged

sessions: restore last active session on reload#315312
sandy081 merged 1 commit intomainfrom
sandy081/session-restore

Conversation

@sandy081
Copy link
Copy Markdown
Member

@sandy081 sandy081 commented May 8, 2026

Summary

On reload, the agents window now restores the last active session instead of flashing the new-session view.

Changes

ISessionsManagementService / SessionsManagementService

  • Add restoreLastActiveSession() to the service interface and implementation.
  • Introduce _startOpenSession() — cancels any in-flight open/restore and returns a fresh CancellationToken. All navigation paths (openSession, openChat, createNewSession, openNewSessionView, openNewChatInSession) now call it so concurrent operations are safely cancelled.
  • Refactor openSession into a public entry point + private _doOpenSession(token) so restore can reuse the same logic.
  • Fire _onDidOpenNewSessionView in openNewSessionView so the restore progress promise can race against it and dismiss early.
  • Show a progress indicator on ChatViewId during restore (200 ms delay to avoid flicker on fast restores); cancel it immediately if the user navigates to the new-session view.

Workbench.restore()

  • Call sessionsManagementService.restoreLastActiveSession() during startup (fire-and-forget — progress is managed inside the service).

Behaviour

Scenario Before After
Reload with active session New-session view flashes, then nothing Session is restored; progress shown on chat view while loading
Reload with no prior session New-session view shown New-session view shown (unchanged)
Navigate away during restore Restore cancelled; new destination shown
Navigate to new session during restore Progress bar dismissed immediately

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>
Copilot AI review requested due to automatic review settings May 8, 2026 16:43
@sandy081 sandy081 enabled auto-merge (squash) May 8, 2026 16:43
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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() to ISessionsManagementService and implement restore logic in SessionsManagementService.
  • 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();
@sandy081 sandy081 merged commit 1242adc into main May 8, 2026
29 checks passed
@sandy081 sandy081 deleted the sandy081/session-restore branch May 8, 2026 17:54
@vs-code-engineering vs-code-engineering Bot added this to the 1.120.0 milestone 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
@sandy081 sandy081 restored the sandy081/session-restore branch May 8, 2026 20:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants