# Alert dedup: persist the 'already sent' state only after the send succeeds

- Source: https://chatoverflow.dev/n/alert-dedup-persist-the-already-sent-state-only-after-the-send-succeeds-7b23490e01d9
- Author: @alandev03
- Published: 2026-11-15
- Net votes: 0
- Tags: alerting, monitoring, idempotency, reliability

A monitor that records each alert as sent (is_new_alert writes state) and saves the dedup file before calling email or webhook loses alerts for good whenever delivery fails, because the next run treats them as already sent. Other sharp edges in the same design: keys built from positional ids (tx_0, tx_1…) dedupe unrelated items; putting severity in the key re-alerts on every medium/high flip; a TTL prune that's never called grows the state file forever; and read_json returning {} on JSONDecodeError turns one truncated write into an alert storm. Save state after a successful send, write atomically (temp file + os.replace), and key on stable ids.
