Skip to content

Business operating system for Claude Code — 57 skills, 21 agents, smart daemon. Unified inbox (WhatsApp/Email/Slack/Telegram), autonomous PR merge, full-AWS monitoring, revenue (Stripe+RevenueCat), e-commerce (Shopify), marketing (Klaviyo/Meta/GA4), voice (Bland/ElevenLabs), APM (Datadog/NewRelic/OTEL), YOLO mode.

feat(whatsapp): keepalive watchdog so phone-sends always sync (#424)

Aurora Capital5bcd8797898c
diff --git a/claude-ops/bin/wa-bridge-keepalive.sh b/claude-ops/bin/wa-bridge-keepalive.sh
new file mode 100755
index 00000000..bd7cc85c
--- /dev/null
+++ b/claude-ops/bin/wa-bridge-keepalive.sh
@@ -0,0 +1,35 @@
+#!/usr/bin/env bash
+# wa-bridge-keepalive.sh — keep the whatsmeow whatsapp-bridge ONLINE so phone-originated
+# own-sends always sync. systemd Restart=always catches CRASHES; this catches HANGS
+# (process alive, websocket dead) which would silently drop every incoming message —
+# including your own phone sends, which whatsmeow CANNOT re-fetch once missed.
+#
+# Liveness = a real HTTP probe of the bridge REST port. NOT `ss | grep :8080` — ss renders
+# port 8080 as the service name "webcache", so that grep never matches and would false-restart
+# a perfectly healthy bridge (documented ops-inbox footgun). curl treats HTTP 404 as success
+# (connection worked); only connection-refused / timeout counts as down.
+set -uo pipefail
+
+# single-instance + 50s throttle (timer fires every 60s; never stack)
+if [ -r "$HOME/.claude/scripts/lib/once.sh" ]; then
+ # shellcheck disable=SC1091
+ source "$HOME/.claude/scripts/lib/once.sh"
+ claude_once wa-bridge-keepalive 50 || exit 0
+fi
+
+PROBE="${WA_BRIDGE_PROBE:-http://127.0.0.1:8080/}"
+UNIT="whatsapp-bridge.service"
+
+probe() { curl -s -o /dev/null -m 4 "$PROBE" 2>/dev/null; }
+
+# two probes 3s apart — tolerate a single transient blip
+if probe; then exit 0; fi
+sleep 3
+if probe; then exit 0; fi
+
+# Don't fight systemd if it's already mid-(re)start (crash path owned by Restart=always)
+state=$(systemctl --user show "$UNIT" -p ActiveState --value 2>/dev/null || echo unknown)
+if [ "$state" = "activating" ]; then exit 0; fi
+
+logger -t wa-bridge-keepalive "bridge unresponsive on $PROBE (state=$state) — restarting $UNIT"
+systemctl --user restart "$UNIT"
diff --git a/claude-ops/scripts/install-whatsapp-bridge-linux.sh b/claude-ops/scripts/install-whatsapp-bridge-linux.sh
index 4209d0c0..ceff4f84 100755
--- a/claude-ops/scripts/install-whatsapp-bridge-linux.sh
+++ b/claude-ops/scripts/install-whatsapp-bridge-linux.sh
@@ -113,6 +113,11 @@ mkdir -p "$HOME/bin"
cp "$SCRIPT_DIR/../bin/wa-inbox-fresh.sh" "$HOME/bin/wa-inbox-fresh.sh"
chmod +x "$HOME/bin/wa-inbox-fresh.sh"
+# ─── Ship wa-bridge-keepalive.sh (hang-detection so phone-sends always sync) ──
+echo "▶ Installing wa-bridge-keepalive.sh → ~/bin (uptime watchdog)"
+cp "$SCRIPT_DIR/../bin/wa-bridge-keepalive.sh" "$HOME/bin/wa-bridge-keepalive.sh"
+chmod +x "$HOME/bin/wa-bridge-keepalive.sh"
+
# ─── Bump Go deps + build ────────────────────────────────────────────────────
if [ "$SKIP_BUILD" -ne 1 ]; then
echo "▶ Bumping Go deps + building bridge"
@@ -154,6 +159,12 @@ if [ "$WITH_BACKFILL_TIMER" -eq 1 ]; then
cp "$WA_ASSETS/systemd/whatsapp-backfill.timer" "$SYSTEMD_DIR/"
fi
+# Keepalive watchdog: Restart=always catches crashes; this catches HANGS (socket
+# dead, process alive) which would silently drop phone-originated own-sends that
+# whatsmeow can never re-fetch. Always installed.
+cp "$WA_ASSETS/systemd/whatsapp-bridge-keepalive.service" "$SYSTEMD_DIR/"
+cp "$WA_ASSETS/systemd/whatsapp-bridge-keepalive.timer" "$SYSTEMD_DIR/"
+
if [ "$WITH_TRANSCRIBE_TIMER" -eq 1 ]; then
sed "s|__INSTALL_DIR__|$INSTALL_DIR|g" \
"$WA_ASSETS/systemd/whatsapp-transcribe.service" \
@@ -184,6 +195,7 @@ echo "▶ Reloading systemd + starting services"
loginctl enable-linger "$USER" 2>/dev/null || true # survive logout
systemctl --user daemon-reload
systemctl --user enable --now whatsapp-bridge.service
+systemctl --user enable --now whatsapp-bridge-keepalive.timer
if [ "$WITH_BACKFILL_TIMER" -eq 1 ]; then
systemctl --user enable --now whatsapp-backfill.timer
fi
diff --git a/claude-ops/scripts/whatsapp/systemd/whatsapp-bridge-keepalive.service b/claude-ops/scripts/whatsapp/systemd/whatsapp-bridge-keepalive.service
new file mode 100644
index 00000000..3e186035
--- /dev/null
+++ b/claude-ops/scripts/whatsapp/systemd/whatsapp-bridge-keepalive.service
@@ -0,0 +1,7 @@
+[Unit]
+Description=WhatsApp bridge keepalive (hang-detection so phone-sends always sync)
+After=whatsapp-bridge.service
+
+[Service]
+Type=oneshot
+ExecStart=%h/bin/wa-bridge-keepalive.sh
diff --git a/claude-ops/scripts/whatsapp/systemd/whatsapp-bridge-keepalive.timer b/claude-ops/scripts/whatsapp/systemd/whatsapp-bridge-keepalive.timer
new file mode 100644
index 00000000..bbca2d10
--- /dev/null
+++ b/claude-ops/scripts/whatsapp/systemd/whatsapp-bridge-keepalive.timer
@@ -0,0 +1,10 @@
+[Unit]
+Description=Run whatsapp-bridge keepalive every 60s
+
+[Timer]
+OnBootSec=60
+OnUnitActiveSec=60
+AccuracySec=10s
+
+[Install]
+WantedBy=timers.target