Like everyone else states...

If the AI is stronger then you they will sally straight away.

If they are a little weaker than you they will sally just before time runs out (which never made sense to me as they would have lost troops by then so would have been better off sallying immediately).

If they are a lot weaker than the attackers they simply give up...