Normally, in that situation which you described, the AI should have lost the battle automatically with their last shot fired, I wonder why they didn´t. Because that´s what happened in my games when I was assaulted and the AI was unable to breach my walls. Strange.
However, it confirms what I suspected, exiting a battle before the "you have won" message will default to a loss.