President Donald Trump is right that it's time for the U.S. to end its longest war. He needs to stop making this harder.

The president last weekend canceled a summit at Camp David with Afghan and Taliban leaders that was meant to finalize a peace deal. He had little choice. The decision followed an attack in Kabul that killed a U.S. soldier. Welcoming Taliban officials to the U.S. just a few days later would have been wrong.

The mistake wasn't canceling the meeting — it was summoning it in the first place. The purpose wasn't to move along the talks. Taliban officials said they had no intention of meeting with Afghan leaders or amending the draft agreement, which reportedly trades a withdrawal of U.S. troops for Taliban commitments to stop Afghanistan from being used as a terrorist base.

The planned event was mainly to afford the president a photo opportunity. As this scheme fell apart, the abrupt departure of Trump's third national security adviser, John Bolton, compounded the impression of disarray. Not for the first time, Trump's theatrics backfired.

A deal along the lines envisioned still makes sense. Refusing to deal with the Taliban and leaving the bulk of American troops in Afghanistan indefinitely isn't an option. There are too few troops to roll back Taliban gains, and their presence keeps the insurgents fighting. Dragging out hostilities would ensure instability and the deaths of thousands more Afghan civilians.

The withdrawal process needs to resume. As before, the challenge is to prevent Afghanistan from falling back into civil war and becoming a terrorist haven. So in any final agreement, the U.S. must keep as much leverage as possible for as long as possible. That means planning the departure of troops not by the U.S. political calendar — the draft deal apparently aimed for full withdrawal by the end of 2020 — but by concrete actions.

Meanwhile, the U.S. should do what it can to hedge against Taliban backsliding. This means supporting the Afghan government with money and technical assistance, and emphasizing that international aid will vanish if the Taliban seize power violently. The U.S. must press Afghanistan's neighbors to work for stability rather than promoting their proxies' interests. And U.S. forces should develop their capacity to gather intelligence and strike targets even after a full withdrawal, to prevent a resurgence of al-Qaida and Islamic State.