summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Sima <ben@bensima.com>2026-06-04 15:01:15 -0400
committerBen Sima <ben@bensima.com>2026-06-04 15:01:15 -0400
commit299f4b47d26b7a8addb42420dda524c4e78fba87 (patch)
tree4d5501ee1554cdc4463bb3f36cdc4bbb12f855c4
parent064ac261533f146cf675af63d18c7505e1bc74b7 (diff)
Back off Zulip connection retries
-rw-r--r--main.py21
-rw-r--r--slopbot.service2
2 files changed, 19 insertions, 4 deletions
diff --git a/main.py b/main.py
index 77ce660..96eb7ef 100644
--- a/main.py
+++ b/main.py
@@ -50,14 +50,27 @@ if not SYSTEM_PROMPT_PATH.is_absolute():
SYSTEM_PROMPT = SYSTEM_PROMPT_PATH.read_text().strip()
-log.info("Connecting to Zulip...")
-client = zulip.Client(config_file=".zuliprc")
-log.info("Connected as %s", client.email)
+client = None
executor = ThreadPoolExecutor(max_workers=WORKERS, thread_name_prefix="slopbot")
agent_slots = Semaphore(AGENT_WORKERS)
+def connect_zulip() -> zulip.Client:
+ """Connect to Zulip with exponential backoff instead of crash-looping."""
+ backoff = 5
+ while True:
+ try:
+ log.info("Connecting to Zulip...")
+ connected = zulip.Client(config_file=".zuliprc")
+ log.info("Connected as %s", connected.email)
+ return connected
+ except Exception as e:
+ log.warning("Failed to connect to Zulip (%s); retrying in %ss", e, backoff)
+ time.sleep(backoff)
+ backoff = min(backoff * 2, 300)
+
+
# ---------------------------------------------------------------------------
# Zulip context
# ---------------------------------------------------------------------------
@@ -233,6 +246,8 @@ def handle_event(event: dict) -> None:
def main() -> None:
+ global client
+ client = connect_zulip()
log.info("Listening for messages...")
client.call_on_each_event(handle_event, event_types=["message"])
diff --git a/slopbot.service b/slopbot.service
index 0be6208..a39e3b4 100644
--- a/slopbot.service
+++ b/slopbot.service
@@ -12,7 +12,7 @@ EnvironmentFile=-/home/ben/src/bsima/slopbot/.env
# Agent shell commands can then resolve only the tools packaged for slopbot, e.g. slop-search/slop-fetch.
ExecStart=/run/current-system/sw/bin/nix --extra-experimental-features 'nix-command flakes' run /home/ben/src/bsima/slopbot#slopbot
Restart=on-failure
-RestartSec=5
+RestartSec=30
NoNewPrivileges=true
CapabilityBoundingSet=