Purge and reprint bot status embed on restart and every few hours - #272
Merged
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
instructionstable 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 —bulkDeletecan't remove messages older than 14 days, and the persistent status embeds are exactly that. Human messages (if any) are left untouched.cancelTrackedInstructions()onInstructionsReadyAction) so the reprint posts fresh messages instead of trying to edit — and 404 on — the just-deleted ones.lastPurgeAt = 0forces 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.refreshBotEmbedis now wrapped in a mutex so the periodic loop and bot data-change events (bot-prismapark/checkout) can't overlap and post duplicate embeds. This also hardens a pre-existing race in the edit path.Notes
PURGE_INTERVAL = 3 * HOURS); easy to tune or move to an env var if you'd prefer.Manage Messagespermission is required.Testing
yarn tsc— clean.yarn test:ci— 84 tests pass.🤖 Generated with Claude Code
Generated by Claude Code