Skip to content

Add owner restart command and keep the gateway connection alive#25

Merged
HiLleywyn merged 1 commit into
mainfrom
claude/bot-restart-and-reconnect-9hiIt
May 20, 2026
Merged

Add owner restart command and keep the gateway connection alive#25
HiLleywyn merged 1 commit into
mainfrom
claude/bot-restart-and-reconnect-9hiIt

Conversation

@HiLleywyn

Copy link
Copy Markdown
Owner

Summary

  • Adds .ai restart / .ai reboot (alias) and a /restart slash command, gated to the bot owner via OWNER_ID or the Discord application owner. The command re-execs the Python interpreter after a graceful shutdown, so a wedged process clears without a redeploy.
  • Adds .ai shutdown (also owner only) for clean exits, with a confirmation prompt.
  • Hardens the outer loop in main.py so it reconnects on any connection error (not just rate-limits) with exponential backoff up to 60s; backoff resets after a successful login so a healthy bot that drops hours later still comes back quickly.
  • Adds a heartbeat watchdog inside ArchimedesBot that force-closes a quiet websocket (no healthy heartbeat for 2 minutes) so discord.py's auto-reconnect always has a chance to kick in. Also logs on_connect / on_resumed / on_disconnect so a future drop leaves a paper trail.

Test plan

  • pytest tests/ passes (157 / 157)
  • Run .ai restart in a server, watch the process re-exec and the bot come back online
  • Confirm /restart slash command appears for the owner only
  • Confirm .ai restart from a non-owner is rejected with "Only the bot owner can use this command."
  • Disconnect the host network briefly and confirm the outer loop reconnects with backoff (look for Reconnecting in Ns (attempt N) lines)
  • Idle the bot long enough to hit the previous drop and confirm the watchdog logs Gateway looks stale ... closing websocket to force reconnect. if the gateway wedges

Generated by Claude Code

A new .ai restart (and /restart) re-execs the Python process so a
wedged or unresponsive bot can recover without a redeploy. The outer
loop now reconnects on any connection error, not just rate-limits,
with exponential backoff that resets after a healthy login. A
heartbeat watchdog inside the bot force-closes a quiet websocket so
discord.py's auto-reconnect always has a chance to kick in.
@HiLleywyn HiLleywyn merged commit 2a43dea into main May 20, 2026
4 checks passed
@HiLleywyn HiLleywyn deleted the claude/bot-restart-and-reconnect-9hiIt branch May 20, 2026 06:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants