This doesn't happen in Emacs-25, largely to address the use case you are
describing.
It was caused by this code in undo.c
if (current_buffer != last_undo_buffer)
Fundo_boundary ();
last_undo_buffer = current_buffer;
Most of the code handling automatic undo boundaries is now in simple.el.
Phil