On Wednesday, Julia Pierson, the first woman to ever lead the Secret Service in its nearly 150-year history, resigned her post amid heavy criticism over an intruder who was able to get as far as the East Room of the White House. 

Reasonable people can disagree about whether, ultimately, she deserved to lose her job or whether anyone in charge during such an incident would have to resign. But it’s probably not pure chance that Pierson, who held that position for just a year-and-a-half, was a woman. Time and again, women are put in charge only when there’s a mess, and if they can’t engineer a quick cleanup, they’re shoved out the door. The academics Michelle Ryan and Alex Haslam even coined a term for this phenomenon: They call it getting pushed over the glass cliff.

Pierson was, in fact, explicitly brought in to clean up a mess. When President Obama nominated her last year, it was on the heels of news that Secret Service employees hired prostitutes in Cartagena, Colombia ahead of the president’s arrival. Pierson was meant to be a breath of fresh feminine air to clear out the macho cobwebs still dogging the agency. That scandal, it must be noted, was overseen by Mark Sullivan, who was in the job for seven years. He even held onto it after revelations that the Salahi couple made it past multiple layers of security to crash a state dinner in 2009.

That wasn’t the only thing hobbling the agency before Pierson’s arrival, though. It has been perpetually underfunded and understaffed. In his book on the secret service, Ronald Kessler describes how agents are stretched so thin that the agency grapples with high turnover. And he points the finger at Sullivan, “whom he argued made it seem as if the Service could function well with what it has been given,” writes Kate Dries. But Congress certainly shares the blame. This is the first year since 2010 that the agency isn’t operating with a budget below what it requested. And since that year, personnel levels have seen a severe decline. In her testimony before Congress, Pierson said that the agency’s current 550 employees is below “optimal level.” 

The understaffing, for which Pierson was not responsible, could have played a significant role in the breach that led to her losing her position. Former secret service agents told the Washington Post that the incident may have been related to the severe staffing shortage in the division responsible for securing the White House. It’s gotten so bad that the agency has had to fly agents in from around the country, who are less familiar with the grounds and response plans.

So Pierson took the reins of a very troubled agency when she made history as its first head. And in that she is not alone. Multiple studies have found that women are most likely to be given a chance at top roles in the corporate world when things are already bad. One found that before a woman took over as CEO of a Fortune 500 company between 1996 and 2010, its previous performance was significantly negative. Another found that FTSE 100 companies who appointed women to their boards were more likely to have had five months of consistently bad performance compared to those who picked men. Another found that companies were most likely to choose women for their boards after a loss that signaled the company was underperforming. Even in a lab, students and business leaders are more likely to pick a woman to lead a hypothetical organization when performance is on the decline.

As with Pierson, women are often put in these positions because rough patches make people think they need to shake things up and try something new – like putting a woman in charge. When it’s smooth sailing, on the other hand, men get to maintain control of the steering wheel. Women are also thought to have qualities associated with cleaning up messes.

And that would be fine, except taking over an organization that’s in trouble is a lot harder than taking over one that’s flourishing. The chances of failure are inevitably higher. Just ask Mary Barra, who made history when she became the first woman to run a global car company. But just two weeks into her tenure as CEO of General Motors, the company issued a massive recall on faulty ignition switches linked to 13 deaths, something the company knew about as early as 2001 but she didn’t know about until she had spent a few weeks on the job. Carly Fiorina took over Hewlett-Packard as the tech bubble was bursting. Anne M. Mulcahy got her shot at being the first female CEO at Xerox when it was $17 billion in debt and being investigated by the Securities and Exchange Commission. Lynn Laverty Elsenhans was named the first female CEO of Sunoco after shares had fallen 52 percent. Erin Callan got a chance at being CFO of Lehman Brothers in December 2007 – just ahead of the financial meltdown – and resigned just months before it ended up declaring bankruptcy. Zoe Cruz became the most powerful woman in finance and was about to be the next CEO of Morgan Stanley just before the mortgage market tanked.

There are examples outside the corporate world as well. Think of Katie Couric, who was given an anchor position at CBS Evening News when the show’s ratings were already in third place, or Diane Sawyer, who got the same job at ABC World News after evening news programs had already bled more than half of their audience. The New York Times appointed its first-ever female executive editor just as newspaper ad sales began to fall off a cliff. You don’t have to disagree with every one of these decisions to discern a pattern.

Some women are able to beat the odds and step away from the glass cliff. Mulcahy is credited with leading Xerox’s turnaround. Shares climbed back up after Elsenhans took the helm. Barra is still struggling, but has taken a more open and conciliatory approach that might just see the company through the crisis.

But many women on the glass cliff simply fall off. Female CEOs, for example, are more likely to end up forced out than men. And when they leave, they are likely to get replaced by a man. As for the Secret Service, it turns out that Joseph Clancy will be Pierson’s temporary replacement, even though he was in charge of the presidential detail the night the Salahis slipped past checkpoints. Make of that what you will.