recoverFromSnapshot() {
        const snapshotKeys = Array.from(this.snapshots.keys()).sort((a, b) => b - a);
        for (const key of snapshotKeys) {
            if (key <= this.undoStack.length) {
                const snapshot = this.snapshots.get(key);
                this.undoStack = snapshot.undoStack.map(cmd => this.deserializeCommand(cmd));
                this.redoStack = snapshot.redoStack.map(cmd => this.deserializeCommand(cmd));
                break;
            }
        }
        this.notifyListeners();
    }
Recovers the state from the most recent valid snapshot.

@description
This method attempts to recover the undo and redo stacks from the most recent snapshot
that is not larger than the current undo stack size. It's typically called after an error
occurs during an undo or redo operation to restore the system to a consistent state.
After recovery, it notifies all listeners of the state change.

@throws {Error} If deserialization of commands fails.

@example
try {
    // Some undo/redo operation
} catch (error) {
    undoRedoManager.recoverFromSnapshot();
}