Good question. I just started up a loop doing USB-PD hard reboots on my MBA every 18 seconds (that's about one second into the desktop with autologin on, where it should still be doing stuff in the background). Let's see if it eats itself.
Finding out if a DFU restore can recover a corrupted SSD storage would be an interesting test in and of itself!
But to be honest, if I end up really bricking a machine for science, that will be worth it for the information it gives us. Obviously I'm not trying to destroy my hardware, but I'm very grateful that I can afford it if it happens thanks to all the support I'm getting from folks for the project.
Laptops are fine unless your battery has issues and you get occasional power losses, which seems to be not too uncommon for third-party batteries (which themselves are not too uncommon since Apple will charge you an arm and a leg to replace half your laptop if you have a defective battery).
Bad batteries generally allow for last-gasp handling, and I've definitely seen the SMC throw a fit on some properties a few seconds before shutdown due to the battery being really dead. Not sure if macOS handles this properly, but I'd hope it does, and if it doesn't they could certainly add the feature. It would be quite an extreme case to have a battery failure be so sudden the voltage doesn't drop slowly enough to invoke this.
A fair fraction of the bad batteries I have seen have not behaved like this. Things like immediate power failure on disconnecting AC power, or claiming to be at 30% and then dying, or denying the existence of the battery altogether (two of these have happened to me personally—one at the ripe age of four months rather than due to age—and three or four to other family members). It’s certainly more common for them to just fade fairly rapidly to zero and die there, but it’s by no means rare for them to spontaneously fall over.
We're talking different timescales here. All you need is one second or so to command the NVMe controller to flush, and killing other power consumers in the mean time would buy you more time by reducing load, possibly even giving you several minutes the way batteries work (they tend to fall over under load when defective/dead). What may visually appear as power suddenly failing isn't necessarily so at the scale of voltage threshold interrupts and PMICs.
What usually happens is battery internal resistance is too high to sustain a given power load, so once load crosses a threshold the system goes into a spiral of doom increasing current as battery voltage decreases and you end up in a shutdown. That's the "30% and suddenly 0% or a shutdown" scenario. But if you catch it before it's too late, you can just stop consuming power and let the NVMe controller flush.
The case I have in mind where it would suddenly die around 30% would happen around that point regardless of load, even asleep, after following a sufficiently typically linear discharge curve up to that point. Maybe the power management system gets a fraction of a second’s notice, I don’t know; but it wasn’t a 30% plummeting to zero over the course of ten or thirty seconds, or even a “30%; no—0%; no—dead” case, which seem to be the much more common failure modes. As for the “pull the AC power and it instantly dies” cases, I’m a layman in battery matters, with no more than high school electronics, but I’d be surprised if there’s enough in there for it to do anything—those are cases where either it literally has no battery to draw on (because it’s electronically dead), or thinks it has a battery but discovers as soon as it tries to draw on it that it effectively doesn’t actually.
If it's literally dying at 30% with no warning, it's either the battery polling being too slow (keep in mind the UI will usually only refresh once a minute or so for these things; the power management system has faster stats), or the charge estimation being way off. There's very little reason for a battery to drop from true 30% SoC to completely dead, without first going into a power draw spiral of doom which you can revert if you stop consuming as much power.
“30% to 0” and “Pull AC and it instantly dies” are typically a combination of load and device temperature. High CPU/GPU usage, high brightness, 3G/LTE usage, and cold temps and the device doesn’t have a chance.
It’s been somewhat fascinating to monitor power usage in this really crude way. TikTok on iOS, for example, uses so much power that it’s the most likely to cause the device to shut off. FB Messenger is in the top 5. Some of Apple’s background processes will also cause it, as will paging memory to disk.
There’s another bit of information that will not surprise many people on HN: high-amperage charging will cause the battery percentage to be “more wrong”. Devices will report 45% or higher and still die as if they were reporting 30%. Charging at 500mA will not only make it “more correct”, but will typically mean that a device will not suddenly die until it’s in the single digits.
Does anyone here run a desktop Mac without a battery backup device?
All of my Macs are either laptops or have a hardware backup device, so unlikely a write would be lost due to power failure (unless backup device failed which could happen).
Where I live the power is quite dirty, so even when power losses are measured in years I invest in line-filtering UPS’ to extend the life of my systems.
I even lost a MBP to a light flickering event with 0 power loss. Fried the charging circuit straight through the original power brick.
Laptops have batteries, so an AC power failure doesn't mean they immediately crash: they just keep running on battery until the battery gets low, at which point the system cleanly hibernates.
Curious, what's the real world risk of full OS level corruption and not just data loss?