Algebraic obstructions and a complete solution of a rational retraction problem