On Monday, as five Middle Eastern countries abruptly severed ties with Qatar, which they accused of condoning fund-raising for terrorist networks, among other grievances, U.S. ambassador Dana Shell Smith took to Twitter to reaffirm America’s relationship with the tiny Arabian petrostate. “Seems a good time to [retweet] this one,” she said, linking to two 2016 posts praising Qatar’s commitment to help cut off financing to extremist groups. The U.S.-Qatar relationship is, after all, of vital importance to American national security interests: Qatar, a longtime U.S. ally, is currently home to one of the largest U.S. military bases in the world, and serves as the command center for the region’s aerial campaign against ISIS.

It was not clear whether President Donald Trump was aware of this fact when he also began tweeting about the Qatar diplomatic crisis himself, directly undercutting the U.S. Embassy in Qatar and leaving Bob Corker, the Republican chairman of the Senate Foreign Relations Committee, shaking his head in disbelief.

Such are the trials of America’s career diplomats and other U.S. representatives in the international community, who have struggled for months to maintain niceties with foreign countries and interpret the president’s inconsistent policy positions without appearing to contradict him directly. Those relationships have been put to the test this week, after Trump withdrew the U.S. from the Paris climate accord, picked a fight with the mayor of London for his response to a terrorist attack, and unexpectedly took Saudi Arabia’s side in a complex, highly combustible diplomatic crisis in the Middle East.

U.N. Ambassador Nikki Haley, who has occasionally found herself advocating a foreign-policy agenda at odds with Trump’s views, did her best to spin the president’s rejection of the Paris agreement, trying to reassure allies that Trump “believes the climate is changing” and that “just because we got out of a club doesn’t mean we don't care about it.” Other representatives of U.S. policy abroad struggled to defend the president’s decision. On Monday, David H. Rank, acting ambassador to China, resigned rather than work with the Trump administration to help withdraw from the landmark climate deal. “It's heart-wrenching that we're losing career officers of his talent,” a former colleague opined to CNN. “But some are increasingly grappling with whether they must take principled decisions as they balance their sense of duty with their conscience.”

Days later, another career diplomat found himself in a similarly precarious position. While Trump lashed out at London mayor Sadiq Khan, calling him “pathetic” for urging Londoners to not be alarmed by increased police presence in the wake of a terrorist attack—a remark that the president took deliberately out of context—acting U.S. Ambassador Lewis Lukens commended Khan for his leadership.

It’s hardly the first time that the U.S. diplomatic community has rebelled against Trump. Earlier this year, about 1,000 career diplomats signed a cable protesting the president’s executive action banning travel from several majority-Muslim nations, and a number of top level diplomats have resigned since Trump took office. As Dana Smith Shell, the ambassador to Qatar, wrote on Twitter last month in the wake of Trump’s dismissal of F.B.I. director James Comey, it is “increasingly difficult to wake up overseas to news from home, knowing I will spend today explaining our democracy and institutions.”