more matrix debugging

This commit is contained in:
rich committed 2026-02-21 16:45:57 -05:00
1 parent 1572eabac5
commit a2e1a42fe6
1 file changed
+10 -4
+10 -4
View File
@@ -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