This command works always (with sh or bash):
ssh -t HOST sh -c "tmux a 2>/dev/null || tmux"
These fail about half the time:
ssh -t HOST -- "tmux a 2>/dev/null || tmux"
ssh -t HOST "tmux a 2>/dev/null || tmux"
with an error from tmux, either server exited unexpectedly
or lost server
. (When testing there was no open tmux session so it always ran both commands.)
Why do they fail and only fail sometimes but not always?