There will always be issues that will delay the project that you couldn't have predicted and priced in at the start, requirements will often change during the project, there can be new feature requests which will further push the deadline.
Much better to instead sign a contract for fixed amount of time (6 months of consulting services for example). You will work on the project for the time defined by signed contract.
A month before your contract ends sit down with the client and estimate the current state of the project and see if additional time will be needed in which case you can negotiate contract extension. This approach is much more agile actually so most clients would prefer it I'd imagine.
Clients can keep extending your contract by 3 month chunks if they need to. If you finish everything early clients will easily find you some more work while they are paying for your consultancy services. If not you can have short notice period in the contract like 1-2 weeks so contract can be cut short.