As per the documentation for kill-this-buffer, it should only be invoked from the menu and behaves unpredictably when invoked programmatically.
eshell-input-filter-initial-space was introduced in Emacs 26. I've inlined its definition, at least until we drop 25.x support.