I always laugh at that typo, hah. Thanks to Erik (sharevari) for pointing it out a while ago.
I can’t see anything obvious at the moment in your crash log.
There shouldn’t be anything legacy about that function/script, either, as far as I know.
Apart from a very tiny change I made (the addition of the local rounding function) to make the resize_pattern() function totally self contained for usage in your tool, and your addition of the optional patternresize parameter, the source code is otherwise completely identical to the 2.8 API 3 version of my Pattern Resizer tool which is obviously working quite ok.
One thing, though: My resize_pattern() function does insert a new track to use as a temporary work area during the expanding/shrinking/etc. Do you possibly have some notifiers listening for tracks being added/removed, and you’re responding to that somehow? Maybe doing something that is somehow clashing with the other functionality in your clone and expand function?
Also, have you tried to simply run the resize_pattern() function directly on the pattern itself, to make sure that nothing weird is happening there? Would be nice to rule that out.