Conversation
- Deregister stale Telegram webhook/polling before connect (NousResearch#23783). Calls delete_webhook(drop_pending_updates=True) before starting a new polling session to prevent 'bot token already in use' errors after gateway restart or update. - Store background task results in memory for querying (NousResearch#8568). Completed /background results are kept in _background_results list with task_id, prompt, and response for later retrieval.
|
Thanks for looking at this — closing. Two unrelated issues are bundled here, and both have problems:
If you want to land either fix, please split them and rebase against current main so the existing code (Telegram side) and the consumer plumbing (bg-results side) are addressed. |
What does this PR do?
Two independent bug fixes for gateway reliability and CLI usability:
Telegram token conflict after update/restart (Telegram bot token already in use after hermes update — gateway fails to start, Telegram broken afterwards #23783). When the gateway restarts (via hermes update, crash recovery, or manual restart), Telegram's servers may still consider the old polling connection active. The new instance's connect() call gets rejected with "bot token already in use." Added an explicit delete_webhook(drop_pending_updates=True) call before every connect attempt, which tells Telegram's API to release the stale session before the new one starts. This matches how python-telegram-bot's own startup sequence handles webhook cleanup, applied here to the polling path as well.
Background task results stored for retrieval ([Bug]: Background tasks have no observable state — no logs, no file list, no session context for foreground agent #8568). The /background command spawned a separate AIAgent and displayed results in the CLI, but once the output scrolled off screen there was no way to see what background tasks completed or what they produced. Added an in-memory _background_results list that stores task_id, prompt, and truncated response for each completed task. This gives both the user and the foreground agent a way to query past background results.
Related Issue
Fixes #23783, #8568
Type of Change
Changes Made
How to Test