Skip to content

fix(terminal): avoid expired ServicesAccessor when creating terminal in multi-folder workspace - #350912

Merged
Dmitriy Vasyura (dmitrivMS) merged 2 commits into
microsoft:mainfrom
wasim-builds:fix/issue-350855
Nov 29, 2026
Merged

Dmitriy Vasyura (dmitrivMS) merged 2 commits into
microsoft:mainfrom
wasim-builds:fix/issue-350855

Conversation

@wasim-builds

@wasim-builds MOHAMMED WASIM KHAN (wasim-builds) commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #350855

Root Cause

In TerminalCommandId.New (src/vs/workbench/contrib/terminal/browser/terminalActions.ts), await c.service.resolveLocation(...) ran before pickTerminalCwd(accessor) was called. Because ServicesAccessor is only valid during the synchronous invocation of its target method, calling pickTerminalCwd(accessor) in a multi-folder workspace threw:

Illegal state: service accessor is only valid during the invocation of its target method

Changes

  • Capture IInstantiationService from accessor synchronously before awaiting c.service.resolveLocation(...) and invoke pickTerminalCwd via instantiationService.invokeFunction(pickTerminalCwd).
  • Extract createNewTerminal and add a regression unit test in src/vs/workbench/contrib/terminal/test/browser/terminalActions.test.ts verifying multi-folder terminal creation with a real InstantiationService.

Copilot AI balanced review requested due to automatic review settings November 28, 2026 19:21

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.

🟢 Approval recommended

There are no active review issues for the multi-folder terminal creation fix.

No open issues 🎉

What changed in this PR

Fixes new-terminal creation in multi-folder workspaces by avoiding access to an expired ServicesAccessor after asynchronous location resolution, addressing #350855.

Changes:

  • Captures IInstantiationService before awaiting and uses a fresh accessor to invoke the working-directory picker.
  • Extracts createNewTerminal and adds a regression test using a real InstantiationService.
File Description
src/​vs/​workbench/​contrib/​terminal/​test/​browser/​terminalActions.test.ts Adds regression coverage for multi-folder selection and the resulting terminal working directory.
src/​vs/​workbench/​contrib/​terminal/​browser/​terminalActions.ts Extracts terminal creation logic and fixes accessor lifetime handling.

Review effort: Balanced

@dmitrivMS

Copy link
Copy Markdown
Collaborator

MOHAMMED WASIM KHAN (@wasim-builds) Thank you!

@dmitrivMS Dmitriy Vasyura (dmitrivMS) added this to the 1.149.0 milestone Nov 29, 2026
@dmitrivMS
Dmitriy Vasyura (dmitrivMS) added this pull request to the merge queue Nov 29, 2026
Merged via the queue into microsoft:main with commit b6ab642 Nov 29, 2026
53 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

terminal General terminal issues that don't fall under another label

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Creating a new terminal with a shortcut is broken when I added multiple folders in VS Code.

4 participants