The advice of staretz Makary (spiritual father of Ivan Kireyevsky) on the failure to break bad habits:
'And so, your good intentions have been frustrated by forces entirely outside your control. In the hard days to come, keep constantly in mind that God knows well how firm was your resolution, how keen your eagerness to act; and he may record your intention as having the value of an accomplished fact. He is particularly likely to do so if your humility remains quick, if it does not wither under the winds of adversity.'
In other words, the failure to achieve something good (such as abandoning a bad habit) can be of spiritual value if it increases the sinners humility.
From - 'A man is his faith'