Hmmm. I ran into a similar problem with my multifill script.
Is there a freeze/thaw call for undo?

Ultimately the solution I came up with was to copy the active layer then use the paste as new image pdb call, then disable the undo stack on the new image only when all the processing was done I did a copy paste back into the original image (that just has an undo group)

That might help?

-Rob A>