When you should discuss the renewal of a contract will depend mainly on whether the contract has a renewal clause or not.
Contracts sometimes have renewal clauses which allow the terms of the agreement to be renewed automatically or under certain conditions. if a renewal is automatic, the other side might have the option to opt-out of the renewal in which case you should discuss the renewal ahead of their opt-out notice.
If a contract doesn't have a renewal clause it is important to assess if there will still be demand for the services provided under the agreement after the end of the initial term. If there is and both parties are happy with the terms then it is important to discuss the renewal sufficiently in advance so that the legal work can be sorted before the end of the term in order to avoid a disruption of the services. This negotiation period should be increased If the terms need to be varied or changed.