BENGHAZI/TRIPOLI International treaties are clear. The Libyan government had a duty to protect the U.S. consulate in Benghazi and it failed utterly when the compound was overrun and four Americans, including the ambassador, were killed.
Libya's problem though, runs far deeper than just diplomatic protection: interim governments have barely governed, and the latest prime minister - named hours after the U.S. mission was torched - has no effective army or police force at his command.
A year after the overthrow of Muammar Gaddafi, the legacy of four decades of one-man rule - when many formal institutions of statehood withered - and of the popular uprising that killed him, is that an anarchic swarm of militias provides both what passes for official security and poses the main threat to it.
For a year, Libyan leaders, backed by the Western allies, have been gambling they can forge a political consensus which will seize power back from the heavily-armed revolutionaries in the streets before rivalries spin irretrievably out of control.
That time may be running out seems most evident in Benghazi. The consulate attack was only the bloodiest and most recent violence in Libya's second city; the seat of last year's February 17 revolution, it has a history of militant Islam, previously directed against Gaddafi, and deep grievances over western Libya's control of oil pumped out of the east.
As one member of the General National Congress, the interim parliament, put it - so bluntly that he did not wish to say it publicly - the state can probably do no more than contain the mayhem for now, still hoping it can build up its own strength:
"As the saying goes, 'If you can't solve the problem, manage it'," he said. "We need to manage it."
Prime Minister Mustafa Abu Shagour, elected by the Congress on Wednesday, said establishing the power of the state was still a priority: "We are going to work very vigorously to build our police force, our army," he told Reuters in an interview.
"We have to deal with these militias because some of them have nothing to do with the revolution, and are made up by a bunch of criminals. We have to dismantle them."
However, the failure of successive efforts since last autumn to persuade the ex-rebel militias to disband and disarm, or to transfer loyalties clearly to the interim leadership, itself a fractious body, has left many skeptical of future prospects.
"There is no shortage of weaponry in Libya, but there is an enormous deficit of state capacity," said Geoff Porter, an independent U.S. analyst of North African affairs.
"The gamble for the Libyans was that they would get their political house in order before the security environment became too difficult to contain. The government has lost that bet."
In Benghazi, the local protection for the U.S. consulate in Libya's oil capital, fulfilling Libya's obligations under the Vienna Conventions on diplomatic missions, was provided by an outfit known as the February 17 Brigade, a collection of young men with rifles proud of their exploits last year in chasing Gaddafi's army west across the desert, aided by NATO bombers.
A second layer of official public order in Benghazi comes courtesy of Libya's Shield, another paramilitary unit born in the revolution and drafted in, ad hoc, by the new leadership.
But as events on Tuesday evening showed, the pro-government forces have far from secured the monopoly on violence which is a key definition of statehood. Others also helped themselves to the weapons left by Gaddafi's disintegrating army and seem prepared to use them against Western and Libyan targets.
When a furious demonstration, emulating a similar embassy protest in neighboring Egypt over an American-made film insulting to the Prophet Mohammad, turned into an assault with machineguns and grenades on the Benghazi consulate, the couple of dozen Libyan guards offered little resistance, Libyan officials in the city said. Outgunned, some guards may also have decided on their own that wrecking the embassy was justified - several Libyan commanders said Washington deserved to suffer.
Among those identified by local people in the crowd were members of a hardline Islamist group, Ansar al-Sharia. Part of a wider Salafist movement that favors a fundamentalist religious state and appears to have some past contact with and sympathies for al Qaeda, Ansar al-Sharia has been accused of involvement in several violent incidents in Benghazi in recent months.
Since Gaddafi fell, there have been fears that some of his weaponry, and enemies, will end up in a wider anti-Western militant movement across north Africa. But such militants are not alone in providing a platform for popular anger in the east against Tripoli's politicians and their allies abroad.
Life and business in Benghazi has been disrupted by sporadic violence and demonstrations, often accompanied by demands for greater autonomy or investment in the east, separated from Tripoli by historic tradition and 1,000 km of desert highway.
"The people who demonstrated in front of the embassy were seriously depressed about their daily lives in Benghazi and not just angry over the film," said Nasser Ahdash, a political analyst living in the city. "The film added to it. But people feel depressed. People need jobs, hope and a feeling like they're not forgotten by the central government.
"If you start with one hardliner, you will get three in Benghazi when they have this depression from seeing that all the economy, the embassies, are in Tripoli, companies are in Tripoli, all the contracts are in Tripoli," he added, arguing that the new government should improve an economic balance which Gaddafi had tilted heavily away from the east of the country.
Saleh Gaouda, a member for Benghazi of the two-month-old Libyan Congress, also blamed the interim authorities for a failure to impose order in the east and to delegate power to local leaders: "The security breaches we are seeing in Benghazi are a direct failure of the government," he said.
"There is no one on the ground in Benghazi who can make the right decision at the right time ... There is no one who can take control of the situation and actually take responsibility."
The immediate impact of the violence is a clear heightening of caution on the part of foreign diplomats and business people, who had already been taking great care in Benghazi following attacks that included a grenade ambush which blasted the convoy of the British ambassador in June. Libyan officials assured diplomats that the security brigades would protect them.
But the killings at the consulate have set back Benghazi's hopes of investment and international favor: "Certainly you will have people questioning whether to go there," one diplomat said. "The overall feeling is one of caution right now."
Tarek Alwan, whose consultancy SOC Libya advises foreign firms on doing business in the country, said: "The impact is great and will lead to more restrictions on travel, higher travel insurance, on development.
"Libya in general and Benghazi specifically will suffer -because we should never bite the hand that helped us."
Our top photos from the past week.