diff options
| -rw-r--r-- | main.py | 21 | ||||
| -rw-r--r-- | slopbot.service | 2 |
2 files changed, 19 insertions, 4 deletions
@@ -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= |
