When attacking a settlement, you are required to defeat all defenders. Reading through the bug reports, it seems that this mechanism is a frequent cause of blocking bugs (invincible molerats, settlers in a different settlement, etc). I just found one myself by the way, Unique NPCs has the option to add new types of settlers. One of the added settler types are children. Of course they cannot be killed, you see the problem there... I think that you should add some fallback code. If the attack progresses far enough that only a small number of defenders are left, that code should check if these defenders are somehow not as expected (wrong race, in wrong location, essential) and if so remove them from the list of defenders that need to be defeated. PS: This is not a help request, I solved my problem by installing Killable Children.