Repository: vscode
Issue: Missed key presses and jumpy cursor in terminal when working remotely with high latency
Labels: bug,remote,confirmed,terminal-local-echo

<!-- ⚠️⚠️ Do Not Delete This! bug_report_template ⚠️⚠️ -->
<!-- Please read our Rules of Conduct: https://opensource.microsoft.com/codeofconduct/ -->
<!-- 🕮 Read our guide about submitting issues: https://github.com/microsoft/vscode/wiki/Submitting-Bugs-and-Suggestions -->
<!-- 🔎 Search existing issues to avoid creating duplicates. -->
<!-- 🧪 Test using the latest Insiders build to see if your issue has already been fixed: https://code.visualstudio.com/insiders/ -->
<!-- 💡 Instead of creating your report here, use 'Report Issue' from the 'Help' menu in VS Code to pre-fill useful information. -->
<!-- 🔧 Launch with `code --disable-extensions` to check. -->
Does this issue occur when all extensions are disabled?: Yes

_Note: VSCode Remote Development does not seem to work when starting with extensions disabled.
Instead, I used Extension Bisect (which does not seem to disable the remote extension) and the result was that the issue still occurs with all (other) extensions disabled._

<!-- 🪓 If you answered No above, use 'Help: Start Extension Bisect' from Command Palette to try to identify the cause. -->
<!-- 📣 Issues caused by an extension need to be reported directly to the extension publisher. The 'Help > Report Issue' dialog can assist with this. -->
- VS Code Version: 1.57.0
- OS Version: macOS Catalina 10.15.7 (Darwin x64 19.6.0)

**Context**
I work fully remotely with VSCode Remote Development via SSH.
The servers of my company are on the other side of the globe, so I have some natural SSH lag when working.
Sometimes there are spikes where the latency gets higher, in these moments I sometimes get incorrectly rendered text in the integrated terminal in VSCode.

**Steps to Reproduce:**
1. Have a remote setup with high latency
1. Type quickly in the terminal

Expected Result:
The terminal should show the exact result of the key sequence I typed (probably after a delay).

Actual Result:
Sometimes the terminal is missing a character (key press did not render) or erroneously shows a deleted character (backspace did not render). Some examples I had today:
- I type `git commit` and the terminal shows `gitcommit`.
- I type `c` `f` `<space>` `<backspace>` `<backspace>` `d` `<space>`, so I expect `cd `, but got `cfd `.

**If I reload the window, the terminal will actually display the correct text, so the key presses were registered and sent to the shell correctly! Just the rendering in the integrated terminal is bugged!**

Further insights from my investigations:
1. Some days it does not happen at all, sometimes I get these every 5 minutes.
1. If I open e.g. iTerm on my Mac and ssh into the remote server, I do not have these issues.
1. Since I have a complex ZSH setup with many plugins, I checked that the problem also happens with a stock bash shell in the integrated terminal. It seems to happen less often, but it also happened.
1. After the initial bug, continuing to use the terminal will lead to all kinds of weirdnesses, e.g. I was able to "delete" my prompt lead character by hitting backspace afterwards.
1. I have this issue already since I started working remotely (8 months), but hoped that others have the same problem and it would get fixed. But here I am now writing this report.