#!/bin/sh # Oikos API health watchdog — if the oikos API restarts while dsh web holds a # stale MCP session, every tool call fails with "session not found" until dsh # web itself restarts. This monitor detects the transition and triggers a # launchd kickstart so the connection recovers automatically. # # Runs every 30s via LaunchAgent network.hubris.oikos-api-watchdog. set -e API_URL="${API_URL:-http://localhost:8090/healthz}" MARKER="${MARKER:-/tmp/.oikos-api-down}" if curl -sf -o /dev/null --max-time 3 "$API_URL"; then if [ -f "$MARKER" ]; then rm -f "$MARKER" echo "oikos API recovered — restarting dsh web" launchctl kickstart -k "gui/$(id -u)/network.hubris.dsh-web" 2>/dev/null || true fi else touch "$MARKER" fi