When it came out that CIA Director David Petraeus had an affair with his hagiographer, I got punked. "It seems so obvious in retrospect. How could you @attackerman?" tweeted @bitteranagram, complete with a link to a florid piece I wrote for this blog when Petraeus retired from the Army last year. ("The gold standard for wartime command" is one of the harsher judgments in the piece.) I was so blind to Petraeus, and my role in the mythmaking that surrounded his career, that I initially missed @bitteranagram's joke.

But it's a good burn. Like many in the press, nearly every national politician, and lots of members of Petraeus' brain trust over the years, I played a role in the creation of the legend around David Petraeus. Yes, Paula Broadwell wrote the ultimate Petraeus hagiography, the now-unfortunately titled All In. But she was hardly alone (except maybe for the sleeping-with-Petraeus part). The biggest irony surrounding Petraeus' unexpected downfall is that he became a casualty of the very publicity machine he cultivated to portray him as superhuman. I have some insight into how that machine worked.

The first time I met Petraeus, he was in what I thought of as a backwater: the Combined Armed Center at Fort Leavenworth. It's one of the Army's in-house academic institutions, and it's in Kansas, far from the battlefields of Iraq and Afghanistan. In 2005, Petraeus ran the place, and accepted an interview request about his tenure training the Iraqi military, which didn't go well. Petraeus didn't speak for the record in that interview, but over the course of an hour, he impressed me greatly with his intelligence and his willingness to entertain a lot of questions that boiled down to isn't Iraq an irredeemable shitshow. Back then, most generals would dismiss that line of inquiry out of hand, and that would be the end of the interview.

One of Petraeus' aides underscored a line that several other members of the Petraeus brain trust would reiterate for years: "He's an academic at heart," as Pete Mansoor, a retired Army colonel who served as Petraeus' executive officer during the Iraq surge, puts it. There was a purpose to that line: It implied Petraeus wasn't particularly ambitious, suggesting he was content at Fort Leavenworth and wasn't angling for a bigger job. I bought into it, especially after I found Petraeus to be the rare general who didn't mind responding to the occasional follow-up request.

So when Petraeus got command of the Iraq war in 2007, I blogged that it was all a tragic shame that President Bush would use Petraeus, "the wisest general in the U.S. Army," as a "human shield" for the irredeemability of the war. And whatever anyone thought about the war, they should "believe the hype" about Petraeus.

I wasn't alone in this. Petraeus recognized that the spirited back-and-forth that journalists like could be a powerful weapon in his arsenal. "His ability to talk to a reporter for 45 minutes, to flow on the record, to background or off-the-record and back, and to say meaningful things and not get outside the lane too much – it was the best I've ever seen," Mansoor reflects. It paid dividends. On the strength of a single tour running the 101st Airborne in Mosul, Newsweek put the relatively unknown general on its cover in 2004 under the headline "Can This Man Save Iraq?" (It's the first of three cover stories the magazine wrote about him.) Petraeus' embrace of counterinsurgency, with its self-congratulatory stylings as an enlightened form of warfare that de-emphasized killing, earned him plaudits as an "intellectual," unlike those "old-fashioned, gung-ho, blood-and-guts sort of commander[s]," as Time's Joe Klein wrote in 2007. This media narrative took hold despite the bloody, close-encounter street fights that characterized Baghdad during the surge.

That March, I was embedded with a unit in Mosul when I learned Petraeus was making a surprise visit to its base. The only time he had for an interview was during a dawn workout session with company commanders, I was told, but if I was willing to exercise with everyone else, sure, I could ask whatever I wanted. The next morning, Petraeus came out for his 5-mile run and playfully asked: "What the hell is Spencer Ackerman doing in Mosul?" It's embarrassing to remember that that felt pretty good, but it did. And sure enough, while I sweated my way through a painful run – I had just quit smoking and was in terrible shape – he calmly parried my wheezed questions. I only later realized I didn't gain any useful or insightful answers, just a crazy workout story that I strained to transform into a metaphor for the war. ("'This tires you out that day, but it gives you stamina over the long run,' he noted. 'And this is about stamina. It's absolutely grueling.'" Ugh.)

There was another element at work: Counterinsurgency seemed to be working to reduce the tensions of Iraq's civil war, as violence came down dramatically that summer. So when I got the occasional push-back e-mail from Petraeus' staff that my reporting was too negative or too ideological, I feared they had a point. And I got exclusive documents from them that – surprise, surprise – not only vindicated Petraeus but made the general seem driven by data and not ideology.

To be clear, none of this was the old quid-pro-quo of access for positive coverage. It worked more subtly than that: The more I interacted with his staff, the more persuasive their points seemed. Nor did I write anything I didn't believe or couldn't back up – but in retrospect, I was insufficiently critical. And his staff never cut off access when they disagreed with something I'd written. I didn't realize I was thinking in their terminology, even when I wrote pieces criticizing Petraeus. A 2008 series I wrote on counterinsurgency was filled with florid descriptions like "Petraeus is no stranger to either difficulty or realism."

Politicians and the press treated Petraeus as a conquering hero. Tom Ricks, then the Washington Post's senior military correspondent, wrote that Petraeus' "determination" was the "cornerstone of his personality," and portrayed the success of surge as that determination beating back the insurgents and the nay-sayers. "The soldiers and marines told us they feel that they now have a superb commander in Gen. David Petraeus," wrote Brookings Institutions analysts Michael O'Hanlon and Kenneth Pollack after a return from Iraq. "They are confident in his strategy, they see real results, and they feel now they have the numbers needed to make a real difference." John McCain hugged Petraeus so closely during his 2008 campaign that Post columnist Jackson Diehl dubbed the general "McCain's Running Mate."

But by the time President Obama tapped Petraeus to run the Afghanistan war in 2010, something had changed. Petraeus' mouth was saying "counterinsurgency," with its focus on protecting civilians from violence, but in practice, he was far more reliant on air strikes and commando raids. He was even touting enemy body counts as measurements of success, which was completely antithetical to counterinsurgency doctrine, and his staff's insistence that nothing had changed sounded hollow.

But then there was Broadwell to spin the shift away. On Ricks' blog, she described the complete flattening of a southern Afghan village called Tarok Kolache, confidently asserting that not only was no one killed under 25 tons of U.S. air and artillery strikes, but that the locals appreciated it. Danger Room's follow-up reporting found that the strikes were even more intense: Two other villages that the Taliban had riddled with bombs, were destroyed as well. But Broadwell, who was traveling around Afghanistan and working on a biography of Petraeus, didn't grapple with the implications of Petraeus shifting away from counterinsurgency, let alone the fortunes of the Afghanistan war.

Broadwell didn't have a journalistic background, and it seemed a bit odd that she was visibly welcomed into Petraeus' inner circle. At a Senate hearing Petraeus testified at last year, for instance, I met Broadwell for the first time in person, and noted that she sat with Petraeus' retinue instead of with the press corps. Some of Petraeus' old crew found it similarly strange. "I never told General Petraeus this, but I thought it was fairly strange that he would give so much access to someone who had never written a book before," Mansoor recalls.

At the same time, consider this passage from All In:

Far beyond his influence on the institutions and commands in Iraq and Afghanistan, Petraeus also left an indelible mark on the next generation of military leaders as a role model of soldier-scholar statesman. ... Creative thinking and the ability to wrestle with intellectual challenges are hugely important in counterinsurgency but also any campaign's design and execution, he felt; and equipping oneself with new analytical tools, civilian and academic experiences, and various networks had been invaluable for him and – he hoped – for those whom he'd mentored and led.

The uncomfortable truth is that a lot of us who've covered Petraeus over the years could have written that. It's embarrassingly close to my piece on Petraeus' legacy that @bitteranagram tweeted. And that's not something you should fault Petraeus for. It's something you should fault reporters like me for. Another irony that Petraeus' downfall reveals is that some of us who egotistically thought our coverage of Petraeus and counterinsurgency was so sophisticated were perpetuating myths without fully realizing it.

None of this is to say that Petraeus was actually a crappy officer whom the press turned into a genius. That would be just as dumb and ultimately unfair as lionizing Petraeus, whose affair had nothing to do with his military leadership or achievements. "David Petraeus will be remembered as the finest officer of his generation, and as the commander who turned the Iraq War around," e-mails military scholar Mark Moyar. But it is to say that a lot of the journalism around Petraeus gave him a pass, and I wrote too much of it. Writing critically about a public figure you come to admire is a journalistic challenge.

Conversations with people close to Petraeus since his resignation from the CIA have been practically funereal. People have expressed shock, and gotten occasionally emotional. It turns out, Mansoor sighed, "David Petraeus is human after all." I wonder where anyone could have gotten the idea he wasn't.