Firstly, there's the Doha agreement which includes (as described by Wikipedia):
a Taliban pledge to prevent al-Qaeda from operating in areas under Taliban control
That seems to be the main failsafe. The Taliban should prevent Afghanistan from becoming a safe haven for international terrorists. Failing that, the Taliban will have broken the agreement and the US and allied forces can go back to Afghanistan fight the terrorists.
This isn't just my take, it's also how Jaap de Hoop Scheffer, who was the NATO secretary general from 2004 to 2009, described their take on the current US and NATO withdrawal in an interview with Dutch current affairs program Nieuwsuur. He was quoted saying:
Als straks blijkt dat de Taliban te weinig doen tegen al-Qaida en IS, sluit ik niet uit dat de Amerikanen weer de leiding zullen moeten nemen om militair in te grijpen.
If it later emerges that the Taliban is doing to little against al-Qaeda and IS, I don't exclude the possibility that the Americans will have to take the lead to intervene militarily.
In other words, if terrorists threaten the US or other NATO countries from Afghanistan then it's possible that there will be a new NATO mission to fight those terrorists on the ground.
That's also what the US president Biden has said on the subject. From a press conference in April 2021:
But — but we’ll not take our eye off the terrorist threat. We’ll reorganize our counterterrorism capabilities and the substantial assets in the region to prevent reemergence of terrorists — of the threat to our homeland from over the horizon. We’ll hold the Taliban accountable for its commitment not to allow any terrorists to threaten the United States or its allies from Afghan soil.
And in a more recent speech in August of 2021, President Biden said:
Our mission in Afghanistan was never supposed to have been nation-building. It was never supposed to be creating a unified, centralized democracy. Our only vital national interest in Afghanistan remains today what it has always been: preventing a terrorist attack on American homeland.
I’ve argued for many years that our mission should be narrowly focused on counterterrorism, not counterinsurgency or nation-building. That’s why I opposed the surge when it was proposed in 2009 when I was vice president. And that’s why as president I’m adamant we focus on the threats we face today, in 2021, not yesterday’s threats.
In that same August 2021 speech, the president also remained open to the possibility of fighting terrorism without a permanent military presence on the ground in Afghanistan:
We conduct effective counterterrorism missions against terrorist groups in multiple countries where we don’t have permanent military presence. If necessary, we’ll do the same in Afghanistan. We’ve developed counterterrorism over-the-horizon capability that will allow us to keep our eyes firmly fixed on the direct threats to the United States in the region, and act quickly and decisively if needed.
So the current US withdrawal is not an end to fighting terrorism if they are using Afghanistan as a home base, it's ending the broader scoped missions. For example, ISAF (2001-2014) was (also) about security within Afghanistan and training Afghan forces. It later rolled over into the Resolute Support mission which was (according to Wikipedia):
to provide training, advice and assistance for Afghan security forces and institutions in their conflict with extremist groups such as the Taliban, the Haqqani network, and ISIS-K.