Months before a firestorm erupted over a federal government tweet criticizing a Saudi civil rights crackdown, Canadian diplomats had been trying to delicately address the issue behind closed doors.

Those efforts came crashing down after Global Affairs Canada publicly called out Saudi Arabia on Twitter for arresting activists and demanded their release.

A trove of over a thousand pages of emails and memos from officials in Ottawa and the Canadian Embassy in Riyadh, obtained by CBC News through an Access to Information request, tells the story of how events unfolded.

Earlier tweets elicited no reaction

While it was the tweets in early August that triggered an international diplomatic crisis, tweets posted May 23 similar in tone and message seemingly went unnoticed. That same day, Global Affairs Minister Chrystia Freeland made a statement during question period condemning the arrests of activists.

Canada is extremely concerned by the arrests of civil society and women’s rights activists in <a href="https://twitter.com/hashtag/SaudiArabia?src=hash&ref_src=twsrc%5Etfw">#SaudiArabia</a>. We call on Saudi authorities to release peaceful activists. <a href="https://t.co/jz8Q7rvjes">pic.twitter.com/jz8Q7rvjes</a> —@cafreeland

Redacted emails from an unknown sender had two days earlier recommended against issuing any public statements or tweets and instead proposed alternative approaches. The concern was that a show of support for the civil rights activists would feed rumours that they were working on behalf of foreign embassies.

During the summer, the Canadian Embassy requested meetings with Saudi officials to follow up on "the arrest and detention of several civil society activists." Invited to the meeting were diplomats from Australia, Switzerland and Norway, embassy documents show.

New round of arrests prompted new tweets

On June 27, a confidential summary of new Saudi crackdowns was circulated among Canadian officials. The memo stated that, just days after the Saudi government lifted its long-standing prohibition on female drivers, "this latest move suggests that the government's campaign to crack down on civil society and make clear its intolerance for political activism is far from over."

On July 31, news came that two more civil rights activists had been arrested — one of which was Samar Badawi, the sister of jailed activist Raif Badawi, whose wife fled to Canada. The next day, bureaucrats began planning out the wording for tweets.

"I spoke to my management and we agree that a tweet is warranted," wrote an employee whose name was redacted. After a series of discussions over which hashtag would yield the most reach on social media, an email was forwarded to the minister's office recommending the tweets be approved in order to "express concern regarding these arrests."

Calm before the storm

On August 2, a first tweet from the minister's account went live, and reaction was being closely monitored. Early on, emails suggest staff were disappointed with how little traction the message received online.

The next day, two more tweets were sent out: one from the departmental account, and a version translated into Arabic from the embassy's account. Staff pointed out that the minister's earlier tweet included explicit mention of Samar Badawi and proposed that the new ones do so, as well.

تشعر كندا بقلق بالغ إزاء الاعتقالات الإضافية لنشطاء المجتمع المدني ونشطاء حقوق المرأة في <a href="https://twitter.com/hashtag/%D8%A7%D9%84%D8%B3%D8%B9%D9%88%D8%AF%D9%8A%D8%A9?src=hash&ref_src=twsrc%5Etfw">#السعودية</a> ، بما في ذلك <a href="https://twitter.com/hashtag/%D8%B3%D9%85%D8%B1_%D8%A8%D8%AF%D9%88%D9%8A?src=hash&ref_src=twsrc%5Etfw">#سمر_بدوي</a> . نحث السلطات السعودية على الإفراج عنهم فوراً وعن جميع النشطاء السلميين الآخرين في مجال <a href="https://twitter.com/hashtag/%D8%AD%D9%82%D9%88%D9%82_%D8%A7%D9%84%D8%A7%D9%86%D8%B3%D8%A7%D9%86?src=hash&ref_src=twsrc%5Etfw">#حقوق_الانسان</a>. —@CanEmbSA

The reaction from Saudi Arabia was swift. Just hours after the second round of tweets was published, the Saudi government retaliated, announcing it was expelling Canada's ambassador, and it would sell off Canadian assets, cease flights to Canada, stop buying Canadian wheat and barley and suspend student exchange programs.

Damage control, media frenzy

On Aug. 5, staff became aware of reports indicating that the Saudi government intended to expel Canadian diplomats from their country. The documents show that staff were learning many of the developments from media reports and from inquiries being made by reporters to their department. By now, the Privy Council Office and the Prime Minister's Office were fully engaged in the discussions over how to manage the situation.

Emails from staff were circulating expressing shock and sadness for embassy and consular staff. Someone working within the overseas team sent a long email thanking their colleagues.

"I couldn't have asked for a better team to close out my career with. Despite the way it ended, I think we were able to do a lot of good things together," read the message.

"The saddest part in all of this is that [redacted] will not have the chance to say a proper goodbye."

As officials were trying to come up with a communication strategy to put out fires, they were getting swamped by questions from national and international media. The foreign affairs department carefully monitored media publications and online reaction.

In one email from the minister's office, a request was made to try and find any evidence of support from "like-minded" groups or countries.

Ninety minutes later, a staffer responded that that there was "very little" to be found in terms of online backing from other countries.

At the same time, the department was receiving emails from Muslim community leaders inquiring about travel advice for Canadians intending to travel to Saudi Arabia for Hajj, an annual Islamic pilgrimage to Mecca.

Then came calls from industry players like Bombardier. The company's government affairs contact was trying to set up a meeting to discuss the impact of the situation. Another email discussed the future of the billion-dollar light-armoured vehicle contract Canada held with the Saudi government.

Even a representative for the government of Prince Edward Island reached out to Global Affairs for assurances the issue would be dealt with, as a local company had just struck a deal to provide lobster to a Saudi restaurant group and shipments were to begin two weeks later.

Staff were also preparing lists of stakeholders and attempting to quantify the impact the rift would have on Canadian post-secondary institutions and medical schools, which host about 10,000 students a year.

"The point is, these are not starving students ... they are generally from more affluent families — and come with families who spend money. Something to bear in mind, if the threat to withdraw KSA students is real — and materializes," a departmental employee wrote.

As the spat began to draw international attention, there was an online backlash from Saudi social media accounts telling Canada to mind its own business. In one notable incident, a Saudi youth group tweeted an image appearing to show an Air Canada plane heading toward the CN Tower in a way that is reminiscent of the 9/11 attacks in the U.S.

Staffers were tasked with keeping tabs on these types of hostile reactions, as well.

Once the dust had begun to settle, records show Freeland held talks with politicians from other countries, including the U.K., Germany and Sweden. On August 7, her office made a formal request to set up a call with U.S. Secretary of State Mike Pompeo, but it is not clear based on the records if this meeting occurred.

In late September, Freeland expressed a desire to mend fences with Saudi officials by discussing their differences on the sidelines of the United Nations General Assembly in New York.

However, Saudi Arabia's Foreign Minister Adel al-Jubeir said at the council meeting that if Canada wishes to move on, it must first apologize for demanding the release of Saudi women's rights activists and stop treating the kingdom as "a banana republic."

Weeks later, the controversy surrounding the murder of Saudi dissident and writer Jamal Khashoggi captured the international community's attention, leaving the situation over the initial Twitter rift in limbo.