How do you allow users to undo actions when the application supports autosave

Many web applications adopt the 'autosave' design pattern for a number of different reasons. One of them is so that changes are not lost when users have completed a number of tasks or actions and forgets to save, another is when the connection is not stable and sometimes the application runs in offline mode so it keeps the states of the application consistent.

I am wondering how these types of applications allow for the user to undo actions, because the triggers for autosaving may not correspond to the logical chunks of actions that the user has performed, and it may not be obvious to the user what the actions are that they want to undo.