Alright, thank you for these explanations.
Indeed, I think we should investigate first how the undo system works in Blender. I guess we should consider the (sort of) proposal made in Access to the history stack. I will probably need to read the thread several times because I do not fully understand it for the moment. Moreover, I need to look at the source code to better see how it is done technically.
Do you already have links or resources about the undo system in Blender?