We invaded for good reason, just the nation building ambitions didn't work out. Largely because Pakistan is a backwards shithole along the border and there's a never ending stream Taliban militants coming across the border into Afghanistan as they please. And of course, in that it was always a lofty ambition anyway given the tribal and lawless nature of much of Afghanistan.
Nation states and nationalism is a largely European concept, Afghans largely identify with their tribe or ethnic group, and along religious groups. How are you going to get Pashtuns and Tajiks to unify and fight for a common Afghanistan when they don't identify with the concept of a nation state?
It's the tribe and the region they hail from that most Afghans seem to identify with. They're not going to give their lives for an alien nation state in Kabul against Islamist militants with a clear unified ideological goal. That's why they're so easily routed. They don't believe in the state or nation, they believe in the immediacy of their families, regions, tribes etc. They're splintered and don't have clear common goals, meanwhile their enemy is the opposite and ever present.
The West couldn't stay there indefinitely, it's tragic but the nation building efforts were always hugely ambitious, and largely futile as we've since seen. Afghanistan will probably be no different in 100 years.
If all we're worried about at this point is preventing terrorist training camps popping up harboured by the Taliban again, I think it'll just be a detached routine trimming with drones going forward, indefinitely.
Tragic for all the ordinary Afghans who wanted to live in a modern nation-state, but it's difficult to see how it realistically can ever be achieved at this point.