Software Developers are Quitters
linkedin.com
linkedin.com
The OP's scenario implies that all the obligation runs in one direction -- the contractor is morally obligated to stick around until the project is over. That's not how a business relationship is supposed to work.
The company will certainly fire the contractor the instant it makes fiscal sense. It is only fair that the contractor should quit the instant it makes fiscal sense.
If the company wants to incent the contractor to stick around, they need to hire the contractor as a regular employee, providing insurance, pension, stock options...