If the AI's enemy destroys your farm before it has been completely built (not the same as theai cancelling the building), your AI will not be able to build another farm for the rest of the game. This is true for all buildings in fact - we used to refer to it as "the destroyed while under construction" bug. It's just plain bad luck if it happens to you, and it is reasonably rare.