From f73a7e80a12a2424a571bfb2dc5e2fabed330946 Mon Sep 17 00:00:00 2001 From: Frank Date: Thu, 17 Sep 2026 15:48:34 -0700 Subject: [PATCH] relay: fix UnboundLocalError in dedupe pruning (rebind made the dict local) Every webhook died on 'cannot access local variable _last_sent' because the prune comprehension rebound the module global inside the function. Prune in place instead. --- scripts/signal-relay.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/scripts/signal-relay.py b/scripts/signal-relay.py index f8b5bf2..4f15f43 100755 --- a/scripts/signal-relay.py +++ b/scripts/signal-relay.py @@ -106,7 +106,12 @@ def handle_alertmanager(payload): return now = time.monotonic() key = dedupe_key(alerts) - _last_sent = {k: v for k, v in _last_sent.items() if now - v < DEDUPE_SECONDS} + # Prune in place: rebinding _last_sent here would make it local to this + # function and the read above the assignment raises UnboundLocalError + # (measured 2026-09-17: every webhook died on it). + stale = [k for k, v in _last_sent.items() if now - v >= DEDUPE_SECONDS] + for k in stale: + del _last_sent[k] if key in _last_sent: log(f"suppressed duplicate: {key[0]}") return