From 4ba8f48228cd4416b444e4e11403345147296756 Mon Sep 17 00:00:00 2001 From: benya Date: Mon, 9 Feb 2026 04:18:05 +0300 Subject: [PATCH] Auto-reset incidents diff marker if ahead of log --- handlers/system.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/handlers/system.py b/handlers/system.py index 4c55162..e4062af 100644 --- a/handlers/system.py +++ b/handlers/system.py @@ -420,11 +420,22 @@ async def incidents_diff(msg: Message): except Exception: last_dt = None rows = read_raw(cfg, hours=hours, limit=5000, include_old=True) - fresh: list[tuple[datetime, str]] = [] - for dt, line in rows: - if last_dt and dt <= last_dt: - continue - fresh.append((dt, line)) + + def collect(from_dt): + fresh: list[tuple[datetime, str]] = [] + for dt, line in rows: + if from_dt and dt <= from_dt: + continue + fresh.append((dt, line)) + return fresh + + fresh = collect(last_dt) + # auto-reset if marker is ahead of all rows + if not fresh and last_dt and rows and last_dt >= rows[-1][0]: + last_dt = None + runtime_state.set_state("incidents_diff_last_ts", None) + fresh = collect(None) + if not fresh: note = f"since {last_dt.astimezone().strftime('%Y-%m-%d %H:%M')}" if last_dt else "for the period" await msg.answer(f"📣 No new incidents {note} (window {hours}h)", reply_markup=system_logs_audit_kb)