Backport HA changes from 4.2.0