However, Hao Yuan, by this point serving under Xue Ju, immediately stated: ''You, Emperor, should not ask something like this, and Chu Liang's response was absurd and rebellious. Gaozu of Han was often defeated, and the first emperor of Shu could not even protect his wife and children. Winning and losing battles happened throughout history. How can you be ready to give up your state just based on one defeat?" Xue Ju saw the fallacy in asking the question, and he greatly rewarded Hao and made Hao his chief strategist. Subsequently, when Li Yuan sent his generals Jiang Mo (), Dou Gui (), and Liu Shirang () against Xue Ju, Xue Ju defeated them and captured Liu, and Jiang and Dou withdrew. Subsequently, under Hao's suggestion, Xue sought to enter a three-way alliance with Eastern Tujue's forces and those of another rebel leader, Liang Shidu the Emperor of Liang, to try to capture Chang'an. However, Li Yuan's general Zhang Changsun () then warned the Tujue general Ashina Duobi that he was aware of their three-way pact, and Ashina Duobi chose to renege and not assist either Xue Ju or Liang. (Soon, after hearing that Emperor Yang had been killed in a coup led by Yuwen Huaji in Jiangdu (江都, in modern Yangzhou, Jiangsu), Li Yuan had Yang You yield the throne to him, establishing Tang Dynasty as its Emperor Gaozu.) In summer 618, Xue Ju launched an attack on Tang's Jing Prefecture (涇州, roughly modern Pingliang, Gansu), and Tang's Emperor Gaozu sent Li Shimin to resist Xue Ju. Li Shimin established his defenses and refused to engage Xue Ju to try to wear Xue Ju out, but at that time, he was afflicted with malaria, and he let his associates Liu Wenjing and Yin Kaishan () take command, ordering them not to engage Xue Ju. Liu and Yin, however, did not take Xue Ju seriously, and Xue Ju ambushed them at Qianshui Plain (淺水原, in modern Xianyang, Shaanxi), crushing Tang forces and inflicting 50%-60% casualties. Li Shimin was forced to withdraw back to Chang'an, and Liu and Yin were removed from their posts. Hao then suggested to Xue Ju that he should attack Chang'an at once, and Xue Ju agreed, but he then grew ill and died. Xue Rengao succeeded him as emperor and honored him with the posthumous name of Wu (武, "martial"), but was defeated by and forced