From 6afa75b6385c3d4a02758acfb4215d06ee419171 Mon Sep 17 00:00:00 2001 From: Astra Logical Date: Thu, 30 Jul 2026 12:14:57 -0400 Subject: [PATCH] Fix syncing issues --- matrix_keycloak_bot.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/matrix_keycloak_bot.py b/matrix_keycloak_bot.py index 5ca3405..5510bce 100644 --- a/matrix_keycloak_bot.py +++ b/matrix_keycloak_bot.py @@ -477,12 +477,11 @@ async def main(): except (json.JSONDecodeError, KeyError) as e: print(f"⚠️ Credentials file is empty or corrupted ({e}). Discarding and forcing new login...") - # 2. If no session exists or restoration failed, log in and save the credentials + # 2. If no session exists or restoration failed, log in and save credentials if not session_restored: print(f"No valid session found. Logging in to {MATRIX_HOMESERVER}...") resp = await client.login(MATRIX_BOT_PASSWORD) - # Create the store directory if it doesn't exist os.makedirs(os.path.dirname(CREDENTIALS_FILE), exist_ok=True) with open(CREDENTIALS_FILE, "w") as f: @@ -493,8 +492,13 @@ async def main(): }, f) print(f"Logged in and saved credentials for {MATRIX_BOT_USER}.") + # Optional: Perform an initial full state sync ONCE on startup + print("Performing initial state sync...") + await client.sync(full_state=True) + + # Start the continuous sync loop WITHOUT full_state=True and with a 20s timeout print("Syncing...") - await client.sync_forever(timeout=30000, full_state=True) + await client.sync_forever(timeout=20000, full_state=False) if __name__ == "__main__":