Tell HN: I have found a hardware heisenbug in my laptop
My configuration is pretty default for Debian: when the lid is closed, the system sleeps, and when the lid is opened the system unsleeps. But if the lid opens and quickly closes due to vibration the system unsleeps and keeps working. If something heavy is running, the battery drains quickly. If you think that nothing heavier than an e-book is running then check your open e-books for any epub files opened. Atril the default viewer uses WebKit for rendering epub which means absurdly heavy CPU load which was my case.
What about the bug with the lid, it is unfixable on a program level. That reed switch is controlled by BIOS, and when the open-lid signal is received, the BIOS thing is going to be busy for several seconds doing some work to get the system unsleep. Solving the problem using bash script with asking the reed every 5 seconds seems like worse than a problem. Since the bug is hardware-caused, the solution has to be hardware as well. Bigger laptops from this series have a lock to prevent this from happening but this device has extremely little room inside of it so I understand why this model doesn't have the lock. Now I tie my laptop with rubber to prevent it from opening while traveling.
Such a pity no mobile device vendor does anything to prevent battery-powered devices from extra charge-discharge cycles.