Microsoft OneDrive Causing Sleepless Nights (on My Mac)
My M1 Mac mini has been sleeping dreadfully recently. Perhaps it's the thought of one day having macOS Ventura installed on it, or the knowledge that its younger M2 brethren beats it in both performance and power efficiency. Or perhaps, it was something else altogether.
I could tell it wasn't sleeping due to the fact the attached USB storage would endlessly spin up and back down during the day; the Mac min sits under my desk while I work all day on my laptop. One time while it was supposedly asleep and idle, I went to plug a device into it, and could feel the fan blowing out hot air from the back. It wasn't sleeping at all.
Thanks to an app called Sleep Aid, I was able to verify that my Mac was indeed struggling to get to sleep. Even when I put it to sleep manually, it would quickly wake up and not go back to sleep again. Sleep Aid helpfully lists the processes that were active during time awake. In my case, the most active process was something called "com.apple.FileProvider.cache-delete.push".
Armed with this information, I did what any self proclaimed nerd would do; I Googled it. To my surprise, there were barely any hits. Some posts relating to Android, one on the Apple Developer forum about a bug with the File Provider API, but it didn't seem related. I was stumped. Sam Rowlands, the developer behind Sleep Aid reached out to me on Twitter and offered to check that Sleep Aid itself wasn't misreporting what I was seeing. It was not.
Eventually I stumbled across a WWDC video on the File Provider API, and decided to watch it. It dawned on me that this is the API Apple makes for services such as Dropbox and Microsoft OneDrive to use. For years, Dropbox and OneDrive have been using various unofficial hacks in order to integrate with the Finder. In 2019, Apple released the File Provider API and gradually the third party cloud sync providers have been moving to it ever since.
Apart from Apple's own iCloud Drive, I only had Microsoft OneDrive installed. I promptly deleted the OneDrive app and since then, my Mac has not had any bouts of insomnia due to com.apple.FileProvider.cache-delete.push. Problem solved.
My guess is that because I had OneDrive set not to run on system startup, and I had the OneDrive sync directory on an external hard drive, somehow the push notifications that Apple sends to indicate a file has changed were getting stuck. Perhaps OneDrive is supposed to say "I've got the file, you can go back to sleep" but wasn't able to do so.
My Mac still spends a lot of the time it is supposed to be sleeping awake, but this seems to be common in M1 Macs. Thankfully now it does go to sleep for around 40% of the time instead of 0%, helping avoid needlessly wasting energy.
So if you've got a Mac that won't sleep, I recommend grabbing a copy of Sleep Aid to help find the culprit.
Title image generated by Stable Diffusion using the prompt "a man sitting at a laptop falling asleep in a dark room at night, Cinematic" (with some edits).