Yep, definitely some need for improvement on the code side, thanks for letting us know
It's a combination of issues related to the rules for when an AI unit "frees" from guard duty to attack and the rules for when human units auto-fire on units, or more specifically when they don't. In an effort to not free a ton of extra AI ships your ships typically avoid firing on non-free AI ships, etc.
To give an example, when I was testing one of the command-station guard missile frigates sidled up and started taking potshots at your turret network. The turrets didn't return fire because doing so would alert/anger the missile frigate and the unit it was guarding. Since the unit it was guarding was the command station, that basically means angering everything on the planet.
But something did seem weird with how close the AI units were able to get to you while maintaining their guard status, so will be investigating that.