American officials received persistent, stark warnings that Afghanistan’s entrenched culture of official corruption would undermine their efforts to rebuild that country after the West’s military invasion 15 years ago, according to recently declassified diplomatic cables and internal government reports.

The diversion of Afghan resources and Western aid for private gain would, the public and private reports all said, drain vitally needed funds from the country’s reconstruction and alienate its citizenry. That would in turn fuel renewed public support for the West’s enemy—the Taliban, whose social brutality notoriously included draconian punishments for official corruption.

But the U.S. officials in charge of rebuilding the country largely failed to heed these alarms, according to their own assessments. “The ultimate point of failure for our efforts,” said Ryan Crocker, the U.S. ambassador from 2011 to 2012, in a newly released interview with a team of official auditors, is Afghanistan’s corruption.

Washington has paid a steep price for its mistakes—it has invested more than $800 billion in Afghanistan, including about $100 billion in direct payments, and lost more than 2,300 American lives over the past 15 years. (The anniversary of the U.S. invasion was last Friday.) At least a tenth of the country’s population is under the Taliban’s control now, with another 25 percent now being contested, and these numbers have lately been rising, not falling. Nearly 40 percent of the population subsists on less than $1.35 a day.

In fact, Washington has so little to show for its efforts that a group of 10 former U.S. ambassadors and military commanders in Afghanistan declared in a joint statement last month, published by the National Interest magazine on Sept. 14, that stabilizing the country and ending its continued incubation of terrorism will require at least another generation of U.S. effort. Meanwhile, the U.S. costs alone are now running at roughly $1 billion a year for reconstruction, plus another $4 billion a year in direct payments meant to continue to prop up Afghanistan’s persistently weak (and partly imaginary) security forces.

Efforts to uncover all that what went wrong may yet take a while. (The Pentagon Papers analyzing American mistakes in Vietnam were leaked to the public two years after they were completed in 1969 and 21 years after America undertook its disastrous military meddling there.) But the Joint Chiefs of Staff concluded in a 2014 report that military and civilian leaders alike grievously underestimated the gravity and impact of Afghanistan’s corruption. More “Lessons Learned” analyses are now emerging from within the government, and the most recent one points some sharp fingers of blame at the Obama administration—including the State Department while Hillary Clinton was at the helm, and at the CIA, during the entire period of the Bush and Obama administrations.

While trying to stabilize the country, these two organizations undertook two actions that made its problems worse, the latest study says: The CIA partnered over a long period with politically connected warlords that engaged in “rampantly corrupt activities,” largely out of political expediency; meanwhile, U.S. aid organizations helped stoke the country’s historic corruption by pouring in more funds than the country could responsibly absorb, all the while measuring their achievements by how much, rather than how well, money was spent. With short military deployment stints and high turnover in civilian oversight roles, no one in Washington or in Afghanistan took effective responsibility for fixing these problems.

These are the unvarnished critiques in a Lessons Learned report by the Special Inspector General for Afghanistan Reconstruction John Sopko, who has been studying the Afghan effort for four years and whose team interviewed 80 participants and solicited comments from five of the key agencies or departments in charge. “We must recognize the danger,” Sopko said at the Carnegie Endowment’s Washington offices while presenting the report on Sept. 14, “of dealing with characters or networks of unsavory repute, tolerating contracting abuses, accepting shoddy performance, and delivering unsustainable projects.”

But we didn’t, his study shows, and so the desultory results of the U.S. intervention shouldn’t have been a surprise.

Afghanistan was at the bottom of annual corruption rankings by the World Bank at the outset of the U.S-led occupation and, beginning in 2005, near the bottom of an annual corruption list published by Transparency International. A cable sent to Washington by the U.S. embassy, entitled “Confronting Afghanistan’s Corruption Crisis” and newly declassified for Sopko’s study, warned that corruption was “the hallmark of daily life” in Afghanistan and “a major threat to its future.” Conquering it, the cable said, “is fundamental to the success of U.S. policy.” The U.S. Agency for International Development, or AID, which dispensed most of Washington’s nation-building funds, also remarked in an internal strategic plan that year that government institutions at all levels are “tainted by high levels of corruption.”

An internal Pentagon review in 2006 bluntly warned that “enormous popular discontent is building against corrupt and ineffective governance.” That was the year that then-President Hamid Karzai appointed as the head of his chief anticorruption agency a man who had been convicted in the United States on drug charges, Sopko’s report points out. It was also when Karzai notably accepted the appointments of 14 senior police officials “who have links to criminal networks,” according to a secret memo (since declassified) written by a senior adviser to the secretary of Defense.

A study by an Afghan integrity group in 2007 warned that “a strong and interwoven spider web of illicit networks” controlled power at all levels. Two years later, at the outset of the Obama administration, the U.S. embassy in Kabul warned in another cable, also recently declassified, that official corruption—including Afghan officials’ protection for the narcotics trafficking that produced around a half of the country’s gross domestic product—was “as likely as is the insurgency to undo our efforts in Afghanistan.” British diplomats were no less aware of the risks: Their chief foreign aid agency warned in a 2009 report that corruption was then “a major reason for supporting the Taliban.” In 2010, at a meeting with U.S. diplomats, Afghanistan’s national security adviser acknowledged that “corruption … is the system of governance.”

Washington’s response during the first seven years after the invasion, according to Sopko’s report, was to prioritize its counterterrorism and development aims, not fully understanding how dependent these ambitions were on thwarting the impulse and ability of Afghan officials to steal their public resources. The creation in 2008 of a special U.S. military intelligence unit devoted to the topic produced shock in Washington at “how bad this situation was and who was involved in it,” according to Kirk Meyer, the unit’s leader from 2008 to 2011.

Polling data during Karzai’s tenure bore out how poorly illicit funds transfers outside the country were being controlled. A comprehensive annual survey in Afghanistan by the Asia Foundation found that the number of respondents who experienced corruption at the customs office rose from roughly 40 percent in 2006 to 61 percent in 2015—even though U.S. diplomats, in a rosy 2013 cable, hailed Afghan reforms there. The average value of a bribe increased by a fifth from 2010 to 2014, and the number of respondents who said they experienced corruption in the court system rose from 42 percent to 61 percent. The public’s sense of corruption within the national police—a major recipient of Western funds—remained largely unchanged through the occupation. (Half of the respondents experienced it.)

Even after Washington finally grasped the centrality of the corruption problem in 2009 and President Obama publicly called for a crackdown on such behavior, top officials essentially blinked: A comprehensive anticorruption strategy drawn up by the embassy in Kabul and sent to Washington in 2010 never won Secretary Clinton’s (or anyone else’s official) endorsement. When a key advocate—Richard Holbrooke, a top adviser to Clinton and veteran diplomat who had seen the debilitating effects of corruption up close during a previous assignment in the Balkans—died in December 2010, no one else seized the plan and compelled its formal approval.

At another key moment the following year, Washington blinked again. That’s when the International Monetary Fund was negotiating a new $133 million 3-year loan to Kabul, and various foreign donors—including the Obama administration—initially withheld their funds to force Karzai to implement financial reforms and aggressively reclaim nearly a billion dollars that politically connected Afghans had looted from the national bank. (The scale of this theft there was comparable, Sopko’s report notes, to the looting of a trillion dollars from the U.S. economy.)

After some back-and-forth with the donors produced Afghan promises to crack down, Washington and its allies eventually agreed to endorse the loan. Clinton, speaking to a donors conference in Bonn, Germany, that December, said while hailing the resumption of U.S. and allied aid that economic reforms Karzai “has outlined are promising.”

But Sopko’s reading of the moment—a time of high leverage for the West—was different: “The Afghan government suffered no major consequences … for its failure to hold accountable and recover significant assets from the politically connected individuals who had defrauded the Afghan people.” Washington could have demanded measurable progress but did not, he said. At that moment, or at other periods during the long occupation, “State, in consultation with other agencies, might have pursued revocation of visas against corrupt Afghan officials and their families and more robust law enforcement actions against corrupt Afghans with dual U.S. citizenship.”

An international group that included Treasury Department officials concluded in November of that year that those finally indicted by the Afghan government in 2012 for the bank’s looting did not include “officials from accounting firms that created false documents for Kabul Bank, airline employees that smuggled money out of Afghanistan, or shareholders who received funds from loans at zero-interest, apparently without the intention of repayment,” many of them politically-connected. The final decision about who to indict, the group’s report said, “was made at the political level.”

Asked for comment on these events, including Clinton’s failure to approve the embassy’s anticorruption plan, presidential campaign spokesman Jesse Lehrich said that Clinton had helped ensure “that U.S. resources in Afghanistan were responsibly utilized … [and] made it clear each step of the way that the US was not offering a blank check.” Lehrich said that as a result of her efforts, civilian and military contracts, purchasing operations, and vetting procedures were all improved.

But Gen. John Allen, the former commander of the International Security Assistance Force in Afghanistan from 2011 to 2013, memorably told the Senate Foreign Relations Committee in 2014 that “for too long, we focused our attention solely on the Taliban. They are an annoyance compared to the scope and the magnitude of corruption.”

Moreover, diplomats and experts from key donor countries who gathered in April at the U.S. Institute of Peace to discuss what went wrong during the West’s intervention noted that the Afghans early on figured out how to play one country against another whenever they were pressed to institute anticorruption reforms. “Conditionality,” meaning the threatened withholding of grants to compel action, was “undermined by the presence of multiple donors that could provide alternative sources of aid,” the conferees concluded.

There was also an added wrinkle in the West’s policymaking challenges: Throughout this period, key Afghan officials—including those in Karzai’s office—were on the CIA’s payroll, according to multiple media reports and Karzai’s own admissions. “There has been a consistent pattern by the CIA … to focus its energy on targeting [terrorists] and therefore to be at the head of colluding and collaborating with corrupt and abusive officials,” said Sarah Chayes, a former reporter who lived in Kandahar from 2002 to 2009 and became an adviser on Afghanistan to several U.S. military commanders there, plus the Joint Chiefs of Staff. “I experienced it on the ground in Kandahar [where I often saw] CIA station chiefs getting in the way of corruption investigations that were underway.”

She said Washington needs “to take a good look at how the agency performs its functions.” Many Afghans wanted Western powers to do more to stem local corruption, she said. “People detested it … [and] our complicity was driving people into the arms of the Taliban. So, while working with the military, “we built a very detailed campaignwide anticorruption program.” But she said it had to be abandoned “once it became obvious there was not political will in Washington.”

Asked for comment, CIA spokeswoman Heather F. Horniak said that “while we will not comment on any specific claims, our goal is always to improve the capabilities and professionalism of foreign allies. We have taken significant steps to help Afghan partners address areas of concern.”

Recent trends in the country are not good. The Taliban has recently taken control of some additional Afghan districts and made gains in Helmand and four other provinces, many of them past battlegrounds for U.S. forces. Civilian deaths are presently running around 3,000 a year, with nonlethal casualties more than twice that number. The Congressional Research Service, in a Sept. 26 report, said the government’s leadership arrangement is “troubled, by many accounts.”

The National Interest experts’ group, which included all the key U.S. military commanders in the country from 2009 to 2014, rated only two to four of the country’s six army corps commanders as effective—after the expenditure of roughly $40 billion from the U.S. treasury on the Afghan Army so far. (Another $28 billion went to other security forces, including the perennially ineffective police.) Only a little more than a third of the population there is optimistic about the future, while two-thirds say the security situation is poor.

Officials in the National Interest group, which was pulled together by Michael O’Hanlon at the Brookings Institution, are nonetheless having a hard time giving up. They urged a “quiet and more patient approach” and warned that “predatory corruption in particular needs to be targeted.” They said Washington needs to apply serious pressure on neighboring Pakistan, where key Taliban leaders and soldiers have long had a refuge—an idea that key Obama administration officials have repeatedly opposed. They also wistfully noted that in 2013, the U.S. military “developed an option” for dispatching 5,000 more foreign troops to the country and blamed the plan’s rejection in both capitals for some of the “deterioration in the Afghan security environment” going on now.

Sopko’s report notes, however, that even though Karzai has left office and his replacement, Ashraf Ghani, in 2014vowed a genuine crackdown on corruption, its achievement is now “a generational goal”—an estimate that mirrors the length of time that former U.S. diplomats and generals say is needed for Western success there. He notes that no significant recovery of National Bank assets has occurred under Ghani, and the country’s judiciary remains under substantial political pressure. Transparency International, in a September report, similarly said Afghanistan still lacks a “comprehensive legal framework for preventing, detecting, and prosecuting corruption,” which it noted remains rife in public institutions. The country’s anticorruption agencies, the group said, have had “little evidence of success in fulfilling their mandates.”

Last week, Western officials at a donors conference in Brussels agreed to pledge another $15 billion in aid to the country over the next four years, on top of the more than $125 billion in aid that it’s received from all donors since the September 2001 attacks on the United States were hatched on Afghan soil. A joint communiqué by the donors noted that corruption “remains a major obstacle to development and stability” but welcomed “the steps taken so far.”

“They find themselves stuck, unable to extricate themselves, because of guilt, pressure, and the fear of what a collapsed Afghanistan would mean for their own security,” said Heather Barr, a senior researcher at Human Rights Watch, who decried the donors’ failure to hold Afghan officials accountable for their many promises of reform.

Whether U.S. lawmakers will have appetite for spending a major share of this won’t be clear until after the November elections.

This story was published by the Center for Public Integrity, a nonprofit, nonpartisan investigative news organization in Washington, D.C.