The best-case POD for the Ottomans is for Selim III to reform the Ottomans at around the time of the French Revolution. Have him pull an Auspicious Incident on the Janissaries, and suddenly the Tanzimat can happen earlier. In this scenario, it's not unlikely that the Ottomans reconquer North Africa, as these reforms will be before Mehmet Ali Pasha came out of nowhere to turn Egypt into a powerhouse, and so will avoid Egypt falling independent in all but name.
Furthermore, the local elites and Jannisaries were only able to resist Selim because of the stresses caused by the Napoleonic Wars and Napoleons betrayal at Tilsit.
No. They were resisting reform even before Napoleon's invasion of Egypt, and the Janissary problem would exist even without Napoleon's betrayal at Tilsit. There was a clear precedent for Janissaries deposing Sultans, anyways. They needed to go as early as possible.
Maybe if Osman II had disbanded the Janissaries, maybe the Ottomans could have modernized?
The Janissary problem still existed and needed to be gotten rid of but they wouldn't have the opportunity to actually pull off a coup without the war and Tilsit (or something similar).
The Serbs for example, were swiftly crushed immediately after the war was over even without modernized troops and reform.
Remember that it took around 18 years after his accession for Mahmud II to feel safe enough to eliminate the Jannisaries. This stuff takes time.
Also, I'm not just talking about the war and coup themselves but the entire geopolitical situation of things like a boosted Russia, a severely weakened France, and suppressed liberalism/instability in Germany/Italy.
They pulled off coups as far back as 1622, and they were obviously the deal brokers, with the Grand Black Eunuch clearly being more powerful than the Sultan at times. I think you're offering too much credit to Tilsit here.
The Serbs were crushed because they were revolting against the local Janissary junta, not the Ottomans. It wasn't just the Serbs revolting, it was a de facto independent Janissary fiefdom rebelling as well.
They also attempted to rebel in an era before nationalism had really spread in the Balkans, when ethno-nationalism here was only existent in the Septinsular Republic. So, the motivation was not really here to be independent...yet.
It doesn't really. Osman II came close to abolishing the Janissaries in 1622, back when they were much more powerful. Hell, if Selim III had defeated the Janissaries in the 1807 coup, you would have probably seen them abolished.
What was really needed to abolish the Janissaries was to gather them in one place and kill them when they revolted. The appropriate tactics were required to abolish them, not time.
Yeah, that makes sense.