Attempt to fix some rare exceptions in HackyAI

Fixes #3642.