From a4f162d2ee87ccb5ea16ef20c96ccd606b2188b6 Mon Sep 17 00:00:00 2001 From: prosolis <5590409+prosolis@users.noreply.github.com> Date: Sat, 4 Jul 2026 10:42:55 -0700 Subject: [PATCH] appservice: heartbeat presence every 20s to beat Synapse's 30s offline timeout (was flapping at 60s) --- internal/bot/appservice.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/internal/bot/appservice.go b/internal/bot/appservice.go index 3de2776..cf23d94 100644 --- a/internal/bot/appservice.go +++ b/internal/bot/appservice.go @@ -18,12 +18,14 @@ import ( ) // presenceHeartbeatInterval is how often the appservice re-asserts its online -// presence. In masdevice mode the /sync long-poll refreshed presence implicitly -// (~30s); appservice mode has no /sync, so we push presence explicitly. Synapse -// decays an "online" user to unavailable after ~5min of no update, so a 1min tick -// keeps the bot reliably green while running — and lets it decay to offline on its -// own if the process dies without a graceful shutdown. -const presenceHeartbeatInterval = time.Minute +// presence. In masdevice mode the /sync long-poll refreshed presence implicitly; +// appservice mode has no /sync, so we push presence explicitly. Synapse ties +// "online" to recent activity and force-offlines a non-syncing user ~30s after its +// last update (SYNC_ONLINE_TIMEOUT). A slower tick makes the bot FLAP (green right +// after each PUT, then offline until the next) — empirically observed at 60s. So we +// tick well under 30s to hold it continuously green. A hard crash stops the +// heartbeat and Synapse offlines the bot within ~30s on its own. +const presenceHeartbeatInterval = 20 * time.Second // cryptoToDeviceTypes are the to-device event types the crypto machine must see // to establish Olm/Megolm sessions and share/receive room keys. In /sync mode