feat: add /restart command#112
Conversation
Adds a /restart Telegram command that sends a confirmation message then triggers SIGTERM, letting systemd restart the process. Registered in both agentic and classic modes. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
_set_bot_commands() was called right after builder.build(), but build() only creates the Application object — it does not initialize the bot's HTTP client. The actual app.initialize() (which creates the HTTPX client and calls getMe) happened much later in start(), so the set_my_commands() API call was made with no HTTP client ready and the command menu was never pushed to Telegram. Move app.initialize() into the bot's initialize() method, before _set_bot_commands(). The later app.initialize() in start() is idempotent, so there is no double-init issue. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Add app.initialize = AsyncMock() to core rate limiter test fixture so the new await self.app.initialize() in bot.initialize() doesn't fail on a non-awaitable MagicMock. - Update orchestrator command count assertions: 5→6 (agentic), 13→14 (classic) to account for the new /restart command. - Update bot command menu assertions similarly and verify "restart" appears in the command list. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
58e5e01 to
b6aecdd
Compare
|
PR Review Summary
What looks good
Issues / questions
Suggested tests
Verdict — Friday, AI assistant to @RichardAtCT |
- Document auth middleware protection in restart_command docstring - Change "Back in a few seconds" to "Back shortly" (no systemd guarantee) - Add unit test verifying restart_command calls os.kill(SIGTERM) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Thanks for the review! Pushed a fix commit addressing both points: 1. Auth concern (confirmed safe): 2. Wording nit: 3. Suggested test added:
This is already covered by the existing middleware test suite ( |
|
PR Review Summary
What looks good
Issues / questions
Suggested tests (if needed)
Verdict — Friday, AI assistant to @RichardAtCT |
|
PR Review Summary
What looks good
Issues / questions
Suggested tests (if needed)
Verdict — Friday, AI assistant to @RichardAtCT |
RichardAtCT
left a comment
There was a problem hiding this comment.
LGTM — /restart command and set_my_commands timing fix look good. CI passing.
Summary
/restartTelegram command that gracefully restarts the bot processSIGTERMso systemd (or any process manager withRestart=always) brings the bot back upset_my_commands()was called before the Application's HTTP client was initialized (see below)Bug fix: command menu not updating
_set_bot_commands()inClaudeCodeBot.initialize()was called right afterbuilder.build(), butbuild()only constructs theApplicationobject — it does not initialize the bot's HTTP client. The actualapp.initialize()(which creates the HTTPX async client and callsgetMe()) happened much later instart().This meant
set_my_commands()was hitting the Telegram API with no HTTP client ready, so the command menu was never actually pushed. Handlers still worked because they're just Python objects added to internal lists.Fix: Call
await self.app.initialize()in the bot'sinitialize()method, before_set_bot_commands(). The laterapp.initialize()call instart()is idempotent (ptb checks_initialized), so there's no double-init issue. This also fixes command menu updates for any commands added in the future.Test plan
/restartin Telegram chatjournalctlfor clean shutdown + restart cycle/command menu🤖 Generated with Claude Code