Usually I replace my phone when the battery is almost dead and a full charge doesn't last more than a few hours. At that point the phone is usable but not good enough to sell. I usually keep it as an emergency backup phone

For some reason I tend to break screens way before the battery dies usually. I am not afraid to replace a battery or even a screen if phone is not totally out of date. Having said that there seems to always be a point when they start acting semi eratically or stop booting.

I had a totally outdated and probably insecure Samsung S6 edge 2 years ago that started rebooting randomly. I think that prior to that it was so old I could only install stuff from f-droid and aurora because roots certs installed on that old android version were too old for playstore to work. Too bad as you can't easily find smartphones in similar sizes anymore.

Knocking on wood my pixel 6a still going strong after 2 years.

You might as well buy a new battery then

Did that for 20 € for my Oppo Find X3 Pro at my closest tech store and saved me from buying a brand new phone

I damaged the screen of my pixel trying to open it to replace the battery. It was literally booby trapped to self destroy when trying to repair it