Magnetic confinement fusion relies on plasma heating and plasma control using gyrotron oscillators providing at megawatt power levels. The operational reliability decreases when operating at the performance limits due to increasing parasitic mode activity. This work demonstrates for the first time the automated, fast recovery of nominal gyrotron operation during a pulse by exploiting the hysteretic gyrotron behaviour after a mode switch being in use at the Wendelstein 7-X ECRH facility.