All your fixes look great but a big LOL on that one - just awesome - presumably a random number generator that just may decide some tick that you pi**ed off the Robot and it goes Terminator against you! Even nastier would be if one AI is attacked, the others all mark that attacker as hostile and engage against 'em!
BTW, is there any difference between if a player goes AFK versus QUITS?
P.S. I don’t know how/if your improvements tie into the AI tech trading algorithm, but I have noticed that the AI is a bit too “nice” about sharing. I.e. I attacked 'em and then a few turns later, they were willing to trade with me. I don’t think one attack should mark you as hostile for life, but seems like it should take longer to be marked as “friendly”