It was as if all the qualities of the Brexit debate came together in perfect unison. It had everything: the cynicism, the inadequacy, the lies, the total collapse of moral or political authority. And it ended with the prime minister whipping her own MPs to defeat her and then inadvertently, by force of her own errors, voting for no-deal. It was a masterpiece of haplessness. Peak Brexit. Except that presumably things will somehow become even more ridiculous tomorrow.

It began simply enough. May had set a clear timetable for this week. First, MPs would vote on her deal again. They did that yesterday and defeated it. Then they would vote on a motion opposing no-deal today. And then, if that passed, there would be a motion on extending Article 50 tomorrow. We were in the second part of the most godawful trilogy on earth.

But the motion was nowhere near as simple as she had made out. Once again, the prime minister tried to pull a fast one. Instead of simply ruling out no-deal, it added a caveat. "That this House declines to approve leaving the European Union without a withdrawal agreement and a framework for the future relationship on 29 March 2019," it read. So far, as expected. But then came the twist. "And notes that leaving without a deal remains the default in UK and EU law unless this House and the EU ratify an agreement."

On point of law, this was simply a truism. The UK leaves the EU automatically without a deal by EU law unless it passes one or revokes Article 50. But it was a pointless truism to state. This motion was about instructing the government. It was not a complete overview of the legal documents relating to no-deal.

The real meaning of the caveat was political, not legal. It sought to keep the possibility of no-deal open. It attempted, in a shoddy and contorted way, to face both ways at once, so that the ERG hardliners would not feel that their precious no-deal nirvana had been taken away from them.

In response, Conservative MP Caroline Spelman put down an amendment. It scrapped the caveat altogether and replaced it with the following statement: "That this House rejects the United Kingdom leaving the European Union without a withdrawal agreement and a framework for the future relationship". In other words: parliament would instruct the government to rule out no-deal in all circumstances. Firmer, tougher, more comprehensive.

The government hated it. It had allowed a free vote on a seperate Brexiter amendment, called Malthouse B, which basically contained a bunch of mythical no-deal fantasies in parliamentary form. But it decided to whip MPs to defeat Spelman's contribution.

They piled the pressure on Spelman until she buckled and asked to pull the amendment. But it was too late. It was on the order paper. Even if she pulled it, Speaker John Bercow said, the co-signatories could put it forward. So the spotlight fell on Yvette Cooper, as it almost always does at these moments. She has been resolute and forensic throughout this process, using parliamentary mechanisms and forward-thinking to outmanoeuvre the prime minister at every turn. Now she was going to deliver another lesson. Cooper took the challenge and put the amendment forward for a vote.

Suddenly the moderate ministers you hear so much about were in trouble. They had briefed over and over again that they'd resign rather than accept no-deal. But now there was a motion stating exactly their view: that it should be ruled out in all circumstances. They could either keep their job or vote with their conscience. But they could not do both.

It came in tight, but it passed. A total of 312 votes for the amendment versus 308 against.

In an instant, the government went into meltdown. The amendment was now attached to the original motion. That meant that when MPs voted on it, they would be voting for the version which ruled out no-deal in all circumstances, not in the heavily-caveated form proposed by May. Suddenly, in a matter of seconds, Downing Street had to do a 180 degree turn. In a frenzy of chaos lasting about half an hour, it suddenly started whipping its MPs to vote against its own motion.

By doing so, it was effectively voting for no-deal - or at least voting against ruling it out - which went completely against the position it held just minutes earlier. But it didn't matter. Probably that wasn't even what it meant. Nothing meant anything, really. It was a bloodbath of logic. Words, actions, principles - all these things were victims of the insanity on the floor of the Commons. And all of it was pointless. The government motion never needed to be that contorted. They never needed to whip against the Spelman amendment. It was all completely unforced.

Chaos reigned. Whips strong-armed ministers, desperately trying to hold the line. Labour MP Jess Phillips saw the prime minister enter the No lobby and told her she was a disgrace. Everything was falling apart.

In the end, moderate Cabinet ministers Amber Rudd, David Gauke, David Mundell, and Greg Clarke failed to go the whole way. But they did go half the way: They abstained. Sarah Newton, minister for disabled people, to her very great credit, resigned on the spot.

And then the result came in. Not only had the government whipping operation failed, it had lost the vote by an even greater margin than the first one. It was defeated by 321 to 278.

Once again, as regular as the tolling of the village bells, May was falling apart in plain sight.

She tried to get up to respond, but she sounded like how her administration looked: utterly broken. Her voice barely worked. She managed to squeak out a harsh statement, showing no contrition or even much recognition of what had just taken place. She was, as ever, completely charmless in defeat. Presumably she would be the same in victory, but we have never seen any incidents of this to judge it.

And then, suddenly, came the sting in the tail. The government published its motion for the vote on Article 50 extension tomorrow. And again, she'd laid a trap. It was as cynical and self-interested and dismal as you would expect.

The vote on extending Article 50 suddenly had caveats. Good old caveats. May loves them. Admittedly, they have done her precisely no good whatsoever so far, but she is not really one to change tactic in the face of persistent failure.

First the motion said that the government would now pursue an extension. But it then presented two kinds. Version one would be a short technical extension, until June 30th. This is the last date before the new European parliament sits. It's basically the last day the UK can stay in the EU without taking part in the European elections in May. This would be sought if the House approved a deal before March 20th.

There was a sudden gasp. There it was, in black and white: the very thing we all suspected she'd try. There would be another vote on her deal. She was going to try again.

And then the second kind of extension was read out. It stated that if the extension was sought without a deal being passed it would have to be much longer, probably for a year or more, and that the UK would therefore have to take part in the European elections in May and provide a purpose to the EU for the extension. The purpose wasn't mentioned, but May had strongly emphasised yesterday that it would be simple revocation, another referendum, or a softer Brexit.

That was the pincer movement. It wasn't really an extension motion at all. It was a Project Fear publication aimed at the ERG Brexit hardliners. May was going to try and pass her deal next week. This time, she was saying, they had better vote for it, because if they didn't Article 50 was going to be extended for ages, we'd have to participate in the European elections, and there was a good chance Brexit would be taken away from them altogether.

That's the battleground now. That's where the final fight of this stage of Brexit takes place: next week, with another vote on the deal. One final swing of the dice.

Very quickly, reports started coming in that the threat might be having some effect on the ERG Brexit hardliners. Eager right-wing journalists started reporting that they were softening.

Perhaps. It is perfectly possible. But there are three obstacles before them.

The first are amendments. Tomorrow's motion can be amended. MPs showed today that they were increasingly ready to stand up and fight whereas May's government looked dimwitted and weak. Amendments put on that motion can bring it under control and take her cynical gambit away from her.

The second obstacle falls on the Speaker. Some parliamentary experts argue that the government cannot put down another motion on an identical deal because it is against the rules. It's possible he could step in to prevent this being put to MPs at all.

The third obstacle is the vote itself. Even if the ERG folds, there are enough votes in the Commons to defeat the deal. There are about a dozen moderate Tories who will vote against it. Yesterday, only three Labour MPs voted for it. That might change, of course. Many Brexiter Labour MPs could move with the ERG. But an ERG capitulation alone is not enough to secure victory, even if it does happen.

The battle plan is now clear. It is exactly as cheap and dirty as would be expected. But something else is clear too: The government is completely useless. It can be defeated. And if it is, a much longer extension and a fundamental rethink of Brexit is finally on the horizon.

Ian Dunt is editor of Politics.co.uk and the author of Brexit: What The Hell Happens Now?

The opinions in politics.co.uk's Comment and Analysis section are those of the author and are no reflection of the views of the website or its owners.