From 140c7870da8604435e8b0755501e46970f67d85c Mon Sep 17 00:00:00 2001 From: drobison00 Date: Sat, 31 Oct 2026 10:39:18 -0600 Subject: [PATCH] Keep a live issue's notification record past retention, so a restart does not send it again Age pruning deleted every notified row older than [retention] max_age_s, including those of issues still open. A row's time is written only when a notification is sent, so an issue that stays open at one severity longer than the retention lost its record, and the next restart notified it again: the duplicate 58a9ff6 set out to stop. Prune a notified row only once its issue is resolved or no longer stored, the same rule the issues table keeps. Reported by Bhanu-partap-13 on 58a9ff6. --- neonwatch/store.py | 4 +++- neonwatch/store_test.py | 11 +++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/neonwatch/store.py b/neonwatch/store.py index 10d7e87..2385ebe 100644 --- a/neonwatch/store.py +++ b/neonwatch/store.py @@ -307,7 +307,9 @@ class AuditEntry: "DELETE FROM links WHERE at < ?", "DELETE FROM links_latest WHERE at < ?", "DELETE FROM analyses WHERE completed_at < ?", - "DELETE FROM notified WHERE at < ?", + # A live issue keeps its record however old, or a restart would send it again. + "DELETE FROM notified WHERE at < ? AND issue_id NOT IN " + "(SELECT id FROM issues WHERE state != 'resolved')", ) #: Size-pruning tiers, each the oldest rows first: every history table merged in time order, diff --git a/neonwatch/store_test.py b/neonwatch/store_test.py index cee92fd..3e15660 100644 --- a/neonwatch/store_test.py +++ b/neonwatch/store_test.py @@ -667,6 +667,17 @@ def test_a_notification_keeps_the_highest_rank_sent_and_the_latest_time(tmp_path s.close() +def test_a_live_issue_keeps_its_notification_past_retention(tmp_path: Path) -> None: + s = Store(tmp_path / "store.sqlite3", config(max_age_s=100)) + s.apply(issue_event(issue("open", updated_at=10))) + s.apply(issue_event(issue("done", state=IssueState.RESOLVED, updated_at=10))) + for issue_id in ("open", "done", "gone"): + s.note_notified(issue_id, 2, 10.0) + s.prune(now=1000) + assert s.notified() == {"open": (2, 10.0)} # resolved or no longer stored: forgotten + s.close() + + def _fill(s: Store, n: int) -> None: for t in range(n): s.apply(obs_event("wide", {f"field{k}": float(t) for k in range(50)}, at=1000 + t))