Skip extension host restart when adding the first folder to an empty window - #334812
Conversation
There was a problem hiding this comment.
🟡 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; |
| if (hadFirstFolder) { | ||
| this.extensionHostRestarter.schedule(); // buffer calls to extension host restart |
|
Closing this. Restarting the extension host when an empty window enters a workspace is the intended behavior, not a bug in that path. Adding the first folder from an empty window is not the same as N→N+1 in an existing multi-root workspace. The empty window has to create and enter a new workspace identity (storage, backups, workspace.rootPath). N→N+1 only updates folders in a workspace that is already open, which is why it does not restart the host. Skipping that restart to keep chat alive would leave the extension host bound to the empty-window workspace id. That is the wrong tradeoff for Save Workspace As, dropping multiple folders, remote, and opening a saved workspace — and it is still a real cost even for the local 0→1 add. The “session in progress” prompt is working as designed when the host has to restart. Fixes for chat surviving a workspace enter belong in session migration / veto UX, not in skipping the restart. |
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+1folders in an existing multi-root workspace does not restart the host.0→1should behave the same.Two restarts fire on that transition:
NativeWorkspaceEditingService.enterWorkspace— reasonOpening a multi-root workspace(empty window always creates an untitled workspace and enters it).WorkspaceChangeExtHostRelauncher— reasonChanging workspace folders(first folder goes from none → one, for the deprecatedworkspace.rootPathAPI).Skipping only (1) is not enough. Local logs still showed the veto from (2):
Fix
Skip the extension host restart on the 0→1 path only. Storage switch, backup reinit, and
onDidEnterWorkspacestill 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 fromWorkbenchState.EMPTY:relauncher.contribution.ts— do not schedule a restart when there was no previous first folder:Notes:
$acceptWorkspaceData(MainThreadWorkspace), same asN→N+1.ChatSessionStorejoiningonDidEnterWorkspace.ExtensionStoragePaths) stays bound to the empty-window workspace id until the next real EH restart. Workbench storage is switched withpreserveData. Extensions that only readrootPathinactivate()can stay stale until then (same class of issue as in-place folder add).Tests
nativeWorkspaceEditingService.test.tsenterWorkspacedoes not callstopExtensionHosts/startExtensionHostsenterWorkspacestill restarts the hostHow to test
./scripts/code.shwith no folder (empty window).Regression: open a single folder, add a second folder via Add Folder to Workspace — EH restart for
enterWorkspacestill applies. In an existing multi-root workspace, adding another folder (not replacing the first) still does not restart.