When a machine breaks, it needs to be cleared and reset. The simplest way of delivering a fresh machine is to deconstruct and rebuild.
I did a quick test, and the game does allow doing order_upgrade from the entity to the same entity, but this maintains the active state and does not fire a robot_mined_entity event so there's no good hook to do what the mod needs to do.