From fddbd8f4d4a602f4ba4009316f68f46c94f77239 Mon Sep 17 00:00:00 2001 From: Vlad Doloman Date: Mon, 22 Jun 2026 20:11:00 +0300 Subject: [PATCH] fix: seed initial state from last 8KB of log on startup --- log_watcher.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/log_watcher.py b/log_watcher.py index d5c9ae7..df865ad 100644 --- a/log_watcher.py +++ b/log_watcher.py @@ -7,6 +7,7 @@ from typing import Callable, Awaitable, Optional class LogWatcher: POLL_INTERVAL = 0.1 FILE_RETRY_INTERVAL = 1.0 + SEED_BYTES = 8192 # read last ~8 KB on open to seed initial state def __init__( self, @@ -35,7 +36,11 @@ class LogWatcher: while True: try: with open(self._path, 'r', errors='replace') as f: - f.seek(0, 2) # start at end of file (tail -f behaviour) + f.seek(0, 2) + end = f.tell() + f.seek(max(0, end - self.SEED_BYTES)) + if f.tell() > 0: + f.readline() # discard partial first line offline_since = None while True: line = f.readline()