Catch more ha agent policy thread errors.

Fixes OOIION-675, and adds a test for it