From 5d3cc49af06439ecd51fe6aa0ed1205bb2fe1928 Mon Sep 17 00:00:00 2001 From: Minz Date: Sat, 1 Aug 2026 18:09:47 +0200 Subject: [PATCH] Reset channel resume points on undo --undo only cleared the reactions log, so a subsequent run kept diffing forward from each channel's last-seen message instead of honoring days_back, silently skipping everything already undone. Undo now also clears channel_scan_state so the next run does a full fresh backlog scan. --- bot/storage.py | 10 ++++++++++ bot/undo.py | 7 ++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/bot/storage.py b/bot/storage.py index 6112f6f..c3f5361 100644 --- a/bot/storage.py +++ b/bot/storage.py @@ -132,6 +132,16 @@ class Storage: ) return inserted + def clear_scan_state(self) -> int: + """Wipe all per-channel resume points. The backlog scan only ever + consults days_back on a channel's very first scan and otherwise just + diffs forward from the last-seen message, so this must be cleared + whenever reactions are undone (or days_back is widened) to force a + fresh full backlog scan instead of silently skipping everything.""" + with self._lock, self._conn: + cur = self._conn.execute("DELETE FROM channel_scan_state") + return cur.rowcount + def get_scan_state(self, channel_id) -> Optional[dict]: with self._lock: cur = self._conn.execute( diff --git a/bot/undo.py b/bot/undo.py index 722389a..b3f3bb6 100644 --- a/bot/undo.py +++ b/bot/undo.py @@ -43,4 +43,9 @@ async def undo_all_reactions(client: discord.Client, storage: Storage, display: await asyncio.sleep(human_jitter()) - log.info("Undo complete: removed %d/%d reaction(s)", removed, total) + cleared = await asyncio.to_thread(storage.clear_scan_state) + log.info( + "Undo complete: removed %d/%d reaction(s), cleared %d channel resume point(s) — " + "the next normal run will do a full fresh backlog scan.", + removed, total, cleared, + )