Skip to main content

Watchdog API

The watchdog monitors agent gateway processes for health and automatically recovers from failures. It detects crash loops, performs auto-repair, and sends notifications via Telegram and Discord.

How It Works

Configuration

VariableDefaultDescription
WATCHDOG_CHECK_INTERVAL120Health check interval in seconds
WATCHDOG_DEGRADED_CHECK_INTERVAL5Retry interval when degraded (seconds)
WATCHDOG_MAX_REPAIR_ATTEMPTS2Max auto-repair attempts before crash-loop
WATCHDOG_CRASH_LOOP_WINDOW300Window for crash-loop detection (seconds)
WATCHDOG_CRASH_LOOP_THRESHOLD3Crashes in window to trigger crash-loop
WATCHDOG_AUTO_REPAIRtrueEnable/disable auto-repair
TELEGRAM_BOT_TOKENTelegram bot token for notifications
TELEGRAM_ADMIN_CHAT_IDChat ID for Telegram notifications
DISCORD_WEBHOOK_URLDiscord webhook URL for notifications

Lifecycle States

StateDescription
stoppedGateway is not running
startingGateway process started, waiting for health check
runningGateway is healthy
degradedHealth check failed, retrying
crash_loopToo many crashes, auto-repair exhausted
repairingAuto-repair in progress

Notifications

The watchdog sends notifications for:
  • Crash detected — Gateway process exited unexpectedly
  • Crash loop — 3+ crashes in 5-minute window
  • Auto-repair started — Attempting to restart the gateway
  • Auto-repair succeeded — Gateway is healthy again
  • Auto-repair failed — Could not recover, needs manual intervention

Telegram Format

Discord Format

Embedded message with color coding:
  • 🔴 Red: crashes, failures
  • 🟡 Yellow: repairing, degraded
  • 🟢 Green: recovered, healthy

Test Script

Test the watchdog by injecting an invalid config:
The watchdog should detect the gateway failure and auto-repair within 2 health check cycles.