diff --git a/matrix_bot.py b/matrix_bot.py index 1d2814c..ede8fd6 100644 --- a/matrix_bot.py +++ b/matrix_bot.py @@ -80,11 +80,13 @@ class MatrixBot: # Initial sync with no timeout to consume backlog before registering callbacks, # so we don't replay old messages on startup. try: - resp = await self.client.sync(timeout=0, full_state=True) + resp = await self.client.sync(timeout=0) if isinstance(resp, SyncError): - print(f" ! [Matrix] Initial sync warning (non-fatal): {resp.message}") + print(f" ! [Matrix] Initial sync error: {resp.message}") + else: + print(f">> [Matrix] Initial sync OK, next_batch={self.client.next_batch!r}") except Exception as e: - print(f" ! [Matrix] Initial sync exception (non-fatal, continuing): {e}") + print(f" ! [Matrix] Initial sync exception: {e}") # Join all configured rooms. The bot account must be a member of a room # to receive its events in the sync stream — having the room ID in config @@ -98,7 +100,11 @@ class MatrixBot: self.client.add_event_callback(self._on_message, RoomMessageText) print(">> [Matrix] Listening for commands") - await self.client.sync_forever(timeout=30000) + # Use a short poll timeout (5 s) to stay well under any reverse-proxy + # idle timeout. A 30 s long-poll through nginx/caddy will often get a + # 504 which matrix-nio can't parse, causing the "next_batch required" + # loop and silencing all callbacks. 5 s is safe for all common setups. + await self.client.sync_forever(timeout=5000) # ------------------------------------------------------------------------- # Event handler