Sqlite3 db unclean shutdown after Windows hibernation

I’m running latest HA in Windows 11 Hyper-V. If I shutdown HA either with hassio.host_shutdown or with PS stop-VM (they seem to be the same), and then restart the VM, the log is fine. If, however, the Windows machine has been hibernated (and returned) in between shutting down the HA host and restarting it, the log complains that “The system could not validate that the sqlite3 database at //config/home-assistant_v2.db was shutdown cleanly”.

  1. How is the cleanly shutdown db (or HA’s sense of it) being affected by the Windows hibernation to cause this, and how can I remediate it? (this question may well be beyond the scope of this forum)

  2. in lieu of an answer to 1), is there a way to tailor an automation with a trigger based on this specific log entry? I could use that to restart HA and clear it.

Thanks.

You are brave…
Friends don’t let friends run HA on a windows computer.

Your database relies on a clean shutdown to write all buffered entries from memory to disk - not only sensor data but error log and status entries. If this doesn’t happen, the database ‘dirty bit’ flag is not reset and the checking routines on restart will show the integrity is compromised and produce the error you have encountered. You not only run the risk of database corruption, but at a lower level, your virtual disk drives risk data loss too.

Often there won’t be any internal corruption, but the risk is there. Is the risk worth it? A strong no!

Hibernation should allow for restart if any events arrive or tasks like automations need to happen. HomeAssistant has an enormous amount of activity going on in the background. Your Windows environment should not be hibernating if hosting HomeAssistant, otherwise the VM will fall increasingly behind, overflow or miss vital events. HomeAssistant is designed to run 24/7/365 and hibernation is not allowing it to.

For your comparison, imagine putting your vehicle automatic transmission into Park while travelling along the freeway at 100mph to slow you down - bolts will tinker out the bottom. Highly dangerous.

Your host shutdown process to hibernate or restart should provide for a clean signal to the VM environment and give it adequate time to close. Often this is a configuration issue, outdated software, or inappropriate platform choices.

Make sure your environment is stable (not crashing and available all the time), has adequate resources allocated (memory, storage, CPU), and the backups are regularly tested for integrity as there is a real risk they will become truly damaged and you will lose your data.

A close examination of your system error log may be advised, both in HomeAssistant as well as Windoze. What is causing the unexpected and abrupt database shutdown? Should your host platform hibernate at all?

Examine your Windows power settings and turn off hibernation. Yes, turning off your monitor when when your system is unattended may be smart, but shutting down your system to save power is inviting disaster in a hosting environment, as you have found out.

[Please remember to use forum </> formatting if posting code or error logs for readability purposes]

While I have basically nothing to add to IOT7712’s excellent writeup, I do want to emphasize what he said:

Your Windows environment should not be hibernating if hosting HomeAssistant

Home Assistant is a server, not a desktop app that you only open occasionally. It relies on being allowed to run freely and at full speed at all times.

Sorry, I’ll re-paraphrase the vehicle comparison.

You’re driving over a bridge in your car. All of a sudden the bridge vanishes. Poof! You’re in the air above a chasm. You’re free falling. The rocks below are sharp. Doing up your seatbelt is not going to prevent your car from crashing. Having a first aid kit under your seat is not going to stop the inevitable crash. The laws of gravity continue to apply.

The solution? Don’t drive.

Your VM hosting environment is your problem. Never hibernate that.

Maybe you are using your Windows environment inappropriately. Yes, when not using a browser to access your headless HomeAssistant server, putting it into hibernation should be fine, however the HomeAssistant server itself needs to continue running all the time, something you may not have realised.