Magnetically induced termination of giant planet formation