Skip to content

Skip extension host restart when adding the first folder to an empty window - #334812

Open
Arunachalam Nachiappan (arun-357) wants to merge 2 commits into
microsoft:mainfrom
arun-357:fix/319944-empty-window-first-folder-eh-restart
Open

Skip extension host restart when adding the first folder to an empty window#334812
Arunachalam Nachiappan (arun-357) wants to merge 2 commits into
microsoft:mainfrom
arun-357:fix/319944-empty-window-first-folder-eh-restart

Conversation

@arun-357

Copy link
Copy Markdown
Contributor

Fixes #319944

Problem

When a window has no folder open and you Add Folder to Workspace, VS Code restarts the extension host. If Copilot Chat (or another session) is in progress, you get Please confirm restart of extensions — A session is in progress. Confirming kills the chat.

N→N+1 folders in an existing multi-root workspace does not restart the host. 0→1 should behave the same.

Two restarts fire on that transition:

  1. NativeWorkspaceEditingService.enterWorkspace — reason Opening a multi-root workspace (empty window always creates an untitled workspace and enters it).
  2. WorkspaceChangeExtHostRelauncher — reason Changing workspace folders (first folder goes from none → one, for the deprecated workspace.rootPath API).

Skipping only (1) is not enough. Local logs still showed the veto from (2):

Extension host was not stopped because of veto (stop reason: Changing workspace folders, veto reason: A session is in progress.)

Fix

Skip the extension host restart on the 0→1 path only. Storage switch, backup reinit, and onDidEnterWorkspace still run. Changing the first folder later (A → B) still restarts the host. Folder → multi-root and remote windows are unchanged.

workspaceEditingService.ts — do not stop/start the EH when coming from WorkbenchState.EMPTY:

const fromEmptyWorkspace = this.contextService.getWorkbenchState() === WorkbenchState.EMPTY;

if (!fromEmptyWorkspace) {
	const stopped = await this.extensionService.stopExtensionHosts(/* ... */);
	if (!stopped) {
		return;
	}
}

relauncher.contribution.ts — do not schedule a restart when there was no previous first folder:

const hadFirstFolder = !!this.firstFolderResource;
this.firstFolderResource = newFirstFolderResource;

// Skip 0→1 folders (#319944): same as adding a folder in an existing workspace
if (hadFirstFolder) {
	this.extensionHostRestarter.schedule();
}

Notes:

  • Workspace folders still update live via $acceptWorkspaceData (MainThreadWorkspace), same as N→N+1.
  • Chat session files still migrate through ChatSessionStore joining onDidEnterWorkspace.
  • Caveat: extension-host workspace-scoped storage (ExtensionStoragePaths) stays bound to the empty-window workspace id until the next real EH restart. Workbench storage is switched with preserveData. Extensions that only read rootPath in activate() can stay stale until then (same class of issue as in-place folder add).

Tests

  • nativeWorkspaceEditingService.test.ts
    • empty window → enterWorkspace does not call stopExtensionHosts / startExtensionHosts
    • folder window → enterWorkspace still restarts the host

How to test

  1. ./scripts/code.sh with no folder (empty window).
  2. Start Copilot Chat and send a message.
  3. Command Palette → Add Folder to Workspace... → pick a folder.
  4. No restart confirmation dialog; chat stays.

Regression: open a single folder, add a second folder via Add Folder to Workspace — EH restart for enterWorkspace still applies. In an existing multi-root workspace, adding another folder (not replacing the first) still does not restart.

Copilot AI balanced review requested due to automatic review settings September 6, 2026 16:06

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The restart guard affects unrelated and remote empty-workspace transitions, and the relauncher behavior lacks regression coverage.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Prevents extension-host restarts when adding the first folder to an empty window.

Changes:

  • Skips workspace-entry and relauncher restarts for empty-to-folder transitions.
  • Adds native workspace editing regression tests.
File summaries
File Description
workspaceEditingService.ts Conditionally skips extension-host restart.
relauncher.contribution.ts Suppresses restart when no prior first folder existed.
nativeWorkspaceEditingService.test.ts Tests restart behavior for empty and folder windows.
Review details
  • Files reviewed: 3/3 changed files
  • Comments generated: 2
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

if (!stopped) {
return;
// Skip extension host restart when coming from an empty window (#319944)
const fromEmptyWorkspace = this.contextService.getWorkbenchState() === WorkbenchState.EMPTY;
Comment on lines +347 to +348
if (hadFirstFolder) {
this.extensionHostRestarter.schedule(); // buffer calls to extension host restart
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.

Adding the first root folder to an empty-window workspace restarts the extension host, killing in-progress Copilot Chat sessions

3 participants