Michael, you are completely right that my previous change was not necessary. I blame my prehistoric knowledge of Emacs here, as I wasn't aware of the change to use INSIDE_EMACS. On testing, it seems that EMACS=t just happened to work in bash (for legacy reasons, probably other dinosaurs like me), and INSIDE_EMACS also disables editing, and fixes my problem.
You are also quite correct that INSIDE_EMACS was being set by tramp. The problem was that it was set at the wrong time: we need it set *before* we start the shell, to disable readline bracketed paste (and other advanced features) before we start, for example, interrogating the remote system for the running version with `uname` during `tramp-open-shell`.
I have attached a patch that moves two variables, TERM and INSIDE_EMACS, out of `tramp-remote-process-environment`, and instead, handles setting them prior to shell execution.
This has two advantages:
First, INSIDE_EMACS is visible to the shell we are about to probe for usability, which fixes my own problem with bracketed paste support in libreadline / bash breaking, and which makes it uniformly available on the remote host.
Second, changes to `tramp-terminal-type` (and the TRAMP version) are now handled correctly without having to recompute the value of `tramp-remote-process-environment`; previously this was not done, and a restart or user intervention would be required to correct them.
Hopefully this meets with approval, so I append both the patch, and what I think is the appropriate changelog entry for this, to be manually added: