In short: EU article 50 is a timer. It can be cancelled and restarted any time. Just like the programming timers we know. So, the solution is exactly what we do in programming: cancel and restart.
On 4 December 2018, the responsible Advocate General to the ECJ published his preliminary opinion that "a country could unilaterally cancel its withdrawal from the EU should it wish to do so, by simple notice, prior to actual departure".
Meaning, that the UK can cancel Brexit any time. But the UK can also restart Brexit at any time again. There are no time limits, no grace periods, no rate limiting on article 50 cancelling and triggering.
That makes the solution obvious: send two letters to the EU back to back.
- the first with the cancellation of the article 50 process,
- the second with a new trigger of article 50.
The result would be (almost) the same as the already planned 2 year transition period. The March 2019 date is only the legal departure date. for all practical purposes, the UK leaves 2 years later after the transition period (December 2020). Let's get rid of the transition period and call it a second article 50 process, another two years. Practical separation would then be March 2021, only 3 months later than already planned.
Just make a law in parliament to cancel article 50 AND trigger it immediately again.
Gives you time for a referendum or a general election or just a good transition period. Anything you want. Gives you time and changes nothing. The move just gets rid of the threatening no-deal timer.
Bonus: an extension of article 50 requires the agreement of all EU members. But the cancel/restart-move can be done by the UK alone.
Bonus Bonus: 2 years transition is what the Brits wanted, but the EU wanted a clean end of year date. So they settled for 21 months. A simple timer reset makes that 24 months again. Owned!
The ECJ handed this solution to the UK. They know what they do. This was not an accident. They mean it. That's the way out. Just do what every programmer does with timers: reset.
PS: it's clearly an exploit and a bit shady. But it's legal. The contract is not meant to be used this way. But many contracts are "stretched". What happened to "no bailout" in the Euro zone? Giving Greece money to be (maybe) payed back in 50 years, is a stretch. What happened to the "prohibition of monetary financing"? Ah, yes, The ECB buy government bonds not directly from he governments, but from the "secondary markets". The ECB so much that the "intermediate" banks are actually straw men, being paid to circumvent Article 123. Another stretch. So, contracts are stretched, if deemed necessary. All we have, unfortunately, is the written word. The written words allow it AND it's necessary.
PPS: If people ever wanted to make exploit proof contracts and laws, then they could ask the gaming industry for advice. They have thousands of specialists who make a living by preventing the exploitation of coded rules. If computer games as an example are too low for you, then ask IT security experts or turn to academics in the field of game theory, the study of mathematical models of strategic interaction between rational decision-makers.
PPPS: In the long run: if you can do it twice, then think n+1. We can do this every other year. Maybe the UK and EU get used to it. Gives the UK a feeling of independence. And that's what it's all about, anyway. Every two years, UK activates article 50 and cancels it two years later. In practice: every other year, Brussels receives a briefcase with 2 letters from London.