The paper proposes a framework for on-the-fly repairing critical embedded software which is developed using formal derivation techniques. When a failure occurs during runtime, recorded information about software derivation history helps to identify and locate the original error in early phases of the development process quickly and precisely; afterwards we can tentatively correct the error and reconstruct the software until the failure is removed. An implementation of a semiautomatic tool demonstrates the feasibility and leads to a general comprehension of the framework.