Successful COIN demands first and foremost that the population/populations where the revolutionary energy is the strongest, perceive themselves to have a viable political alternative to that which they feel compelled to revolve against - and trusted, certain, and legal ways to pursue that alternative that make sense in the context of their respective cultures.
From a Western perspective true, but this assumption ignores history. Insurgencies historically have been defeated more through the use of force than political maneuvering. Obviously we don't fight that way, but then again our approach to COIN is still looking for a victory somewhere.

The US always skips this step. We fixate on what we think is best for us, and then create or adopt some government who we believe most likely to act as we think is fit, wrap this fundamentally illegitimate entity in the nomenclature and trappings of "democracy" - and then task the military to build partner military capacity to protect this abomination from large elements of its own population. As this begins to fail of its own weight, we then apply more and more direct US energy (security, development, etc) in efforts to prop the whole thing up - but ultimately this has always failed.
Agree, and even when we can see it coming we don't change course. Operational design promotes reframing when the situation changes, but I think most people are psychologically wired to resist change, so while they may agree with reframing conceptually, doing it is another thing altogether.

When our overarching strategy was to prevail in a Cold War bi-polar contest, a tie in Korea and a loss in Vietnam could both contribute to a larger win. But that does not mean by any stretch that either of those conflicts were necessary, or even particularly helpful, in attaining that "win." They did not however cause a strategic "fail."
Of course any arguments of what would have happened if we didn't intervene are counterfactual. Still worth entertaining, but there is no way we can honestly know what would have happened. The fact that we did fight with an international coalition may have demonstrated to the communists that the West and its allies were willing to stand up to communist aggression. It "may" have served as a form of strategic deterrence that in the end prevented a nuclear holocaust. Who knows?

But what is the US larger end now?? What can a loss in Afghanistan and/or Iraq possibly contribute toward? What can they cause? They cannot contribute to a larger win because we have not defined a larger win. They can only contribute to a larger fail.
Not defined well, but I think we have defined the larger win, and that is an international order that protects our interests (clearly not black and white), and sustaining U.S. leadership (though President Obama seems to be backing away from this).

We have a grand strategy post-Cold War that is essentially to play not to lose.
Where is this articulated?

The US needs a new grand strategic focus and a game defined in terms we can play to win if we hope to get off the current odyssey of bleeding off strategic altitude in exchange for tactical airspeed. As General Zinni commented to my war college class 9 years ago, "we don't know where we are going, but we are making good time."
I don't disagree with this aspiration, but the world is changing fundamentally and frankly I don't think we know what we want the new order to look like. We have some idea of what we don't want it to look like, but that perspective results in reacting instead of proactive strategic shaping. I also think we're too divided politically to reach a consensus of where we want to go. There is little consensus on Cuba, ISIL, Iran, and Russia to name a few. If we had desired strategic goal then we could frame these issues in a larger context and make smart choices. That doesn't seem to be happening at the moment.