I've encountered a similar problem with enemies from https://mods.factorio.com/mod/enemyracemanager (ERM), when the event on_unit_group_finished_gathering is fired. Might be the same root cause for the problem, though I didn't check with Rampant.
The problem seems to be that "Enemy Alert" doesn't handle compound commands well, which I guess (maybe) Rampant and ERM fires, maybe base Factorio doesn't (I'm not a modder, I have no clue).
At control.lua:57/59, Enemy Alert tries to access the property command.destination. That works well for all types of commands as defined here https://lua-api.factorio.com/latest/defines.html#defines.command, but not for the compound type, which is itself an array of multiple commands. Within all these commands, there is a property "destination"; but not on the parent compound command.
E.g. this is the result if you hack a "log(serpent.block(group.command))" into control.lua at line 52:
{
commands = {
{
destination = {
x = -75,
y = 52
},
distraction = 1,
pathfind_flags = {
allow_destroy_friendly_entities = false,
allow_paths_through_own_entities = false,
cache = true,
low_priority = false,
no_break = false,
prefer_straight_paths = false
},
radius = 32,
type = 2
},
{
destination = {
x = -18,
y = -146
},
distraction = 1,
radius = 32,
type = 5
}
},
structure_type = 2,
type = 3
}
type 3 is compound, and within it is a type 2 (go_to_location) and a type 5 (attack_area) command. The event probably fired because the compound command contains a type 2, thus Enemy Alert ist triggered, but instead of taking into account the compound command and iterating through the array of commands to find the "real" go_to_location command and get its property "destination", it tries to get "destination" from the parent compound command, which fails.
Whereas a "simple" command looks like this:
{
destination = {
x = -727.12109375,
y = -1083.7578125
},
distraction = 1,
ignore_planner = false,
type = 7
}
On the latter, the property "destination" is defined and Enemy Alert works. On the former, the encapsulated commands all have their property "destination", but not the parent structure, this Enemy Alert fails and crashes Factorio.