Bit of a weird one, this.
#5788 is a situation where an entity ended up in GATHER.APPROACHING while out of the world (Haven't really investigated how, but that sounds possible if it's killed/renamed on that turn). That failed, since it can't move, it then switched to findnewtarget, which found resources to collect, and then looped back to gather.approaching, which failed again.
To fix this, I check in FINDINGINDNEWTARGET that the entity actually has a position right now, which seems sensible in general, and actually lets de-indent slightly.
There is a subsidiary question: how did this entity end up doing:
WARNING: Setting next state : INDIVIDUAL.COMBAT.ATTACKING WARNING: Setting next state : COMBAT.FINDINGNEWTARGET WARNING: Setting next state : INDIVIDUAL.GATHER.APPROACHING WARNING: Setting next state : FINDINGNEWTARGET
while somehow out of the world.
Based on the video at #5788, the most likely case is that then entity promoted, thus got renamed, and thus the OG entity ended up being in an invalid state.
Reported by user psypherium on the forums, and actually caught on video: https://www.youtube.com/watch?v=fV5MZ7aBS5Q&feature=youtu.be&t=2302
Thanks to @Angen for pinging me.