Disqualify stricken updates from validity on ingest & resync
authorJakob Cornell <jakob+gpg@jcornell.net>
Wed, 28 Sep 2022 04:26:22 +0000 (23:26 -0500)
committerJakob Cornell <jakob+gpg@jcornell.net>
Wed, 28 Sep 2022 04:26:22 +0000 (23:26 -0500)
strikebot/src/strikebot/__init__.py

index 77be97767dc66d8ea8d115eff79d533c88d40e64..daa9944173e3d28e38208aef33b6c2593009668f 100644 (file)
@@ -1,4 +1,4 @@
-"""Count tracking logic."""
+"""Count tracking logic and bot's external interface."""
 
 from contextlib import nullcontext as nullcontext
 from dataclasses import dataclass
@@ -143,12 +143,12 @@ async def count_tracker_impl(
                                or (
                                        update.number is not None
                                        and (pred is None or pred.number is None or update.can_follow(pred))
+                                       and not update.stricken
                                )
                        )
                        logger.debug("{} {} -> {}".format("accepted" if tu.accepted else "rejected", pred, update))
                        if tu.accepted:
                                # resync subsequent updates
-                               newly_valid = []
                                newly_invalid = []
                                resync_last_valid = update
                                converged = False
@@ -158,14 +158,16 @@ async def count_tracker_impl(
                                                if last_valid:
                                                        converged = True
                                        elif scan_tu.update.number is not None:
-                                               accept = resync_last_valid.number is None or scan_tu.update.can_follow(resync_last_valid)
-                                               if accept and scan_tu.accepted:
+                                               accept = (
+                                                       (resync_last_valid.number is None or scan_tu.update.can_follow(resync_last_valid))
+                                                       and not scan_tu.update.stricken
+                                               )
+                                               if accept:
+                                                       assert scan_tu.accepted
+                                                       resync_last_valid = scan_tu.update
                                                        # resync would have no effect past this point
                                                        if last_valid:
                                                                converged = True
-                                               elif accept:
-                                                       newly_valid.append(scan_tu)
-                                                       resync_last_valid = scan_tu.update
                                                elif scan_tu.accepted:
                                                        newly_invalid.append(scan_tu)
                                                        if scan_tu.update is last_valid:
@@ -180,12 +182,6 @@ async def count_tracker_impl(
                                        last_valid = resync_last_valid
 
                                parts = []
-                               if newly_valid:
-                                       parts.append(
-                                               "The following counts are valid:\n\n"
-                                               + "\n".join(" - " + _format_update_ref(tu.update, thread_id) for tu in newly_valid)
-                                       )
-
                                unstrikable = [tu for tu in newly_invalid if tu.update.stricken]
                                if unstrikable:
                                        parts.append(
@@ -207,7 +203,7 @@ async def count_tracker_impl(
                                                if enforcing:
                                                        api_pool.enqueue_request(StrikeRequest(thread_id, invalid_tu.update.name, invalid_tu.update.ts))
                                                invalid_tu.update.stricken = True
-                       elif update.count_attempt:
+                       elif update.count_attempt and not update.stricken:
                                if enforcing:
                                        api_pool.enqueue_request(StrikeRequest(thread_id, update.name, update.ts))
                                update.stricken = True