Some checks failed
Skills Index Freshness Check / check-freshness (push) Has been cancelled
Skills Index Freshness Check / check-catalog-cors (push) Has been cancelled
Deploy Site / deploy-vercel (push) Has been cancelled
Deploy Site / deploy-docs (push) Has been cancelled
Docs Search Monitor / probe (push) Has been cancelled
auto-fix lint issues & formatting / Generate eslint --fix patch (push) Has been cancelled
auto-fix lint issues & formatting / Apply patch (push) Has been cancelled
PTB's Application.add_handler creates a group by keying it on the current dict and then replacing app.handlers with a new sorted dict. _register_handlers kept a reference to app.handlers from before core registration and read the core handler ids from it afterwards, so only the first group created during registration was recorded. When no plugin had a handler at connect (the usual late-install case), group 0 was recorded and the group-99 gateway_platform_event observer was not. A plugin loaded mid-run that registered a group-99 handler was then appended behind that catch-all TypeHandler(Update), and PTB, which runs the first matching handler per group, never ran it. A plugin present at connect already sat ahead of the observer, so the late re-wire did not match connect as documented. The core ids now come from the live table after registration, minus the handlers that were there before it (the plugin handlers wired at connect), so a late handler lands after earlier plugin handlers and ahead of the observer, as at connect. Ahead of the observer is the order connect already uses, and nothing the observer does depends on running first: dispatch is counted in TelegramApplication.process_update, an observer's return never completes an admission claim (4a2b984fd2), and a plugin callback accepts the claim on entry. For an update the plugin's own group-99 handler matches, the observer does not emit gateway_platform_event, the same trade-off as for a plugin wired at connect; updates it does not match still reach the observer. The gateway test's _PtbApp appended with setdefault, which hid the swap; it now mirrors PTB 22.8. A real-PTB dispatch test covers both load orders where python-telegram-bot is installed. The snapshot came with the late re-wire in21d0b12958(#119266). Reported-by: AliZakaee (#152827)