One possibility that I see is out of order execution of hook scripts which is theoretically possible. Server schedules execution of hook script in background thread pool, passing copy of alarm in its current state to the script. It is possible that due to database problems thread pool was full with tasks waiting on database, so earlier script execution task was waiting on free thread, next task was scheduled in the meantime, and then both were started in parallel, possibly in wrong order.
I will think about it, but probably we have to serialize executions of alarm state change hooks.
Best regards,
Victor