Hysteresis not working properly
Without RC filter caps on the comparator inputs, I might suggest you have  80mV of noise that triggered the low point of 3.4 or you have some input offset on the comparator.

When the battery is charging, again either you have noise or the threshold on (+) input is not  4.0V.

How is the comparator powered? And what is the output swing? And how much noise is on V- and V+ of the comparator.  It is either set to wrong threshold or there is noise.

The other problem is the lack of a good bandgap reference voltage supply on comparator output swing and thus input reference voltage for (+) and Vboost +5..  All of these sources &amp; noise + R ratios  affect your thresholds.