Julia Gillard being welcomed to the Boao Forum by Xi Jinping, President of the People's Republic of China. Photo: AAP
It has been said before that if it weren't for bad luck, Julia Gillard would probably have no luck at all.
This was a foreign policy Rubik's Cube and one Gillard alone can claim credit for puzzling out.
That's the way it looked again this week as the brinkmanship on the Korean peninsula stole oxygen from the first days of her China visit and an asylum seeker boat got as far south as Geraldton, just as she wrapped up the trip on Wednesday.
The Korean crisis was not on the formal agenda of the annual Bo'ao Asia business forum, which kicked off Gillard's diplomatic tour de force.
But it may as well have been. It dominated talk on the Bo'ao sidelines and was referenced by leaders including hosting Chinese President Xi Jinping and by Gillard herself.
But, surprisingly enough, she was not animated by the inconvenient timing of Kim Jong-un's prelude-to-war pantomime.
A survivor of many bad moments during her troubled premiership, Gillard is now philosophically of the ''what doesn't kill you makes you stronger'' school.
But her equanimity stems from something else also: namely, an assessment that the bizarre North Korean situation will not, as many fear, become a full-blown military crisis with nuclear dimensions.
Gillard views the North's bellicose posturing as just that.
And, importantly for the bigger picture and the optics of her visit, she remains confident of Beijing's capacity to contain the problem.
Great powers, she believes, whether established like the US, or emerging like China, need a substantial degree of strategic space in which to operate.
What they do not need is to be further hemmed in by the expectations or ''principled'' advice and demands of others. Thus she is unmoved by the many calls for China to more overtly rein in its renegade client state, or by fears Beijing will simply sit on its hands.
It is a nuanced reading of complex international circumstances for which Gillard was expressly not well known in her early days as Prime Minister.
Having taken over from the foreign affairs obsessed Kevin ''747'' Rudd, Gillard initially attempted to play down any fascination for travel or the world stage.
This was a mistake. Like many a tactical blunder, it was a clunky attempt at alternative positioning transparently designed to mark her out against Rudd as domestic in orientation and suburban in essence - a leader, yes, but a reluctant one far happier in socks and trackies in front of the telly than in business jets, glad-handing her way around the power councils of the world.
No doubt, she would willingly retract this disgracefully anti-intellectual sentiment if only because it didn't work.
It was always silly anyway because it unwisely surrendered one of the few genuine advantages of incumbency: the responsibility to travel internationally and the authority that attaches to it. She might also want to live it down because, as (rotten) luck would have it, foreign policy now stands as Gillard's most unalloyed strength.
Who knew? During her short time at the top, this reluctant diplomat has driven three of the most important foreign policy articulations for Australia in decades.
These are: the historic ''pivot'' of the US to the Asia-Pacific region with Australia placed crucially at front and centre; the long-overdue rapprochement with the world's second-biggest country by population, a colossal market and an obvious cultural confrere, India; and now the historic agreement with Beijing to elevate the Sino-Australian relations to new heights.
Each of these changes is a significant piece of work in the national interest but the fact that Gillard has managed to deliver all three in a term, given their complex interplay, is remarkable.
Each will be dismissed by Gillard's critics as the low-hanging fruit. With the US, it is self-interest in containing China. With India, it was a case of caving in and selling them our uranium. With China, it is mere window dressing. Forget about it. This was a foreign policy Rubik's Cube and one Gillard alone can claim credit for puzzling out.
Think about it. Simultaneously deepening Australia's defence and strategic enmeshment with the US while restoring damaged and neglected relations with the emerging economic giant of India and then finding a favoured path to the inside councils of China, the great rival of both India and the US.
Which brings us back to luck. The China deal is big and has made front-page news in Beijing. But any credit will come too late for Labor.
Gillard began declaring she was not interested in diplomacy and yet finished up being substantially better at it than the self-important preeners she succeeded.
Foreign policy will be her enduring legacy but few votes turn on it and it has all come too late, anyway, to make a difference in September.
Mark Kenny is chief political correspondent.
Paul Sheehan is on leave.