Last year, India and China were locked in their most serious border crisis in the last three decades. China's state-controlled media was issuing near-daily threats of war, as both sides built up forces on the edge of the tiny Kingdom of Bhutan.
It would have seemed implausible that, just eight months on, Mr Modi and Mr Xi would be meeting at an informal summit. But this is exactly what it is happening in the Chinese city of Wuhan, as the two leaders convene far from their capitals, without aides or an agenda, and plenty of time to discuss their mounting differences.
But the meeting does not come out of the blue. After the border dispute was defused in August, Mr Modi and Mr Xi broke the ice at the Brics summit in September, alongside the leaders of Russia, Brazil and South Africa.
A flurry of high-level visits to China followed, including by India's foreign secretary, national security adviser, foreign minister and defence minister.
There were also some olive branches. In February, the Indian government sent out a private note asking officials to keep away from events marking the 60th anniversary of the Dalai Lama's exile from Tibet. It quietly informed Beijing of this.
China considers the Dalai Lama a separatist and tries to isolate the spiritual leader by asking foreign leaders not to see him.
In March, Mr Modi followed up with fulsome congratulations to Mr Xi on his re-appointment as president, saying it showed Mr Xi enjoyed the "support of the whole Chinese nation". In recent days,
China reciprocated. It will resume sharing hydrological data on the rivers that run into India and has offered to re-start low-level military exercises; both activities were suspended during last year's crisis.
So why is this thaw occurring now? There are several reasons.
Firstly, India believes that last year's crisis marked a dangerous phase in the relationship and that tensions need to be kept in check - especially with national elections in 2019. More broadly, China's economy is five times bigger than India's and its defence spending is three times as large.
While India has a local military advantage at many points on the border, it still needs time to build up its strength.
Secondly, India hopes to secure Beijing's cooperation on several issues where China's role is crucial, such as putting pressure on Pakistan-based terrorist groups and securing India's admission to the Nuclear Suppliers Group (NSG), a body that controls nuclear trade.
In recent years, Indians have grown increasingly frustrated at what they see as Chinese efforts to thwart India's rise, but Delhi has not given up on nudging Mr Xi in a more flexible direction.
Thirdly, India is responding to an uncertain period in world politics. India's concern is that Beijing will improve ties both with Washington, because of the North Korean crisis, and with Moscow, because of the rupture in West-Russia relations, all at Delhi's expense. Better, in this view, that India hedges its bets now.
"With a strengthening Russia-China axis and with the US taking its eye off China to deal with Russia," warned PS Raghavan, a former ambassador and chairman of a body that advises the Indian government on national security, "it is prudent for India to maintain a harmonious dialogue with China, even as we deal with the wrinkles in our relations with the other two great powers."
Of course, there are advantages for China too. Last year, India was the only country to publicly reject China's flagship Belt and Road Initiative (BRI), a network of infrastructure investment stretching from Asia to Europe.
More recently, the US, Japan and even the EU have grown more sceptical of the project, which they argue is skewed towards Chinese companies, saddles small countries with unsustainable debt and masks strategic, rather than economic, ambitions.
China is eager to dampen India's hostility to the scheme. It is also concerned about last year's meeting of India, the US, Japan and Australia - informally known as the Quad - after a decade-long hiatus, and their joint efforts to develop alternatives to the BRI. By engaging Mr Modi, Mr Xi hopes to slow India's steady drift towards America and its allies.
Nevertheless, it is premature to see this as a rapprochement. Beneath the thaw, the currents of competition swirl stronger than ever - on air, land and sea.
India just concluded its largest-ever air exercises, pointedly demonstrating how it could move hundreds of aircraft from its Pakistan-facing western sector to the China-facing eastern sector in under 48 hours.
On the ground, the dispute at the heart of last summer's standoff is dormant rather than resolved. China has built up its forces a stone's throw from the flashpoint, while India has upped its own presence and patrols the border more aggressively.
The maritime contest is most vigorous of all. China, fresh from opening its first overseas military base in Djibouti, on the Horn of Africa, is deepening its involvement in the small island nations to India's south.
The Indian Navy, whose most important task is now watching the Chinese naval vessels that roam the Indian Ocean in growing numbers, has recently signed agreements giving it access to the facilities of the US, France and Oman.
No doubt the relaxed surroundings of Wuhan will help the two leaders have a candid discussion on the issues that divide them, and we may see a further softening of tone. But beyond the bonhomie, this strategic competition for power and influence is unlikely to slow down.
More about: India