CIA officers in Afghanistan were so eager to meet the spy they believed would help them crack al-Qaida's leadership, they planned a birthday celebration complete with cake for his visit in December, according to officials.

But before they could begin to question their source, he detonated a powerful bomb, killing himself and seven CIA employees, in one of the deadliest attacks in the agency's history. Humam Khalil Abu-Mulal al-Balawi, a 36-year-old doctor who had been recruited by Jordanian intelligence officials, was a double agent.

The account, confirmed by current and former officials briefed on the case, is the latest evidence that CIA officials at the Afghan base had trusted Balawi and wanted to build rapport with him. The bombing not only weakened US intelligence operations, it started a contentious debate within the intelligence community about whether the CIA was too lax with its security.

The CIA director, Leon Panetta, has scoffed at suggestions that security lapses were to blame for the attack. But it remains unclear why there was such a large contingent around Balawi when the bomb erupted.

It was not unusual for CIA officers to offer gestures such as a birthday cake or a small gift for spies they oversee, former intelligence officials said. Such gestures lightened the mood, relieved pressure and convinced an informant of his importance.

"Normally though, that's something you do after you've established a relationship," said the former CIA and National Security Council official Bruce Riedel, who was not aware of the CIA's birthday plans for Balawi. "It's not something you do on the first date."

Such celebrations are typically discreet affairs, involving one or two officers. In this case, several officials were nearby when Balawi arrived at the CIA's Afghan base. In addition to the seven that were killed, six others were wounded.

In an interview made public after his death, Balawi said he knew in advance he was meeting "an entire CIA team." He said he had been planning to kidnap or kill his Jordanian intelligence contact, but the chance to kill CIA officers was too tempting.

"We planned for something, but got a bigger gift. A gift from Allah, who brought us, through his accompaniment, a valuable prey: Americans from the CIA," Balawi said. "That's when I became certain that the best way to teach Jordanian intelligence and the CIA a lesson is with the martyrdom belt."

Balawi's contacts with Jordanian intelligence, one of the CIA's most trusted partners in the Middle East, gave him credibility. He was thought to have critical intelligence about al-Qaida's second-in-command, Ayman al-Zawahri, and was not searched before meeting the CIA agents.

Shortly after the attack, Panetta rejected criticism that poor spycraft was to blame. "That's like saying marines who die in a firefight brought it upon themselves, because they have poor war-fighting skills," Panetta wrote in a Washington Post article.

Robert Baer, a former Middle East CIA operative, heaped criticism on the agency in this month's GQ magazine. Baer said the senior officer at the base was "in over her head" and should never have let so many people meet the source. "Informants should always be met one-on-one," Baer wrote.

A CIA spokesman, George Little, said of former employees turned critics: "They don't have all the facts of this case, yet they criticise those who were on the frontlines on 30 December, including some whose lives were taken. That's disgraceful.

"Informed criticism can be very valuable. Some of the junk I've seen in the press, clearly isn't."