The best thing the soviets could have done is limited involvement. Air support and training the Afghan army along with using special forces. If the Soviets seem like occupiers they can't win.
Have the USSR survive and you have it; they had effectively won the war when they had pulled out and had inflicted far higher losses upon the Muj than they had received in exchanged compared to the Coalition in Afghanistan since 2001. What ended up costing them the war was the end of the USSR's support to the Afghans Post-pullout and political infighting within the Afghan regime.