Re-registered WSL distro profiles do not get auto generated on terminal restart unless state.json is deleted. #15551

Closed
opened 2026-01-31 04:41:41 +00:00 by claunia · 6 comments
Owner

Originally created by @ghost on GitHub (Oct 14, 2021).

Windows Terminal version (or Windows build number)

Microsoft Windows [Version 10.0.19043.1237]

Other Software

WSL

Steps to reproduce

  • close terminal
  • re-register an existing WSL distribution which had an existing profile in WT before
  • remove that profile from WT's config
  • open terminal
  • config file does NOT contain the new distribution's auto-generated profile

Expected Behavior

An auto-generated profile for the WSL distro which was registered.

Actual Behavior

A profile is not added automatically, to make WT add the profile, the state.json file must be deleted, and the terminal must be reopened.

I'm just blindly guessing but I'm assuming this bug as to do w caching existing profiles in state.json, wt looks at the guid in state.json, assumes thats already generated, and skips trying to generate it again for the config.

Also, just for my own curiosity, how are the GUIDs generated for a distro? Is it a uuid v5 with the terminal uuid namespace? I registered a custom distro using wsl --import and it gave it a GUID too. A uuid v5 is what i could tell from the source code, but i tried generating some UUID v5s myself using the terminal's runtime namespace and the name of the distro, and the results weren't the same.

Originally created by @ghost on GitHub (Oct 14, 2021). ### Windows Terminal version (or Windows build number) Microsoft Windows [Version 10.0.19043.1237] ### Other Software WSL ### Steps to reproduce - close terminal - re-register an existing WSL distribution which had an existing profile in WT before - remove that profile from WT's config - open terminal - config file does NOT contain the new distribution's auto-generated profile ### Expected Behavior An auto-generated profile for the WSL distro which was registered. ### Actual Behavior A profile is not added automatically, to make WT add the profile, the state.json file must be deleted, and the terminal must be reopened. I'm just blindly guessing but I'm assuming this bug as to do w caching existing profiles in state.json, wt looks at the guid in state.json, assumes thats already generated, and skips trying to generate it again for the config. Also, just for my own curiosity, how are the GUIDs generated for a distro? Is it a uuid v5 with the terminal uuid namespace? I registered a custom distro using `wsl --import` and it gave it a GUID too. A uuid v5 is what i could tell from the source code, but i tried generating some UUID v5s myself using the terminal's runtime namespace and the name of the distro, and the results weren't the same.
Author
Owner

@ghost commented on GitHub (Oct 14, 2021):

Ok so I may have found the cause,

Before:

image

As you can see, state.json has the Ubuntu distro's GUID in the generatedProfiles array.

Now lets assume that the user decides to uninstall Ubuntu, and hence removes the Ubuntu profile from settings.json,

image

As you can see, the GUID of Ubuntu isn't removed from state.json upon removing it from settings.json.

Now lets assume that the user decides to reinstall Ubuntu again, and restarts Windows Terminal, since the GUID of Ubuntu is still in the generatedProfiles array even thought the profile IS NOT generated, the Ubuntu profile won't be regenerated this time, hence causing the bug.

The workaround has been to remove the GUID of that distro which is still stuck in state.json and make any modification to the config causing the state.json file to be rewritten.

@ghost commented on GitHub (Oct 14, 2021): Ok so I may have found the cause, Before: ![image](https://user-images.githubusercontent.com/67145097/137368092-4cc0921b-e68b-4b8e-a0da-692718a4171c.png) As you can see, `state.json` has the `Ubuntu` distro's GUID in the `generatedProfiles` array. Now lets assume that the user decides to uninstall Ubuntu, and hence removes the Ubuntu profile from `settings.json`, ![image](https://user-images.githubusercontent.com/67145097/137368291-74b52954-5df6-469e-ac6e-ed7f16a546d2.png) As you can see, the GUID of `Ubuntu` isn't removed from `state.json` upon removing it from `settings.json`. Now lets assume that the user decides to reinstall Ubuntu again, and restarts Windows Terminal, since the GUID of Ubuntu is still in the generatedProfiles array even thought the profile IS NOT generated, the Ubuntu profile won't be regenerated this time, hence causing the bug. The workaround has been to remove the GUID of that distro which is still stuck in state.json and make any modification to the config causing the state.json file to be rewritten.
Author
Owner

@zadjii-msft commented on GitHub (Oct 25, 2021):

Okay yep, that's exactly what happened here. Same as in #11593.

  1. We found the WSL profile, generated it into the settings.json file, and then added that guid to state.json so we wouldn't generate it again.
  2. We saw that the distro was gone, so we removed it from the file
  3. When we re-found the profile, we see that we already added it into the state, so we skip it.

We should maybe not do 2 anymore. @lhecker thoughts?

@zadjii-msft commented on GitHub (Oct 25, 2021): Okay yep, that's exactly what happened here. Same as in #11593. 1. We found the WSL profile, generated it into the settings.json file, and then added that guid to `state.json` so we wouldn't generate it again. 2. We saw that the distro was gone, so we _removed it from the file_ 3. When we re-found the profile, we see that we already added it into the `state`, so we skip it. We should maybe not do 2 anymore. @lhecker thoughts?
Author
Owner

@DHowett commented on GitHub (Oct 25, 2021):

Yes, we should not do 2. Only now after #11184 merged do we have the ability to find disconnected generator "leaf profiles." They used to be omitted from the settings model entirely at parse time.

I've mentioned to a couple of you a UI that would display something like, "This profile was generated and seems to have disappeared. We've kept your local copy just in case." etc.

@DHowett commented on GitHub (Oct 25, 2021): Yes, we should not do 2. Only now after #11184 merged do we have the ability to _find_ disconnected generator "leaf profiles." They used to be omitted from the settings model entirely at parse time. I've mentioned to a couple of you a UI that would display something like, "This profile was generated and seems to have disappeared. We've *kept your local copy* just in case." etc.
Author
Owner

@DHowett commented on GitHub (Oct 25, 2021):

(we only do 2 when you [save] while the distro is gone. That's still a big footgun.)

@DHowett commented on GitHub (Oct 25, 2021): (we only do 2 when you [save] while the distro is gone. That's still a big footgun.)
Author
Owner

@lhecker commented on GitHub (Oct 25, 2021):

Oh right I meant to test this today...
If I remove my WSL distro and launch WT the distro is not removed from the file. However hitting "Save" in the settings UI removes it, as only "visible" profiles are saved.
Implementing Dustin's suggestion shouldn't be too hard. This is the code responsible for removing such profiles: 9662bc6910/src/cascadia/TerminalSettingsModel/CascadiaSettingsSerialization.cpp (L776-L788)

I'm not sure if it would be enough to simply mark such profiles as "hidden".

@lhecker commented on GitHub (Oct 25, 2021): Oh right I meant to test this today... If I remove my WSL distro and launch WT the distro is _not_ removed from the file. However hitting "Save" in the settings UI removes it, as only "visible" profiles are saved. Implementing Dustin's suggestion shouldn't be too hard. This is the code responsible for removing such profiles: https://github.com/microsoft/terminal/blob/9662bc69102e2e152a062a9060cb63d2742582d3/src/cascadia/TerminalSettingsModel/CascadiaSettingsSerialization.cpp#L776-L788 I'm not sure if it would be enough to simply mark such profiles as "hidden".
Author
Owner

@andreyvdl commented on GitHub (Sep 29, 2023):

So i had this problem just now when re-registering Debian, i notice that it didn't created the Debian profile even when i wanted to duplicate.

To resolve what i did was delete all generatedProfiles in state.json that wasn't in use in settings.json, then i go to duplicate a profile, and this time Debian was a option.

@andreyvdl commented on GitHub (Sep 29, 2023): So i had this problem just now when re-registering Debian, i notice that it didn't created the Debian profile even when i wanted to duplicate. To resolve what i did was delete all `generatedProfiles` in `state.json` that wasn't in use in `settings.json`, then i go to duplicate a profile, and this time Debian was a option.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#15551