Autocompleting a single word records two undo actions. First undo deletes the whole word, second undo adds back the original text. This is different than autocompleting with more words which records only one undo action.
Attached patch fixes this.
I won't be able to review this until next year.
Thanks for the heads-up. It's a single line...