While writing Opentype code after using undo (cmd Z), the code is accidentally undone piecemeal and in a random place. Attempting to undo the change results in the same thing. You have to start writing again from scratch.
Probably the problem is connected to macOS Monterey.