terminal icon indicating copy to clipboard operation
terminal copied to clipboard

Problems with session startup and resumption

Open kamrann opened this issue 1 year ago • 7 comments

Windows Terminal version

1.18.3181.0

Windows build number

10.0.19045.0

Other Software

No response

Steps to reproduce

  • In Terminal settings, Default terminal application is Windows Terminal, Launch on machine startup is On, When terminal starts is set to Open windows from a previous session, and New instance behaviour to Create a new window.

Expected Behavior

My expectation would be that restoration of the previous session should apply only to the first Terminal instance (be it at machine startup or subsequently). Any further explicitly opened instances should open a tab with the default profile, whereas any instances opened to house an application that was launched explicitly should simply have a single tab for that application.

Actual Behavior

Initial startup is as expected (for the most part, see caveat below), however I'm seeing strange behaviour following that. With a single instance of Terminal open, if I attempt to launch any console application (cmd.exe, PS, or a console program launched via Visual Studio debugger), that application will open in a new Terminal window as expected, but alongside it a further Terminal window will be opened populated with tabs based on the prior session (so to clarify, I end up with 3 windows: the original session, a duplication of it, and the opened application).

  • The above does not occur when explicitly opening Terminal.
  • The above does not occur when I already have more than a single Terminal session open.

Regarding above noted caveat. It's not clear exactly how Terminal decides/updates what constitutes the previous session, but it seems far too easy for what I want to be considered my previous session to get replaced. Perhaps it's just based on the last window to be closed down? I really need some way to mark my 'main' session so that I don't end up losing the layout as a result of having at some point opened a secondary session. In particular, the fact that a session resulting from a request to open cmd.exe or similar directly can end up overwriting my Terminal layout restoration seems wrong.

kamrann avatar Dec 21 '23 01:12 kamrann

Can I contribute?

Mubashir2611 avatar Dec 23 '23 10:12 Mubashir2611

Hmm. You wouldn't happen to be launching the Terminal as admin at any point in all this, would you? There's separate persisted state for each of those two instances, so that might be at play here/?

Sounds like there's something weird going on with defterm here, since it's like the defterm launch is then also triggering another state restore?

I'd reckon this may almost be related to #15509? Or maybe, more horrifyingly, there's an interplay here between defterm, session restore, and refrigeration. I coulda swore we had a better dupe somewhere for "a defterm session seemingly can't communicate with the existing WT process", but I can't find that.

Just to confirm - do you only have one version of the Terminal installed? (e.g. only Stable, not also Preview)

zadjii-msft avatar Jan 10 '24 16:01 zadjii-msft

Not opening as admin, no. I've tested a bit and found that I don't see this behaviour on my laptop running Windows 11, but only on my other machine running Windows 10, on which I believe I updated the version of Windows Terminal at some point.

As far as I'm aware I only have a single version installed. I'm not too familiar with update process for Windows apps/Powershell though. Are there any commands you suggest I run to verify that the installations are as they should be?

kamrann avatar Jan 18 '24 06:01 kamrann

I need to go dedupe the set of

  • #16487
  • #16557
  • #16561
issue Windows? DefTerm? Restore prev session Launch on startup? issues?
#16487 10 true true true ❌ launch on boot restores normally, then defterm also restores?
#16487 10 true true true ✅ seemingly works fine?
#16557 10 ? true true ❌ launch on boot restores normally, then {{a second launch, unsure if defterm}} also restores?
#16561 10 ? ? (probably) true ❌ launch on boot restores double of the session
#16732 10 true true ? ❌ When opening a defterm even with window open, creates a window with a set of "restored" tabs

zadjii-msft avatar Jan 31 '24 22:01 zadjii-msft

Seems like there's something up with the way Windows 10 restores the Terminal... we restore the session, but then a subsequent launch of the Terminal also tries to restore. Weird.

Oh no, I can't repro this in a VM, least, not on 10.0.19041 & 1.19.2682.0

zadjii-msft avatar Feb 08 '24 12:02 zadjii-msft

oh man I wonder if there's some other console app that's starting at boot, triggering defterm, which triggers a session restore. But then also the Terminal gets launched, and it simultaneously finds no one else booted, so it also session restores. Is there anything else suspicious in "Startup" in Task Manager?

zadjii-msft avatar Feb 08 '24 12:02 zadjii-msft

Details in #16732 make me think that this is less related to Start on Login and more related to defterm accidentally triggering a session restore.

zadjii-msft avatar Feb 19 '24 12:02 zadjii-msft

Note to self: Go look at https://github.com/microsoft/terminal/pull/16598#discussion_r1543634396

holy sh--, multi-window restore starts WindowsTerminal.exe which then gets a handle to our Monarch and sends it a commandline.

What the heck.

We could just... use Monarch directly here. I know you didn't write this code but I think we missed it when we migrated to single-proc.

zadjii-msft avatar Mar 29 '24 11:03 zadjii-msft