THROUGH a slit in a stone bunker, soldiers from the Nagorno-Karabakh republic can see their Azeri foes just 150 metres away. In these mountains between two former Soviet republics, there are echoes of Ukraine. This summer was “more tense than before”, says an officer at the front of this long-simmering conflict. Nagorno-Karabakh is run by ethnic Armenians but is legally part of Azerbaijan. Secession in 1988 led to a war that killed some 30,000 people. A shaky ceasefire ensued in 1994, with Azerbaijan losing 14% of its territory. Exchanges of fire along the front have long been common, but the clashes this year have been the worst since 1994. Commando raids became frequent, adding to the usual sniper fire. And the action has spread to the Armenia-Azerbaijan border, where civilians have become targets. Each side blames the other. Heavy Azeri losses at the start of August provoked bellicose rhetoric from the president, Ilham Aliyev. “The war is not over,” he declared. “Only the first stage of it is.”

Like a headmaster disciplining unruly students, Russia’s Vladimir Putin summoned Mr Aliyev and his Armenian counterpart, Serzh Sargsyan, for talks in Sochi in early August. Tensions cooled, but the parties are no closer to a settlement. On September 2nd Mr Sargsyan congratulated Nagorno-Karabakh on the 23rd anniversary of its independence by calling the republic’s choice “an irreversible reality now”.

But it is Ukraine that casts an ominous shadow, “reinforcing the zero-sum mentality”, says Thomas de Waal of the Carnegie Endowment in Washington. Trust in international mediators and security guarantees has frayed. Officials in Baku, Azerbaijan’s capital, detect double standards over sovereignty and self-determination. They wonder why the West punishes Russia for annexing Crimea, but not Armenia for similar behaviour in Karabakh. Many ask why the West approves of Ukraine using force to restore territorial integrity, but insists on Azerbaijan’s peaceful patience. As a result, Azerbaijan is “losing trust in the ability of the West to maintain a deterrent or a peaceful ceasefire,” says Matthew Bryza, a former American ambassador to Azerbaijan.

Azerbaijan feels vulnerable. Russia provides a security guarantee for Armenia, where it has a military base and 4,000-5,000 troops. Azeri officials see the Western response to Ukraine as tepid, part of a worrying pattern of disengagement.

This perceived indifference has favoured a crackdown in Azerbaijan. Several anti-government activists have been arrested this year, some charged with treason. The bank accounts of NGOs have been frozen. International pressure was once a “brake mechanism” on Azerbaijan, says Sabine Freizer, at the Atlantic Council, but it may no longer work.

Azerbaijan’s new assertiveness has come with the weakening of two restraints: its military disadvantage and the prospect of a diplomatic settlement. Riding a wave of petrodollars, Azerbaijan’s annual defence budget rose from $177m in 2003 to $3.4 billion in 2013. Purchases include sophisticated weapons from Israel, Turkey and Russia. The country has a new and inexperienced defence minister.

Armenia has built up its forces and defences too. Even so, Mr Putin used its sense of vulnerability to persuade it to apply for membership of the Eurasian union, his pet project. The risk of open war remains low, but the militarisation of the borders and the willingness to use violence creates “the risk of a war by accident”, says Richard Giragosian, director of the Yerevan-based Regional Studies Centre. The consequences would be disastrous, drawing in Russia, Turkey and Iran, and potentially feeding unrest in the Middle East.

The framework of a peace plan exists, hinging on the return of seven de jure Azerbaijani districts around Nagorno-Karabakh in exchange for the republic’s right to decide its own status. But in Stepanakert, the capital, leaders insist that a settlement is impossible without a seat at the table for Karabakh, which is represented by Armenia. Even then, a compromise that includes returning territory to Azerbaijan is “unrealistic”, says Nagorno-Karabakh’s prime minister, Arayik Harutyunyan.

While Stepanakert seems peaceful, the people steel themselves for what many see as an inevitable return to violence. Zhanna Galstyan, head of the Nagorno-Karabakh parliament’s defence committee, recalls an adage of Chekhov: “If there is a gun hanging on the wall in the first act, at some point in the play it must go off.”