Formulate supports undo via the Go Back button at the bottom-right of every form. Your code is being executed to build up the form in real time, so implementing undo isn't as simple as it otherwise would be.
Here's what we do: we replay the form from the beginning – substituting cached data for user input and
fetch requests – and simply stop one question prior to the question you're currently at, controlling for non-determinism very carefully.
This idea also allows us to ostensibly resume execution of your code when the page is refreshed.