fix(bot): retry boot-time config fetch so bot self-heals on cold start #62
Reference in New Issue
Block a user
No description provided.
Delete Branch "fix/bot-boot-config-retry"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
After launching a new version or restarting the stack with
docker compose, the Discord bot shows enabled but disconnected in the admin panel. The only workaround is to disable → save → re-enable → save, which forces the site to re-push config to the bot.Root cause — a startup race
On
docker compose up/restart the bot and app start together. The bot'sdepends_on: appusescondition: service_started, which only waits for the app container to launch — not for its internal Express server (port 3001) to be listening after it connects to the DB and boots.bot/src/bootstrap.jsdid a single, un-retriedfetchfor the bot config. It loses that race (connection refused / non-ok), logs, and returns — the bot stays disconnected while the DBenabledflag is stilltrue. Hence "enabled but disconnected." The manual toggle works only because it triggers apushConfigfrom the (by-then-ready) site to the bot.Fix
Retry the boot-time config fetch with backoff (~1 min, 2s apart) until the app answers:
Also wrapped
discordManager.start(...)in try/catch: previously a bad-token boot would reject the bootstrap promise and crash the whole bot process (server.jsexits on any start failure). Now it logs and stays running, waiting for the admin to fix config — consistent with the self-heal intent. The bot's own internal listener is already up beforebootstrap()is awaited, so it stays reachable to the admin panel throughout the retry window.Verification
No automated tests exist in the bot package, so this needs a runtime check. Cold whole-stack start with
enabled=truein the DB:Expect a few
boot-time config fetch not ready — retryinglines, thenboot-time config says enabled — reconnecting→discord client ready, with the admin panel showing connected without any toggling.🤖 Generated with Claude Code
https://claude.ai/code/session_0114TpmrNW4wNXsHq5CR72jQ