Loss of bound key processing after disconnecting from unix PowerShell SSH session #7300

Closed
opened 2026-01-31 01:00:30 +00:00 by claunia · 10 comments
Owner

Originally created by @LookoutHill on GitHub (Apr 6, 2020).

Environment

Windows build number: 10.0.18363
Windows Terminal version (if applicable): 0.10.781.0

Any other software?

Tested local Windows shell versions:

  1. PowerShell 7.0.0
  2. PowerShell 5.1.18362.752
  3. cmd.exe 10.0.18363.752

Tested remote Unix shell versions (zsh and bash are included because pwsh is not my login shell):

  1. PowerShell 7.0.0
  2. GNU bash, version 5.0.3(1)-release (arm-unknown-linux-gnueabihf)
  3. zsh 5.7.1 (x86_64-apple-darwin19.0)

Tested Unix variants:

  1. Raspbian GNU/Linux 10 (buster) (Linux 4.19.50-v7l+ #895 SMP Thu Jun 20 16:03:42 BST 2019)
  2. macOS 10.15.4 (19E266) (Darwin 19.4.0 Darwin Kernel Version 19.4.0: Wed Mar 4 22:28:40 PST 2020; root:xnu-6153.101.6~15/RELEASE_X86_64)

Tested ssh.exe versions:

  1. OpenSSH_for_Windows_8.1p1, LibreSSL 2.9.2
  2. OpenSSH_for_Windows_7.7p1, LibreSSL 2.6.5

Steps to reproduce

PS local> ssh.exe @<unix_host>
*sh remote> exec pwsh
PS remote> exit
PS local>

Notes:

  1. All 3 local shells are susceptible.
  2. One must connect to a remote PowerShell on a Unix system. Connecting to the remote shells, zsh or bash, does not trigger the issue. Connecting to a remote PowerShell instance on a Windows system does not trigger the issue.
  3. Only OpenSSH 8.1p1 is susceptible. Connecting via OpenSSH 7.7p1 does not trigger the issue.

Expected behavior

Once the steps to reproduce are followed, then you should be able to use all key bindings including up arrow and down arrow to access history or home and end to navigate a command line.

Actual behavior

Once the steps to reproduce are followed, then you will be unable to use some key bindings including UpArrow and DownArrow to access history or Home and End to navigate a command line.
Some key bindings continue to work. Ctrl+LeftArrow and Ctrl+RightArrow continue to navigate a command line properly. I did not perform an exhaustive test of which key bindings are affected, so this is only a sample.

Originally created by @LookoutHill on GitHub (Apr 6, 2020). <!-- 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨 I ACKNOWLEDGE THE FOLLOWING BEFORE PROCEEDING: 1. If I delete this entire template and go my own path, the core team may close my issue without further explanation or engagement. 2. If I list multiple bugs/concerns in this one issue, the core team may close my issue without further explanation or engagement. 3. If I write an issue that has many duplicates, the core team may close my issue without further explanation or engagement (and without necessarily spending time to find the exact duplicate ID number). 4. If I leave the title incomplete when filing the issue, the core team may close my issue without further explanation or engagement. 5. If I file something completely blank in the body, the core team may close my issue without further explanation or engagement. All good? Then proceed! --> <!-- This bug tracker is monitored by Windows Terminal development team and other technical folks. **Important: When reporting BSODs or security issues, DO NOT attach memory dumps, logs, or traces to Github issues**. Instead, send dumps/traces to secure@microsoft.com, referencing this GitHub issue. If this is an application crash, please also provide a Feedback Hub submission link so we can find your diagnostic data on the backend. Use the category "Apps > Windows Terminal (Preview)" and choose "Share My Feedback" after submission to get the link. Please use this form and describe your issue, concisely but precisely, with as much detail as possible. --> # Environment Windows build number: 10.0.18363 Windows Terminal version (if applicable): 0.10.781.0 Any other software? Tested local Windows shell versions: 1. PowerShell 7.0.0 2. PowerShell 5.1.18362.752 3. cmd.exe 10.0.18363.752 Tested remote Unix shell versions (zsh and bash are included because pwsh is not my login shell): 1. PowerShell 7.0.0 2. GNU bash, version 5.0.3(1)-release (arm-unknown-linux-gnueabihf) 3. zsh 5.7.1 (x86_64-apple-darwin19.0) Tested Unix variants: 1. Raspbian GNU/Linux 10 (buster) (Linux 4.19.50-v7l+ #895 SMP Thu Jun 20 16:03:42 BST 2019) 2. macOS 10.15.4 (19E266) (Darwin 19.4.0 Darwin Kernel Version 19.4.0: Wed Mar 4 22:28:40 PST 2020; root:xnu-6153.101.6~15/RELEASE_X86_64) Tested ssh.exe versions: 1. OpenSSH_for_Windows_8.1p1, LibreSSL 2.9.2 2. OpenSSH_for_Windows_7.7p1, LibreSSL 2.6.5 # Steps to reproduce PS local> ssh.exe <username>@<unix_host> *sh remote> exec pwsh PS remote> exit PS local> Notes: 1. All 3 local shells are susceptible. 2. One must connect to a remote PowerShell on a Unix system. Connecting to the remote shells, zsh or bash, does not trigger the issue. Connecting to a remote PowerShell instance on a Windows system does not trigger the issue. 3. Only OpenSSH 8.1p1 is susceptible. Connecting via OpenSSH 7.7p1 does not trigger the issue. # Expected behavior Once the steps to reproduce are followed, then you should be able to use all key bindings including up arrow and down arrow to access history or home and end to navigate a command line. # Actual behavior Once the steps to reproduce are followed, then you will be unable to use some key bindings including UpArrow and DownArrow to access history or Home and End to navigate a command line. Some key bindings continue to work. Ctrl+LeftArrow and Ctrl+RightArrow continue to navigate a command line properly. I did not perform an exhaustive test of which key bindings are affected, so this is only a sample.
Author
Owner

@DHowett-MSFT commented on GitHub (Apr 6, 2020):

This might be related to a zsh issue I was just investigating. It looks like zsh turns on application-keypad-mode and then when it's terminated in a way other than exiting it fails to turn it back off.

Application keypad mode changes how the arrow keys are encoded. This is likely the root cause of the remote powershell no longer receiving them.

OpenSSH 7.7 works because it doesn't actually use VT input mode, and instead generates it itself.

Small tap trace:

exit with exit

/ appkey mode on                      / appkey mode off
|      / bracketed paste on           |      / bracketed paste off
v      v             (my prompt line) v      v
␛[?1h␛=␛[?2004h␛[?25ldhowett-sl% exit␍␛[?1l␛>␛[?2004l␍␊

exit with ^D

/ appkey mode on                / I press ^D (EOT)
|      / bracketed paste on     |/ bracketed paste off
v      v             (my prompt)vv
␛[?1h␛=␛[?2004h␛[?25ldhowett-sl%␄␛[?2004l␍␊

App key mode is never turned off.

I presume exec is like the ^D case.

@DHowett-MSFT commented on GitHub (Apr 6, 2020): This might be related to a zsh issue I was just investigating. It looks like zsh turns on application-keypad-mode and then when it's terminated in a way other than `exit`ing it fails to turn it back off. Application keypad mode changes how the arrow keys are encoded. This is likely the root cause of the remote powershell no longer receiving them. OpenSSH 7.7 works because it doesn't actually _use_ VT input mode, and instead generates it itself. Small tap trace: ### exit with `exit` ``` / appkey mode on / appkey mode off | / bracketed paste on | / bracketed paste off v v (my prompt line) v v ␛[?1h␛=␛[?2004h␛[?25ldhowett-sl% exit␍␛[?1l␛>␛[?2004l␍␊ ``` ### exit with `^D` ``` / appkey mode on / I press ^D (EOT) | / bracketed paste on |/ bracketed paste off v v (my prompt)vv ␛[?1h␛=␛[?2004h␛[?25ldhowett-sl%␄␛[?2004l␍␊ ``` App key mode is never turned off. I presume exec is like the `^D` case.
Author
Owner

@DHowett-MSFT commented on GitHub (Apr 6, 2020):

(Investigation yet to be done for bash.)

@DHowett-MSFT commented on GitHub (Apr 6, 2020): (Investigation yet to be done for bash.)
Author
Owner

@DHowett-MSFT commented on GitHub (Apr 6, 2020):

Actually, it looks like powershell itself is requesting application cursor keys mode ...

/ enable appkey
v      (powershell's prompt begins)
␛[?1h␛=PS␣
@DHowett-MSFT commented on GitHub (Apr 6, 2020): Actually, it looks like powershell _itself_ is requesting application cursor keys mode ... ``` / enable appkey v (powershell's prompt begins) ␛[?1h␛=PS␣ ```
Author
Owner

@DHowett-MSFT commented on GitHub (Apr 6, 2020):

Can you share the output of get-module psreadline|fl *?

@DHowett-MSFT commented on GitHub (Apr 6, 2020): Can you share the output of `get-module psreadline|fl *`?
Author
Owner

@DHowett-MSFT commented on GitHub (Apr 6, 2020):

Oh, I see. Yes, this is another variation of the zsh issue described above. The remote powershell says "please change how arrow keys are encoded". The local powershell, on Windows, doesn't support the different encoding. For some reason, the remote powershell doesn't say "please restore the arrow keys" when it is exiting.

That's pretty bad hygiene on their part.

@DHowett-MSFT commented on GitHub (Apr 6, 2020): Oh, I see. Yes, this is another variation of the zsh issue described above. The remote powershell says "please change how arrow keys are encoded". The local powershell, on Windows, _doesn't support the different encoding._ For some reason, the remote powershell doesn't say "please restore the arrow keys" when it is exiting. That's pretty bad hygiene on their part.
Author
Owner

@LookoutHill commented on GitHub (Apr 6, 2020):

local.txt
remote.txt

^D still produces the issue for me on either Raspbian or macOS and with either zsh or bash. I'm going to set pwsh as my default shell and see what happens.

@LookoutHill commented on GitHub (Apr 6, 2020): [local.txt](https://github.com/microsoft/terminal/files/4440207/local.txt) [remote.txt](https://github.com/microsoft/terminal/files/4440208/remote.txt) ^D still produces the issue for me on either Raspbian or macOS and with either zsh or bash. I'm going to set pwsh as my default shell and see what happens.
Author
Owner

@LookoutHill commented on GitHub (Apr 6, 2020):

I can't tell if this is important to your thought process, but exec isn't important for triggering this issue, it still happens if you just run pwsh then exit it and then exit the logon shell.

@LookoutHill commented on GitHub (Apr 6, 2020): I can't tell if this is important to your thought process, but exec isn't important for triggering this issue, it still happens if you just run pwsh then exit it and then exit the logon shell.
Author
Owner

@LookoutHill commented on GitHub (Apr 6, 2020):

Yep. The issue happens even when pwsh is my login shell, so zsh and bash are out of the equation.

@LookoutHill commented on GitHub (Apr 6, 2020): Yep. The issue happens even when pwsh is my login shell, so zsh and bash are out of the equation.
Author
Owner

@LookoutHill commented on GitHub (Apr 6, 2020):

Application keypad mode changes how the arrow keys are encoded. This is likely the root cause of the remote powershell no longer receiving them.

Repeatedly connecting to remote sessions doesn't help. The remote sessions continue to have key bindings work normally, but they are still broken in my local shell (PowerShell or cmd).

@LookoutHill commented on GitHub (Apr 6, 2020): > Application keypad mode changes how the arrow keys are encoded. This is likely the root cause of the remote powershell no longer receiving them. Repeatedly connecting to remote sessions doesn't help. The remote sessions continue to have key bindings work normally, but they are still broken in my local shell (PowerShell or cmd).
Author
Owner

@DHowett-MSFT commented on GitHub (Apr 6, 2020):

I looked through powershell, psreadline and dotnet-runtime, and I'm stumped as to where the issue lies. However, I'm gonna move this one on up the chain. https://github.com/PowerShell/PowerShell/issues/12268

@DHowett-MSFT commented on GitHub (Apr 6, 2020): I looked through powershell, psreadline and dotnet-runtime, and I'm stumped as to where the issue lies. However, I'm gonna move this one on up the chain. https://github.com/PowerShell/PowerShell/issues/12268
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#7300