As the Syrian uprising evolved into full-blown warfare, and as it now winds its way towards an apparently inevitable denouement, so US policy has struggled to adapt. Donald Trump's initial instincts – and tweets – that the US would pull out of Syria have been reversed, but the precise direction is not yet clear.
America's Syria policy appears to be formulated somewhere between the White House and the State Department. Since John Bolton came in as National Security Adviser earlier this year and Jim Jeffrey was appointed as the State Department's special representative for Syria last month, a new policy appears to be taking shape.
Both have publicly declared that the estimated 2,000 US troops inside Syria will not leave "as long as Iranian troops are outside Iranian borders", as Mr Bolton put it at the United Nations General Assembly. Mr Jeffrey later said that US troops would not leave before the end of this year and also promised "a more active approach" inside Syria. Taken together, these comments reverse Mr Trump's assertions, made as recently as April this year, that he would withdraw from Syria.
The policy, while evolving, does offer a specific direction of travel and a broadly clear goal: to roll back Iran's influence inside Syria and ensure that Iranian forces leave Syrian territory. The only problem is that Iran has spent years preparing for precisely that eventuality. Iran's policy inside Syria has been configured to retain influence, even after the last Iranian soldier goes home.
From the very beginning of the war, Tehran has sought to embed its fighters and those of its allies into the conflict.
For the Iranian regime, the idea has been to find ways to defuse its influence and ideology across society, rather than maintain it in a top-down, single chain of command. That makes it much harder to destroy.
Iran, with a large military and developed intelligence agencies, as a centre of Shia Islam and as a country with extensive links to Iraq and Lebanon, was always going to be in a position to influence Syria's Shia population culturally, religiously and militarily. All it needed was the appropriate opening.
Tehran sent advisers as early as 2011, during the early period of the uprising, and Iranian fighters were on the ground in Syria from at least 2012, around the same time as Hezbollah began to become covertly involved.
Since 2013, Hezbollah's influence has been open and a fortnight ago, Hezbollah's leader Hassan Nasrallah used a speech to warn that “no one can force us to leave Syria” and that Hezbollah would stay in the country indefinitely.
But Hezbollah is only the largest of the foreign militias in Syria. Iran has used the Syrian conflict as an opportunity to create further Shia militias, in the way that it did in Iraq after the 2003 invasion.
The links between these groups and the complexity of their chains of command are bewildering. Some are directed from Damascus, others from Tehran, others still have close ties to Hezbollah or even to the Shia miltias of Iraq.
Some of the larger groups, such as the Abbas Brigade, have splintered off into smaller militias inside Syria. Others, such the Zulfiqar Brigade, appear to have links with organisations abroad, especially in Iraq.
Researchers have tried to uncover the groups and their affiliations through social media posts, photographs of soldiers and officers, symbols, flags, names and even funeral notices. But in the fast-moving war, when affiliations and alliances shift rapidly, the dynamics are fiendishly difficult to unravel.
What is certain is that, with overlapping personnel, commanders and fighters drawn from diverse countries (Iran has recruited Shia fighters from Pakistan and Afghanistan) and many Syrian fighters swapping sides, it is almost impossible to distinguish between Syrian and Iranian groups. Similarly it is difficult to determine who is taking orders from Damascus and who is taking orders from Tehran, or between those who pledge allegiance to one but remain influenced by the other. It is difficult to know who the Iranian militias are, let alone if they have gone home.
Since at least 2012, under the guise of relocating families to more secure areas, Iran and the regime have swapped populations inside Syria along sectarian lines. The best-known has been the relocation of Sunni Muslims from the Damascus suburb of Zabadani to the northern villages of Foua and Kefraya, just outside Idlib. Similar numbers of Shia Muslims from those villages were brought to Zabadani.
Other populations have also been switched, particularly around important Shia shrines, such as the Sayyidah Zaynab mosque in Damascus. Shia families, reportedly including Iraqis and Lebanese, have been relocated to the area.
The aim appears to be to secure Syria south of Homs, meaning the coastal cities and the area between the capital and the Lebanese border. By ensuring Shia demographic supremacy in this area, both Iran – which is one of the two centres of the Shia faith – and the regime, which is drawn predominantly from Alawite Shias, hope to insulate themselves while also protecting Hezbollah in Lebanon.
Taken together, these links create a spider's web of influence across Syria, Iraq and Lebanon. Iran not only has direct influence with the Assad regime in Damascus, it also has influence on militias that Damascus ostensibly controls, on Hezbollah, which itself has influence with Damascus and on Shia Syrians, through its power as a centre of religious learning.
Thus, even if the last Iranian soldier is forced home, Tehran will still be able to sway Damascus. Iran will not need to keep any of its fighters in Syria to retain influence in the country indefinitely.