By June 244, the Wei army had become stuck in a perilous situation as they could not advance beyond Mount Xingshi and their supplies were running low. Sensing that defeat was imminent, Cao Shuang's adviser Yang Wei () tried to persuade his superior to pull back the Wei army before it was too late. However, Cao Shuang listened to Deng Yang and Li Sheng instead and ordered his troops to hold their positions. After Cao Shuang's co-regent Sima Yi wrote to Cao Shuang's deputy Xiahou Xuan and warned him of the danger they were in, Xiahou Xuan became fearful and managed to convince Cao Shuang to retreat. In late June or July, while the Wei army was retreating, Fei Yi led the Shu forces to launch a three-pronged attack and inflicted a devastating defeat on the enemy with Cao Shuang barely escaping alive.