Solved. I was wrong about ACTIVITY_HOLD having anything to do with it.
The problem is this:
If a unit under AIcontrol is in a group of more than one (that is, with other units) make it leave the group.
Allow units that are under AIcontrol to group with eachother.
What's the problem? Well what happens is the AI is forced to leave the group, then return to try again. The next time they run the normal routine, find someone to group with and do so.
The next time now being two in a group the unit is forced to leave the group and return to try again... always grouping with the same unit, which is in the same plot, then being forced to split on the next try.
So it's caused by a unit deciding to join a group, then being forced to leave said group, then joining, leaving and so on forever.
I see two possible solutions
Easy but not very good solution:
In CvUnit::canJoinGroup once again make sure you can't group AIcontrolled units (the code is there, just commented out)
Better but not as easy solution: (there are many variations of this, this is just one of them)
Don't force units to leave groups with other AIcontrolled units. This code in CvUnitAI::AI_update() would need to be changed:
Code:
if (getGroup()->getNumUnits()>1)
{
joinGroup(NULL);
return true;
}
Looping through each unit to see if they're ai controlled should work, like this:
Code:
if (getGroup()->getNumUnits()>1)
{
CLLNode<IDInfo>* pUnitNode = getGroup()->headUnitNode();
CvUnit* pLoopUnit;
while (pUnitNode != NULL)
{
pLoopUnit = ::getUnit(pUnitNode->m_data);
pUnitNode = getGroup()->nextUnitNode(pUnitNode);
if (!pLoopUnit->isAIControl())
{
joinGroup(NULL);
return true;
}
}
}
Ironically while this solves the WoC it does not mean the turn can be continued - there's another unrelated WoC in another part of the code, causing the same split-and-join behavior

(pretty sure I know the cause, just gotta add one if statement to fix it)
Another possible solution would be to see if the head unit is in the same AIControlled state as this and leave the group if not. (aicontrolled head, nonaicontrolled unit --> leave group; nonaicontrolled head, aicontrolled unit -> leave group). The problem I have with that is it can break up a big group, human or AI, simply because the head unit became AI controlled.