Skip to content

Purge and reprint bot status embed on restart and every few hours - #272

Merged
ebm5025 merged 1 commit into
mainfrom
claude/eqnotify-castle-bot-integration-5c7l4s
Aug 21, 2026
Merged

Purge and reprint bot status embed on restart and every few hours#272
ebm5025 merged 1 commit into
mainfrom
claude/eqnotify-castle-bot-integration-5c7l4s

Conversation

@ebm5025

@ebm5025 ebm5025 commented Aug 21, 2026

Copy link
Copy Markdown
Collaborator

Problem

Stale bot status embeds pile up in the bot status channel and have to be deleted by hand. The embed is tracked by message ID in the instructions table and edited in place; when those IDs drift — a redeploy, a manually deleted message, an embed-shape change — the old copies are orphaned and linger.

Fix

On restart and every 3 hours, the refresh now deletes all of the bot's own messages in the status channel and reprints from scratch.

  • purgeBotMessages() paginates the channel and deletes each bot-authored message individually — bulkDelete can't remove messages older than 14 days, and the persistent status embeds are exactly that. Human messages (if any) are left untouched.
  • It then drops the tracked instruction records (new public cancelTrackedInstructions() on InstructionsReadyAction) so the reprint posts fresh messages instead of trying to edit — and 404 on — the just-deleted ones.
  • The purge is driven from inside the existing refresh loop, keyed on elapsed time (lastPurgeAt = 0 forces it on the first refresh after startup). The 30s live-data refresh continues to edit the current embed between purges, so nothing about the live behavior changes.
  • refreshBotEmbed is now wrapped in a mutex so the periodic loop and bot data-change events (bot-prisma park/checkout) can't overlap and post duplicate embeds. This also hardens a pre-existing race in the edit path.

Notes

  • Purge interval is a single constant (PURGE_INTERVAL = 3 * HOURS); easy to tune or move to an env var if you'd prefer.
  • Only the bot's own messages are deleted, so no Manage Messages permission is required.

Testing

  • yarn tsc — clean.
  • yarn test:ci — 84 tests pass.

🤖 Generated with Claude Code


Generated by Claude Code

Stale bot status embeds accumulated in the channel across restarts/redeploys
and had to be deleted by hand: the embed is tracked by message ID, and when
those IDs drift (redeploy, manual deletion, code changes) old copies linger.

On restart and every 3 hours, the refresh now deletes all of the bot's own
messages in the status channel and reprints from scratch:

- purgeBotMessages() paginates the channel and deletes each bot-authored
  message individually (bulkDelete can't touch messages older than 14 days),
  then drops the tracked instruction records so the reprint posts fresh
  messages instead of editing the just-deleted ones.
- The purge is driven from within the existing refresh loop keyed on elapsed
  time (lastPurgeAt = 0 forces it on the first post-startup refresh), so the
  30s live-data refresh is unaffected between purges.
- refreshBotEmbed is now serialized with a mutex so the periodic loop and bot
  data-change events can't race and post duplicate embeds.

Adds a public cancelTrackedInstructions() to InstructionsReadyAction to drop
tracking without a Discord fetch (avoids 404 log noise after a purge).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BWXRmPbtEz35wquwFd8Cu7
@ebm5025
ebm5025 merged commit 94facd0 into main Aug 21, 2026
1 check passed
@ebm5025
ebm5025 deleted the claude/eqnotify-castle-bot-integration-5c7l4s branch August 21, 2026 12:16
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