From 8d7a66c4314c43399af56ca24cead9b7cc274ddc Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 28 Feb 2026 09:04:28 +0000 Subject: [PATCH] Fix bot not going online: stop silently swallowing presence errors _set_presence was catching all exceptions and logging them at DEBUG level, which meant connection failures (bad token, unreachable homeserver, etc.) were completely hidden at the default INFO log level. The bot would appear to start normally but never actually go online. Now the initial presence call in start_presence() propagates errors so startup fails visibly if the Matrix connection doesn't work. The background heartbeat loop still catches errors but logs them at WARNING. https://claude.ai/code/session_019ANRdyL2jfi7ysWhqN4PfD --- app/matrix.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/app/matrix.py b/app/matrix.py index f5ea0fd..46c1342 100644 --- a/app/matrix.py +++ b/app/matrix.py @@ -38,23 +38,26 @@ async def close_client() -> None: pass _presence_task = None if _client is not None: - await _set_presence("offline") + try: + await _set_presence("offline") + except Exception: + log.warning("Failed to set offline presence during shutdown", exc_info=True) await _client.close() _client = None async def _set_presence(state: str) -> None: client = await get_client() - try: - await client.set_presence(state) - except Exception: - log.debug("Presence update failed", exc_info=True) + await client.set_presence(state) async def _presence_loop() -> None: while True: - await _set_presence("online") await asyncio.sleep(PRESENCE_INTERVAL_SECONDS) + try: + await _set_presence("online") + except Exception: + log.warning("Presence heartbeat failed", exc_info=True) async def start_presence() -> None: