Maybe keeping the custom Ai as human or orc, will make it dont recognize the peasants/peons you built.
About the towers again: I just found a similliar bug somedays ago. Theres a field at the botom of the unit' informations thats called "Unit Equivalences". Find this in your Scout Towers and Put the Guard and Cannon towers on this field. Without this, after the AI finishes an ugrade, it will count that a tower is missing, as if it was "destroyed by enemy attacks". Puting the tower's upgrades on these fields tells the AI that tower wasnt destroyed, its still there, it was just upgraded.
EDIT: Forget what I said above. It just tells AI to replace units, not to do the upgrades.