Extendscript Undo Groups (app.beginUndoGroup) always throws error
I'm working on a script and I just finished creating a function that renders certain items and then import them into after effects.
I want to add
before the function and
after the function, so I can undo all the actions within that function that affects the project.
Everything together looks like this
Here's a screenshot of all the actions performed in that function which can be found under Edit > History

This is basically the history for 1 imported item, since the final script will do this for multiple files I need an effective way to undo all actions for all items.
The errror I get with the from after effects when pressing CTRL+Z is:

"Undo group mismatch, will attempt to fix."
Otherwise everything works completely fine without the Undo groups involved.
My goal with this is to create a scriptui button that will undo all of those actions.
If any of you know a way to make this work or perhaps having the same issue then please let me know.
