The window motors in my truck have some kind of encoder built into them. The roof door module monitors it to determine when to stop raising the window. Whenever the RDM looses power (battery disconnect) it forgets where the endpoints should be. If a window is partway down when power is restored, the RDM assumes that is all the way up. Stays that way until you reteach it. A simple process, Run the window up, hold the down button down until the window stops and for a couple seconds more, then run it up till it stops, and hold for a couple seconds.

I suspect the sunroof motor is similar. Don't know why shorting the open limit switch lets the motor close the window fully.