Auditor recorded output

← All 27 packs

Proven

prune() deletes acked events that are still being reported, so they come back as new unacked alerts

bugmedium src/argus_scout/store/sqlite.py:233

The finding

prune() deletes any event whose acked_at is older than the cutoff (also any whose expires_at is older). It never checks last_seen or whether the event is resolved. An event that was acknowledged but whose condition persists is still re-sent by its source each cycle; upsert_event refreshes it, but its acked_at does not change. After the retention window, prune() deletes the row anyway. On the next ingest, upsert_event finds no row and INSERTs it fresh, with acked_at taken from the incoming payload (normally NULL) and broadcast_count reset. The person's ack and the announce bookkeeping are lost. The ongoing, already-acknowledged condition reappears in open_events() and gets broadcast again as new news. This repeats every retention period. It also contradicts the docstring's intent that only finished events are pruned.

  221|         raise RuntimeError(f"database schema v{current} is newer than this argus-scout (v{SCHEMA_VERSION})")
  222|     for version in range(current + 1, SCHEMA_VERSION + 1):
  223|         try:
  224|             conn.executescript(f"BEGIN;\n{MIGRATIONS[version - 1]}\nPRAGMA user_version = {version};\nCOMMIT;")
  225|         except Exception:
  226|             if conn.in_transaction:
  227|                 conn.execute("ROLLBACK")
  228|             raise
  229|         log.info("store.migrated", version=version)
  230|     return SCHEMA_VERSION
  231| 
  232| 
  233| class SqliteStore:
  234|     """The default :class:`~argus_scout.store.base.Store`. ``path`` may be ``":memory:"``."""
  235| 
  236|     @classmethod
  237|     def copy_of(cls, path: Path | str) -> SqliteStore:
  238|         """An in-memory copy of the database at ``path`` (read-only open; empty if it doesn't exist).
  239| 
  240|         Writes to the copy never reach the file: a dry run sees real history without changing it.
  241|         """
  242|         store = cls(":memory:")
  243|         if str(path) != ":memory:" and Path(path).is_file():
  244|             src = sqlite3.connect(f"{Path(path).resolve().as_uri()}?mode=ro", uri=True)
  245|             try:

The work pack

Recommendation. Only prune events that are no longer being refreshed: add AND last_seen < ? to each clause (or to the whole predicate). An event the source still reports then keeps its ack and announce state.

Acceptance criteria

  • Address: prune() deletes acked events that are still being reported, so they come back as new unacked alerts
  • Keep the change scoped to the cited file/symbols unless impact requires otherwise
  • Only prune events that are no longer being refreshed: add AND last_seen < ? to each clause (or to the whole predicate). An event the source still reports then keeps its ack and announce state.
  • Re-check src/argus_scout/store/sqlite.py after the fix

Status

  1. claimed
  2. resolved

The fix

2024ed9c31 fix: prune never deletes an event its source still reports.

diff --git a/src/argus_scout/store/sqlite.py b/src/argus_scout/store/sqlite.pyindex c87199f..1977a03 100644--- a/src/argus_scout/store/sqlite.py+++ b/src/argus_scout/store/sqlite.py@@ -943,15 +943,17 @@ class SqliteStore:         """Delete events acked, resolved or expired before ``older_than``, reports and delivery records older         than it, and usage counts of earlier days. -        Open events, recommendations and their audit trail are never pruned.+        Open events, recommendations and their audit trail are never pruned, nor is an event its source still+        reports (``last_seen`` since ``older_than``): pruning it would bring it back unacked, as news.         """         cutoff = _ts(older_than)         with self._tx() as conn:             events = conn.execute(-                """DELETE FROM events WHERE (acked_at IS NOT NULL AND acked_at < ?)-                       OR (resolved_at IS NOT NULL AND resolved_at < ?)-                       OR (expires_at IS NOT NULL AND expires_at < ?)""",-                (cutoff, cutoff, cutoff),+                """DELETE FROM events WHERE last_seen < ?+                       AND ((acked_at IS NOT NULL AND acked_at < ?)+                            OR (resolved_at IS NOT NULL AND resolved_at < ?)+                            OR (expires_at IS NOT NULL AND expires_at < ?))""",+                (cutoff, cutoff, cutoff, cutoff),             ).rowcount             reports = conn.execute("DELETE FROM reports WHERE generated_at < ?", (cutoff,)).rowcount             deliveries = conn.execute("DELETE FROM deliveries WHERE at < ?", (cutoff,)).rowcountdiff --git a/tests/test_store.py b/tests/test_store.pyindex 87b78aa..43f383a 100644--- a/tests/test_store.py+++ b/tests/test_store.py@@ -330,6 +330,15 @@ def test_prune(store):     assert store.get_recommendation(rec.id) is not None  +def test_prune_keeps_an_acked_event_its_source_still_reports(store):+    store.upsert_event(event("ongoing"), now=T0)+    store.ack_event("nas", "ongoing", "someone", at=T0)+    store.upsert_event(event("ongoing"), now=T0 + timedelta(days=9))  # still reported, still acked+    assert store.prune(T0 + timedelta(days=5))["events"] == 0+    kept = store.get_event("nas", "ongoing")+    assert kept is not None and kept.acked_at is not None++ def test_restart_keeps_everything(db_path):     rec = proposal()     with SqliteStore(db_path) as s:

How it was judged

Proven 1 test(s) fail on dev and pass with the fix: tests/test_store.py::test_prune_keeps_an_acked_event_its_source_still_reports

Judged 24 Nov 2026, 04:48 UTC against dev at d0c0f66.

Teston devdev + patch
tests/test_store.py::test_prune_keeps_an_acked_event_its_source_still_reportsfailedpassed
The other 28 tests in the run (28 with the same result on both trees)
tests/test_store.py::test_ackpassedpassed
tests/test_store.py::test_audit_trail_survives_restartpassedpassed
tests/test_store.py::test_copy_of_is_a_detached_snapshotpassedpassed
tests/test_store.py::test_datetimes_normalised_to_utcpassedpassed
tests/test_store.py::test_event_round_trippassedpassed
tests/test_store.py::test_file_store_uses_wal_and_foreign_keyspassedpassed
tests/test_store.py::test_fingerprint_dedup_querypassedpassed
tests/test_store.py::test_guardrail_refusal_stores_nothingpassedpassed
tests/test_store.py::test_key_migration_keeps_old_rowspassedpassed
tests/test_store.py::test_list_by_statuspassedpassed
tests/test_store.py::test_manual_approval_sourcepassedpassed
tests/test_store.py::test_mark_announced_drives_reannouncepassedpassed
tests/test_store.py::test_migrations_are_idempotentpassedpassed
tests/test_store.py::test_newer_schema_is_refusedpassedpassed
tests/test_store.py::test_open_events_skip_expiredpassedpassed
tests/test_store.py::test_prunepassedpassed
tests/test_store.py::test_recommendation_round_trippassedpassed
tests/test_store.py::test_rejection_reason_in_trailpassedpassed
tests/test_store.py::test_reportspassedpassed
tests/test_store.py::test_resolved_column_migration_keeps_open_events_openpassedpassed
tests/test_store.py::test_restart_keeps_everythingpassedpassed
tests/test_store.py::test_runtime_rule_store_keeps_file_rules_outpassedpassed
tests/test_store.py::test_runtime_rules_survive_restartpassedpassed
tests/test_store.py::test_satisfies_protocolpassedpassed
tests/test_store.py::test_shared_across_threadspassedpassed
tests/test_store.py::test_signal_pending_round_trippassedpassed
tests/test_store.py::test_unchanged_reupsert_keeps_ack_but_changed_content_reopenspassedpassed
tests/test_store.py::test_upsert_updates_last_seen_without_duplicatingpassedpassed