Starting the terminal in a non-WSL shell boots a WSL distribution whose shell is set as default in settings #11428

Closed
opened 2026-01-31 02:47:22 +00:00 by claunia · 14 comments
Owner

Originally created by @KyleRAnderson on GitHub (Nov 16, 2020).

Environment

Windows build number: 10.0.19042.0
Windows Terminal version (if applicable): 1.4.3141.0

Any other software? Ubuntu 18.04 and Ubuntu WSL distros installed, the latter of which is a WSL 2 distro.

Steps to reproduce

  1. With a WSL distribution installed and its shell configured in the Windows Terminal, set that distribution's shell as the default profile in the Windows terminal settings (the distribution is usually added automatically, you should only need to modify the defaultProfile key in the settings JSON).
  2. Ensure that the WSL distribution whose shell is currently set as the default in Windows terminal is not currently running (consider using wsl --shutdown to stop all distros).
  3. Open the start menu, find the Windows Terminal application shortcut, and right click on it.
  4. Under Tasks, open any non-WSL shell such as PowerShell or cmd.
  5. Run wsl --list --verbose and observe that the WSL distribution whose shell is set to the default has been started and is now running.

Expected behavior

When starting the Windows Terminal directly to a specified profile via right clicking on the application icon and selecting one of the Tasks, the default shell is not invoked. If the default shell is a WSL distribution shell, this means not booting the WSL distribution.

Actual behavior

After starting Windows terminal directly to the powershell profile, I observed that the Ubuntu WSL distribution, whose shell is set as my default in Windows Terminal, was getting booted. The terminal would still load the Powershell profile correctly, it just starts the WSL distro even though it won't be getting used.

Settings.json

Note: I've removed the colour schemes, and I had no keybindings configured.

// To view the default settings, hold "alt" while clicking on the "Settings" button.
// For documentation on these settings, see: https://aka.ms/terminal-documentation
{
    "$schema": "https://aka.ms/terminal-profiles-schema",
    "defaultProfile": "{2c4de342-38b7-51cf-b940-2309a097f518}",
    "profiles": {
        "defaults": {
            // Put settings here that you want to apply to all profiles
        },
        "list": [
            {
                // Make changes here to the powershell.exe profile
                "guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
                "name": "Windows PowerShell",
                "commandline": "powershell.exe",
                "hidden": false
            },
            {
                // Make changes here to the cmd.exe profile
                "guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",
                "name": "cmd",
                "commandline": "cmd.exe",
                "hidden": false
            },
            {
                "guid": "{c6eaf9f4-32a7-5fdc-b5cf-066e8a4b1e40}",
                "hidden": false,
                "name": "Ubuntu-18.04",
                "source": "Windows.Terminal.Wsl",
                "startingDirectory": "//wsl$/Ubuntu-18.04/home"
            },
            {
                "guid": "{b453ae62-4e3d-5e58-b989-0a998ec441b8}",
                "hidden": false,
                "name": "Azure Cloud Shell",
                "source": "Windows.Terminal.Azure"
            },
            {
                "guid": "{2c4de342-38b7-51cf-b940-2309a097f518}",
                "hidden": false,
                "name": "Ubuntu",
                "source": "Windows.Terminal.Wsl",
                "startingDirectory": "//wsl$/Ubuntu/home"
            },
            {
                "guid": "{00000000-0000-0000-ba54-000000000002}",
                "commandline": "%PROGRAMFILES%/git/usr/bin/bash.exe -i -l",
                "icon": "%PROGRAMFILES%/Git/mingw64/share/git/git-for-windows.ico",
                "name": "GBash",
                "startingDirectory": null,
                "colorScheme": "Tinacious Design (Dark)",
                "acrylicOpacity": 0.5,
                "useAcrylic": true
            }
        ]
    },
Originally created by @KyleRAnderson on GitHub (Nov 16, 2020). # Environment ```none Windows build number: 10.0.19042.0 Windows Terminal version (if applicable): 1.4.3141.0 Any other software? Ubuntu 18.04 and Ubuntu WSL distros installed, the latter of which is a WSL 2 distro. ``` # Steps to reproduce 1. With a WSL distribution installed and its shell configured in the Windows Terminal, set that distribution's shell as the default profile in the Windows terminal settings (the distribution is usually added automatically, you should only need to modify the `defaultProfile` key in the settings JSON). 1. Ensure that the WSL distribution whose shell is currently set as the default in Windows terminal is not currently running (consider using `wsl --shutdown` to stop all distros). 1. Open the start menu, find the Windows Terminal application shortcut, and right click on it. 1. Under `Tasks`, open any non-WSL shell such as PowerShell or cmd. 1. Run `wsl --list --verbose` and observe that the WSL distribution whose shell is set to the default has been started and is now running. # Expected behavior When starting the Windows Terminal directly to a specified profile via right clicking on the application icon and selecting one of the `Tasks`, the default shell is not invoked. If the default shell is a WSL distribution shell, this means not booting the WSL distribution. # Actual behavior After starting Windows terminal directly to the powershell profile, I observed that the Ubuntu WSL distribution, whose shell is set as my default in Windows Terminal, was getting booted. The terminal would still load the Powershell profile correctly, it just starts the WSL distro even though it won't be getting used. # Settings.json _Note: I've removed the colour schemes, and I had no keybindings configured_. ```jsonc // To view the default settings, hold "alt" while clicking on the "Settings" button. // For documentation on these settings, see: https://aka.ms/terminal-documentation { "$schema": "https://aka.ms/terminal-profiles-schema", "defaultProfile": "{2c4de342-38b7-51cf-b940-2309a097f518}", "profiles": { "defaults": { // Put settings here that you want to apply to all profiles }, "list": [ { // Make changes here to the powershell.exe profile "guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}", "name": "Windows PowerShell", "commandline": "powershell.exe", "hidden": false }, { // Make changes here to the cmd.exe profile "guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}", "name": "cmd", "commandline": "cmd.exe", "hidden": false }, { "guid": "{c6eaf9f4-32a7-5fdc-b5cf-066e8a4b1e40}", "hidden": false, "name": "Ubuntu-18.04", "source": "Windows.Terminal.Wsl", "startingDirectory": "//wsl$/Ubuntu-18.04/home" }, { "guid": "{b453ae62-4e3d-5e58-b989-0a998ec441b8}", "hidden": false, "name": "Azure Cloud Shell", "source": "Windows.Terminal.Azure" }, { "guid": "{2c4de342-38b7-51cf-b940-2309a097f518}", "hidden": false, "name": "Ubuntu", "source": "Windows.Terminal.Wsl", "startingDirectory": "//wsl$/Ubuntu/home" }, { "guid": "{00000000-0000-0000-ba54-000000000002}", "commandline": "%PROGRAMFILES%/git/usr/bin/bash.exe -i -l", "icon": "%PROGRAMFILES%/Git/mingw64/share/git/git-for-windows.ico", "name": "GBash", "startingDirectory": null, "colorScheme": "Tinacious Design (Dark)", "acrylicOpacity": 0.5, "useAcrylic": true } ] }, ```
claunia added the Area-SettingsIssue-BugProduct-TerminalPriority-2 labels 2026-01-31 02:47:22 +00:00
Author
Owner

@DHowett commented on GitHub (Nov 16, 2020):

Please share a copy of your settings.json.

@DHowett commented on GitHub (Nov 16, 2020): Please share a copy of your settings.json.
Author
Owner

@KyleRAnderson commented on GitHub (Nov 16, 2020):

I've updated the description @DHowett , let me know if there is anything else you'd like.

@KyleRAnderson commented on GitHub (Nov 16, 2020): I've updated the description @DHowett , let me know if there is anything else you'd like.
Author
Owner

@DHowett commented on GitHub (Nov 16, 2020):

Thanks.

If you run wt -p {61c54bbd-c2c6-5271-96e7-009a87ff44bf} directly (from the Run dialog) after terminating your WSL instances, what happens?

When you launch Terminal via the Tasks list, and it goes to the wrong profile, what icon does it display? Does it use the settings from one profile (color scheme, font, etc.) but start an application from a different profile?

@DHowett commented on GitHub (Nov 16, 2020): Thanks. If you run `wt -p {61c54bbd-c2c6-5271-96e7-009a87ff44bf}` directly (from the Run dialog) after terminating your WSL instances, what happens? When you launch Terminal via the Tasks list, and it goes to the wrong profile, what icon does it display? Does it use the settings from one profile (color scheme, font, etc.) but start an application from a different profile?
Author
Owner

@KyleRAnderson commented on GitHub (Nov 16, 2020):

Looks like I get the same behaviour when invoking it with wt -p {61c54bbd-c2c6-5271-96e7-009a87ff44bf}.

Also, to clarify @DHowett, it is going to the correct profile, using the correct icons and settings, etc. The only problem that I think exists is that it seems to be starting the WSL distro as well. It's just pointless booting of a VM only for it to be stopped automatically shortly after.

@KyleRAnderson commented on GitHub (Nov 16, 2020): Looks like I get the same behaviour when invoking it with `wt -p {61c54bbd-c2c6-5271-96e7-009a87ff44bf}`. Also, to clarify @DHowett, it is going to the correct profile, using the correct icons and settings, etc. The only problem that I think exists is that it seems to be starting the WSL distro as well. It's just pointless booting of a VM only for it to be stopped automatically shortly after.
Author
Owner

@DHowett commented on GitHub (Nov 16, 2020):

And if you do not set this WSL distribution as your default, it's definitely not booted?

How about if you launch Windows PowerShell outside of terminal after shutting down WSL?

WT doesn't do anything that should result in processes that are not part of a current active profile being run...

@DHowett commented on GitHub (Nov 16, 2020): And if you _do not_ set this WSL distribution as your default, it's definitely not booted? How about if you launch Windows PowerShell _outside of terminal_ after shutting down WSL? WT doesn't do anything that should result in processes that are not part of a current active profile being run...
Author
Owner

@KyleRAnderson commented on GitHub (Nov 16, 2020):

When the WSL shell isn't set as my default profile and I start the app to a non-WSL profile, it doesn't start the distro. Additionally, if I set the default profile to the shell for my Ubuntu 18.04 distro, it starts that distribution instead of the Ubuntu one, so it's definitely only starting the shell that's configured as the default. This also means it's not specific to WSL 1 or WSL 2, it occurs on both.

Starting powershell or CMD from outside of Windows Terminal does not cause this issue.

@KyleRAnderson commented on GitHub (Nov 16, 2020): When the WSL shell isn't set as my default profile and I start the app to a non-WSL profile, it doesn't start the distro. Additionally, if I set the default profile to the shell for my Ubuntu 18.04 distro, it starts that distribution instead of the Ubuntu one, so it's definitely only starting the shell that's configured as the default. This also means it's not specific to WSL 1 or WSL 2, it occurs on both. Starting powershell or CMD from outside of Windows Terminal does not cause this issue.
Author
Owner

@KyleRAnderson commented on GitHub (Nov 16, 2020):

Small note here, there seems to be a mismatch between the build number listed by [Environment]::OSVersion in PowerShell and ver in CMD.
image

I reported the one listed in PowerShell, but the version in CMD is reported when I run winver or go to Settings -> System -> About.

@KyleRAnderson commented on GitHub (Nov 16, 2020): Small note here, there seems to be a mismatch between the build number listed by `[Environment]::OSVersion` in PowerShell and `ver` in CMD. ![image](https://user-images.githubusercontent.com/22606608/99254838-016d5780-27e1-11eb-83f1-89ccf4a901a9.png) I reported the one listed in PowerShell, but the version in CMD is reported when I run `winver` or go to Settings -> System -> About.
Author
Owner

@DHowett commented on GitHub (Nov 17, 2020):

Yeah, that version number thing is annoying. PowerShell doesn't know where to find the fourth component!

Would you mind grabbing a process monitor trace? It might be enlightening, and help us see what Terminal is doing behind the scenes.

  1. Shut down WSL -- get ready to reproduce the issue
  2. Install process monitor
  3. Launch it.
  4. Configure it with the following filters in place:
    • Process Name is WindowsTerminal.exe: Include
    • Process Name is wsl.exe: Include
    • Process Name is powershell.exe: Include
    • image
  5. Hit OK
  6. Reproduce the issue! Launch terminal with a profile that is incorrectly launching WSL.
  7. Press the capture icon to stop capturing
    • image
  8. File > Save
    • image

E-mail me the PML file -- or post it here (but it will include things like your username and some details about the file layout on your machine) -- at the address on my GitHub profile.

Thanks! 😄

@DHowett commented on GitHub (Nov 17, 2020): Yeah, that version number thing is annoying. PowerShell doesn't know where to find the fourth component! Would you mind grabbing a process monitor trace? It might be enlightening, and help us see what Terminal is doing behind the scenes. 1. Shut down WSL -- get ready to reproduce the issue 1. Install [process monitor](https://docs.microsoft.com/en-us/sysinternals/downloads/procmon) 1. Launch it. 1. Configure it with the following filters in place: * _Process Name_ is `WindowsTerminal.exe`: _Include_ * _Process Name_ is `wsl.exe`: _Include_ * _Process Name_ is `powershell.exe`: _Include_ * ![image](https://user-images.githubusercontent.com/189190/99329639-82553f00-2833-11eb-962f-7139687b0e69.png) 1. Hit OK 1. Reproduce the issue! Launch terminal with a profile that is incorrectly launching WSL. 1. Press the capture icon to _stop capturing_ * ![image](https://user-images.githubusercontent.com/189190/99329710-a31d9480-2833-11eb-9fd1-ffd48b90ede2.png) 1. File > Save * ![image](https://user-images.githubusercontent.com/189190/99329754-bb8daf00-2833-11eb-99a6-7b6d6d4278af.png) E-mail me the PML file -- or post it here (but it will include things like your username and some details about the file layout on your machine) -- at the address on my GitHub profile. Thanks! :smile:
Author
Owner

@KyleRAnderson commented on GitHub (Nov 17, 2020):

I've gathered the logs @DHowett and have sent the email. Let me know if there's anything else that you may need.

@KyleRAnderson commented on GitHub (Nov 17, 2020): I've gathered the logs @DHowett and have sent the email. Let me know if there's anything else that you may need.
Author
Owner

@DHowett commented on GitHub (Nov 17, 2020):

I think I've got it. Thanks so much!

We create a whole TerminalSettings for the default profile to measure how big the window should be (to translate rows/columns to pixels through the renderer).
Creating one of those evaluates the starting directory for the default profile, which causes it to be checked for viability.

Since yours is //wsl$/Ubuntu/xxx, it starts up the distribution to see if that path exists. Ew.

6b503ba887/src/cascadia/TerminalApp/TerminalSettings.cpp (L97)

6b503ba887/src/cascadia/TerminalSettingsModel/Profile.cpp (L405-L409)

@carlos-zamora remember how we talked about TerminalSettings proxying through to a profile? This is one issue where eagerly evaluating the profile values causes a problem.

@DHowett commented on GitHub (Nov 17, 2020): I think I've got it. Thanks so much! We create a whole `TerminalSettings` for the default profile to measure how big the window should be (to translate rows/columns to pixels through the renderer). Creating one of those _evaluates the starting directory for the default profile_, which causes it to be checked for viability. Since yours is `//wsl$/Ubuntu/xxx`, it starts up the distribution to see if that path exists. Ew. https://github.com/microsoft/terminal/blob/6b503ba8878b084280fa7de7fc36378f73807000/src/cascadia/TerminalApp/TerminalSettings.cpp#L97 https://github.com/microsoft/terminal/blob/6b503ba8878b084280fa7de7fc36378f73807000/src/cascadia/TerminalSettingsModel/Profile.cpp#L405-L409 @carlos-zamora remember how we talked about TerminalSettings _proxying through_ to a profile? This is one issue where eagerly evaluating the profile values causes a problem.
Author
Owner

@KyleRAnderson commented on GitHub (Nov 17, 2020):

Awesome, glad you were able to narrow down a cause 🙂

@KyleRAnderson commented on GitHub (Nov 17, 2020): Awesome, glad you were able to narrow down a cause 🙂
Author
Owner

@DHowett commented on GitHub (Nov 20, 2020):

The fix will probably be removing EvaluatedStartingDirectory from the profile interface & evaluating it in ConPtyConnection.

@DHowett commented on GitHub (Nov 20, 2020): The fix will probably be removing EvaluatedStartingDirectory from the profile interface & evaluating it in ConPtyConnection.
Author
Owner

@DHowett commented on GitHub (Aug 2, 2021):

Hey! I think we actually did fix this in 1.9. We shopped evaluating the starting directory of any profile, likely much to folks' dismay.

See #10045, which closed #9541 and #9114.

@DHowett commented on GitHub (Aug 2, 2021): Hey! I think we actually did fix this in 1.9. We shopped evaluating the starting directory of *any* profile, likely much to folks' dismay. See #10045, which closed #9541 and #9114.
Author
Owner

@DHowett commented on GitHub (Aug 2, 2021):

/dup #9541 (sorry to dupe you to a higher number!)

@DHowett commented on GitHub (Aug 2, 2021): /dup #9541 (sorry to dupe you to a higher number!)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#11428