It was implied in the accounts regarding Shangguan's death that he was arrested and killed on the same day, but it could have been that he was merely arrested on January 4, 665, and not executed until sometime later. See Zizhi Tongjian, vol. 201 and New Book of Tang, vol. 61.
As Yang Gongren became acting commandant of Yang Prefecture sometime after the start of Emperor Taizong's Zhenguan era in 627 and became the commandant at Luo Prefecture (洛州, roughly modern Luoyang) in 631, Yang's recommendation of Shangguan must have come between those years. See Old Book of Tang, vol. 62.