A Chinese agent sent to New Zealand to spy on Taiwanese Kiwis abandoned his mission, and has been fighting for 23 years to live here.
The Chinese citizen and Chinese Public Security Bureau (PSB) officer arrived in New Zealand in 1996 on a visitor visa.
The spy, known as Mr H, quickly decided "he preferred New Zealand's democratic way of life and abandoned his mission", according to a new Court of Appeal judgment.
He then applied unsuccessfully for refugee status, after failing to disclose his PSB links.
"For present purposes it was uncontested that the PSB is an organisation that has committed gross human rights abuses," Justice Patricia Courtney said in the new judgment.
Mr H then lived in New Zealand illegally. In 2007 he applied again for refugee status, this time acknowledging his PSB involvement.
He said he'd be persecuted if he returned to China, having abandoned his official duties.
His refugee bid application was initially refused but ultimately granted.
But despite that success, Mr H was unable to get a residence-class visa (RCV).
"As a result, he lives a rather uncertain life, relying on temporary work permits and unable to obtain a passport for ease of travel out of New Zealand," Justice Courtney added.
And that instability is likely to continue for Mr H.
In 2014 he applied for an RCV but was refused. He then lodged a successful appeal with the Immigration and Protection Tribunal.
But Immigration New Zealand (INZ) refused the application and the case bounced around before being referred to the Minister of Immigration without success for Mr H.
The former spy also sought a judicial review of one recent High Court decision.
It was that matter the Court of Appeal concerned itself with.
A pivotal issue for the Appeal Court related to an INZ test which stated applicants who posed a risk to New Zealand's global reputation should not usually get residence-class visas.
The rule was introduced in 2005 due to concerns abut Iraqi nationals with ties to Saddam Hussein's regime entering New Zealand.
Mr H's lawyer Rodney Harrison QC said the INZ test unfairly labelled some people as risks to New Zealand's international reputation, even when no such risk existed.
But the Appeal Court was not satisfied the INZ test was invalid in the former spy's case.
"Until the time is reached where it can be said that Mr H's association with the PSB is remote, he remains ineligible for a RCV."
The appeal was dismissed.
Mr H could potentially take his case to the Supreme Court.
Harrison on Thursday would not say whether an appeal was planned or not.
Intelligence, defence and security analyst Dr Paul G Buchanan said Chinese spies operated widely in Australasia.
A primary concern for agents could be uncovering what New Zealand and Australia were telling other members of the Five Eyes intelligence alliance about China.
"It is rare you have defectors of this sort. One happened last year and one happened in the 2000s," Buchanan told the Herald.
Last year's defection was that of Wang "William" Liqiang, who claimed Beijing ordered overseas murders, including in Australia.
"There is a track record of Chinese spying in the Antipodes and there is a small record of Chinese defecting, deciding to leave because they are no longer ideologically committed to the Motherland."
Buchanan, of 36th Parallel Assessments, said some spies pretended to defect, but ended up infiltrating host country agencies.
For this reason, state institutions could be suspicious of anybody who professed to have "turned" or defected.
"If the country bites, the person can be used as a mole inside .. You bring him in and it turns out he never turned."
Only the most experienced spies would attempt such a complex and high-risk operation, he said.
'Very unpleasant situation'
Malcolm Pacific Immigration director David Cooper said living in New Zealand without a residence-class visa would present extreme challenges.
"He can't really put down any roots," he told the Herald after hearing of Mr H's case.
"It's very difficult to get a good job, unless you're extremely high-skilled."
The absence of residency status made many employers uneasy.
Having refugee status didn't change that, because Cooper said a person's refugee status could be rescinded.
"If you fled a country because of your political beliefs, then the civil war goes away, and there's a new leader, New Zealand can say: 'You're not a refugee anymore."
Cooper told the Herald people in Mr H's position couldn't get home loans.
"The system you and I take for granted about borrowing money, buying cars, getting loans, getting credit cards, none of that's available to him."
"Being able to feel part of the country where you've lived for these 20-odd years becomes very difficult."
Cooper said since the Minister of Immigration declined to intervene in Mr H's favour, and the Court of Appeal dismissed his case, the former spy faced big challenges.
"He's left in a very unpleasant situation."