From 3e3069d2aa579d28a6b29cd7a029dec6044bcff0 Mon Sep 17 00:00:00 2001 From: Jared Vititoe Date: Mon, 23 Nov 2026 23:52:27 -0500 Subject: [PATCH] WAN degraded: a modem restart resets the judgement Only health periods from 15 minutes after the latest restart count, so a slowdown the restart fixed neither opens a ticket on deploy nor holds one open. Replay: opens 11-24 01:30, resolves 04:20 after the reboot. Co-Authored-By: Claude Opus 5.5 --- README.md | 2 +- modem.py | 2 ++ monitor.py | 8 +++++++- tests/test_monitor.py | 9 +++++++++ 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7544860..b1091ed 100644 --- a/README.md +++ b/README.md @@ -433,7 +433,7 @@ swap or recabling. | Modem pages unreadable, e.g. after a firmware update (≥`modem.failure_threshold`) | P3 | | UniFi logs that Smart Power auto power-cycled the modem | P3 | | UniFi logs that the WAN failed multiple times in 24 hours, and at least 2 of those drops aren't explained by a modem restart (decided 10 minutes later; at most one ticket a day) | P2 | -| Internet degraded: at least `modem.degraded_fraction` (default half) of the last 2 hours' 5 minute periods slow, lossy or down by UniFi's WAN health. Closes with a recovery note once the last 2 hours are at most a quarter bad. | P2 | +| Internet degraded: at least `modem.degraded_fraction` (default half) of the last 2 hours' 5 minute periods slow, lossy or down by UniFi's WAN health. Closes with a recovery note once the last 2 hours are at most a quarter bad. A modem restart resets it: only periods from 15 minutes after the latest restart count. | P2 | | An installed cable doesn't match the cutsheet (wrong neighbor, no link, missing port, port conflict) for `cutsheet.mismatch_ticket_hours` | P4 | A failed Pulse ping check counts as "unknown": it neither raises nor resolves `host_unreachable`. diff --git a/modem.py b/modem.py index 67c8a63..cdd16ae 100644 --- a/modem.py +++ b/modem.py @@ -418,6 +418,8 @@ def recovered(periods: List[dict], newest: float) -> bool: # Restart entries this close together are one restart (a reboot, then Smart Power, say). _EPISODE_GAP_S = 900 +# WAN health from this long after a restart reflects the modem as it now runs. +RESTART_SETTLE_S = 900 def restart_episodes(history: dict, button: Optional[dict], since: float) -> List[dict]: diff --git a/monitor.py b/monitor.py index f812b0c..bfac551 100644 --- a/monitor.py +++ b/monitor.py @@ -2099,13 +2099,19 @@ class NetworkMonitor: if not periods: return # nothing fresh to judge by: leave any open alert as it is newest = periods[-1]['ts'] + episodes, lines, hint = self._restart_context(time.time()) + if episodes: + # A restart resets the judgement: only what came after it (once it has settled) + # counts, so a slowdown it fixed neither opens a ticket nor holds one open. + periods = [p for p in periods if p['ts'] >= episodes[-1]['at'] + modem_api.RESTART_SETTLE_S] + if not periods: + return fraction = float((self.cfg.get('modem') or {}).get('degraded_fraction', modem_api.DEGRADED_FRACTION)) bad = modem_api.degradation(periods, newest, fraction) if bad is None: if modem_api.recovered(periods, newest): db.resolve_event('wan_degraded', self.modem_name, '') return - episodes, lines, hint = self._restart_context(time.time()) parts = [f'{bad[s]} {s}' for s in ('latency', 'loss', 'down') if bad[s]] description = (f'The internet has been degraded for most of the last 2 hours: {bad["bad"]} of ' f'{bad["total"]} five-minute periods had {", ".join(parts)} (UniFi WAN health).') diff --git a/tests/test_monitor.py b/tests/test_monitor.py index df18964..989de29 100644 --- a/tests/test_monitor.py +++ b/tests/test_monitor.py @@ -1240,6 +1240,15 @@ class TestWanDegraded: mon._process_wan_degraded(None, []) assert not db.upsert_event.called and not db.resolve_event.called + def test_a_restart_resets_the_judgement(self, mon, db): + # 2026-11-24: hours of loss, then a reboot 50 minutes ago, fine since + end = time.time() + history = json.dumps({'outages': [], 'restarts': [{'at': end - 3000, 'by': None}]}) + db.get_state.side_effect = lambda k, d=None: history if k == 'wan_history' else None + mon._process_wan_degraded(_timeline(['loss'] * 16 + ['down'] * 2 + ['ok'] * 6, end), []) + assert not db.upsert_event.called + db.resolve_event.assert_called_with('wan_degraded', 'att-modem', '') + def test_slow_ping_from_the_modem_is_mentioned(self, mon, db): checks = json.dumps({'ping': {'verdict': 'gateway', 'avg_ms': 1154}}) db.get_state.side_effect = lambda k, d=None: checks if k == 'modem_checks' else None