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.

fix(whatsapp): supervise the bridge LaunchAgent and pin the macOS DNS resolver (#835)

Aurora Capital2748246ee278
diff --git a/claude-ops/assets/launchagents/com.claude-ops.whatsapp-bridge.plist b/claude-ops/assets/launchagents/com.claude-ops.whatsapp-bridge.plist
index 8fd173de..a851f9c4 100644
--- a/claude-ops/assets/launchagents/com.claude-ops.whatsapp-bridge.plist
+++ b/claude-ops/assets/launchagents/com.claude-ops.whatsapp-bridge.plist
@@ -5,9 +5,20 @@
<key>Label</key>
<string>com.__USER__.whatsapp-bridge</string>
+ <!--
+ Launch the supervised wrapper, NEVER the bare bridge binary.
+
+ run-bridge.sh strips any `--pair` argument before exec'ing the bridge. A
+ supervisor pointed straight at the binary will pair itself unattended
+ after a LoggedOut event, and repeated unattended pairing is what gets a
+ WhatsApp account banned. Do not "simplify" this back to the binary path.
+
+ Bridge dirs that predate run-bridge.sh must add it before installing this
+ LaunchAgent; see skills/setup/channels/whatsapp.md.
+ -->
<key>ProgramArguments</key>
<array>
- <string>__BRIDGE_BINARY_PATH__</string>
+ <string>__BRIDGE_WORKING_DIR__/run-bridge.sh</string>
</array>
<key>WorkingDirectory</key>
@@ -15,12 +26,19 @@
<key>KeepAlive</key>
<dict>
+ <key>Crashed</key>
+ <true/>
<key>SuccessfulExit</key>
<false/>
</dict>
+ <!--
+ 300s, not 60s. A logged-out bridge exits immediately, so a short throttle
+ turns launchd into a tight restart loop against WhatsApp's device-link
+ endpoint.
+ -->
<key>ThrottleInterval</key>
- <integer>60</integer>
+ <integer>300</integer>
<key>RunAtLoad</key>
<true/>
@@ -37,6 +55,15 @@
<string>/usr/local/bin:/opt/homebrew/bin:/usr/bin:/bin</string>
<key>HOME</key>
<string>__HOME__</string>
+ <!--
+ REQUIRED on macOS. With the cgo resolver the whatsmeow websocket to
+ web.whatsapp.com dies with "failed to read frame header: EOF" plus a
+ keepalive timeout within minutes. That silently breaks both pairing
+ (the phone shows "Couldn't link device" even with a correct code) and
+ steady-state connection. The bridge's own --help documents this.
+ -->
+ <key>GODEBUG</key>
+ <string>netdns=go</string>
</dict>
</dict>
</plist>
diff --git a/claude-ops/bin/ops-post-update-migrate b/claude-ops/bin/ops-post-update-migrate
index 4086e359..90358cc2 100755
--- a/claude-ops/bin/ops-post-update-migrate
+++ b/claude-ops/bin/ops-post-update-migrate
@@ -19,8 +19,13 @@ PLUGIN_JSON="$PLUGIN_ROOT/.claude-plugin/plugin.json"
VERSION=$(python3 -c "import json,sys; print(json.load(open('$PLUGIN_JSON'))['version'])" 2>/dev/null || echo "unknown")
SENTINEL_DIR="$DATA_DIR/.migrated"
SENTINEL="$SENTINEL_DIR/v${VERSION}"
+# Set by a migration (inside the backgrounded subshell, so a file not a variable)
+# when it skipped work that a later session could still complete. Suppresses the
+# sentinel stamp so the next SessionStart retries instead of skipping forever.
+SENTINEL_DEFER_FLAG="$SENTINEL_DIR/.defer-v${VERSION}"
mkdir -p "$SENTINEL_DIR" 2>/dev/null || true
+rm -f "$SENTINEL_DEFER_FLAG" 2>/dev/null || true
LOG="$DATA_DIR/post-update-migrate.log"
mkdir -p "$DATA_DIR" 2>/dev/null || true
@@ -178,15 +183,31 @@ run_migrations() {
if [[ -f "$plist_src" ]] && [[ ! -f "$plist_dst" || "$plist_src" -nt "$plist_dst" ]]; then
mkdir -p "$HOME/Library/LaunchAgents" 2>/dev/null || true
local bridge_dir="${WHATSAPP_BRIDGE_HOME:-$HOME/.local/share/whatsapp-mcp/whatsapp-bridge}"
- sed -e "s#__BRIDGE_BINARY_PATH__#$bridge_dir/whatsapp-bridge#g" \
- -e "s#__BRIDGE_WORKING_DIR__#$bridge_dir#g" \
- -e "s#__HOME__#$HOME#g" \
- -e "s#__USER__#$USER#g" \
- "$plist_src" > "$plist_dst" 2>/dev/null && {
- launchctl unload "$plist_dst" 2>/dev/null || true
- launchctl load "$plist_dst" 2>/dev/null || true
- log " ok: whatsapp-bridge LaunchAgent refreshed"
- }
+ # The template supervises via run-bridge.sh, which strips --pair so a
+ # logged-out bridge can never re-pair itself unattended (that is what gets
+ # a WhatsApp account banned). If the wrapper is missing, installing the
+ # LaunchAgent would give launchd nothing safe to exec, so skip instead:
+ # better no autostart than an unsupervised pair loop.
+ #
+ # The skip must NOT be sticky. The per-version sentinel is stamped even on
+ # partial failure, and SessionStart exits early once it exists, so a bridge
+ # dir that gains run-bridge.sh later would otherwise never get its
+ # LaunchAgent for this version. Defer the sentinel so the next session
+ # retries.
+ if [[ ! -x "$bridge_dir/run-bridge.sh" ]]; then
+ log " skip: whatsapp-bridge LaunchAgent (missing $bridge_dir/run-bridge.sh) — will retry next session"
+ : > "$SENTINEL_DEFER_FLAG"
+ else
+ sed -e "s#__BRIDGE_BINARY_PATH__#$bridge_dir/whatsapp-bridge#g" \
+ -e "s#__BRIDGE_WORKING_DIR__#$bridge_dir#g" \
+ -e "s#__HOME__#$HOME#g" \
+ -e "s#__USER__#$USER#g" \
+ "$plist_src" > "$plist_dst" 2>/dev/null && {
+ launchctl unload "$plist_dst" 2>/dev/null || true
+ launchctl load "$plist_dst" 2>/dev/null || true
+ log " ok: whatsapp-bridge LaunchAgent refreshed"
+ }
+ fi
fi
fi
@@ -220,5 +241,15 @@ wait "$MIGRATE_PID" 2>/dev/null || true
# Stamp sentinel even on partial failure — individual migrations log their own state.
# Re-run forced by deleting the sentinel or bumping plugin.json version.
+#
+# Exception: a migration that deliberately skipped recoverable work sets the defer
+# flag. Stamping then would make the skip permanent for this version, since the
+# early-exit above never re-enters run_migrations. Leave the sentinel unwritten so
+# the next SessionStart retries.
+if [[ -f "$SENTINEL_DEFER_FLAG" ]]; then
+ rm -f "$SENTINEL_DEFER_FLAG" 2>/dev/null || true
+ log "post-update-migrate DEFERRED sentinel version=$VERSION (a migration will retry next session)"
+ exit 0
+fi
touch "$SENTINEL"
exit 0
diff --git a/claude-ops/tests/run-all.sh b/claude-ops/tests/run-all.sh
index 60d9c368..212f30bc 100755
--- a/claude-ops/tests/run-all.sh
+++ b/claude-ops/tests/run-all.sh
@@ -45,6 +45,7 @@ run_suite "$TESTS_DIR/test-account-recovery.sh"
run_suite "$TESTS_DIR/test-claude-invoke.sh"
run_suite "$TESTS_DIR/test-staged-enrollment.sh"
run_suite "$TESTS_DIR/test-coordination-provisioning.sh"
+run_suite "$TESTS_DIR/test-post-update-migrate-sentinel.sh"
run_suite "$TESTS_DIR/test-template.sh"
run_suite "$TESTS_DIR/test-claude-md.sh"
run_suite "$TESTS_DIR/test-no-secrets.sh"
diff --git a/claude-ops/tests/test-post-update-migrate-sentinel.sh b/claude-ops/tests/test-post-update-migrate-sentinel.sh
new file mode 100755
index 00000000..ef16aea6
--- /dev/null
+++ b/claude-ops/tests/test-post-update-migrate-sentinel.sh
@@ -0,0 +1,100 @@
+#!/usr/bin/env bash
+# Regression guard for the ops-post-update-migrate sentinel.
+#
+# The per-version sentinel ($DATA_DIR/.migrated/v<VERSION>) is stamped even when
+# a migration only partially succeeds, and SessionStart exits early once it
+# exists. A migration that SKIPS recoverable work therefore makes that skip
+# permanent for the whole version unless it defers the stamp.
+#
+# Concretely: the whatsapp-bridge LaunchAgent install is skipped when
+# run-bridge.sh is absent (installing an unsupervised bare-binary agent is what
+# gets a WhatsApp account banned). Without the defer flag, a bridge dir that
+# gains run-bridge.sh later would never get its LaunchAgent.
+#
+# Verified to FAIL against the pre-fix script before being trusted.
+set -uo pipefail
+
+TESTS_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
+SCRIPT="${1:-$TESTS_DIR/../bin/ops-post-update-migrate}"
+
+PASS=0
+FAIL=0
+
+ck() {
+ if [[ "$2" == "$3" ]]; then
+ echo " PASS: $1"
+ PASS=$((PASS + 1))
+ else
+ echo " FAIL: $1 (want '$3', got '$2')"
+ FAIL=$((FAIL + 1))
+ fi
+}
+
+setup() {
+ ROOT=$(mktemp -d)
+ export HOME="$ROOT/home"
+ mkdir -p "$HOME/Library/LaunchAgents"
+ PLUGIN_ROOT="$ROOT/plugin"
+ mkdir -p "$PLUGIN_ROOT/.claude-plugin" "$PLUGIN_ROOT/assets/launchagents"
+ echo '{"version":"9.9.9-test"}' >"$PLUGIN_ROOT/.claude-plugin/plugin.json"
+ cat >"$PLUGIN_ROOT/assets/launchagents/com.claude-ops.whatsapp-bridge.plist" <<'PL'
+<?xml version="1.0" encoding="UTF-8"?>
+<plist version="1.0"><dict>
+<key>Label</key><string>com.__USER__.whatsapp-bridge</string>
+<key>ProgramArguments</key><array><string>__BRIDGE_WORKING_DIR__/run-bridge.sh</string></array>
+</dict></plist>
+PL
+ export CLAUDE_PLUGIN_DATA_DIR="$ROOT/data"
+ mkdir -p "$CLAUDE_PLUGIN_DATA_DIR"
+ export WHATSAPP_BRIDGE_HOME="$ROOT/bridge"
+ mkdir -p "$WHATSAPP_BRIDGE_HOME/logs"
+ SENTINEL="$CLAUDE_PLUGIN_DATA_DIR/.migrated/v9.9.9-test"
+ PLIST="$HOME/Library/LaunchAgents/com.${USER}.whatsapp-bridge.plist"
+}
+
+make_wrapper() {
+ printf '#!/bin/bash\n' >"$WHATSAPP_BRIDGE_HOME/run-bridge.sh"
+ chmod +x "$WHATSAPP_BRIDGE_HOME/run-bridge.sh"
+}
+
+run() { CLAUDE_PLUGIN_ROOT="$PLUGIN_ROOT" bash "$SCRIPT" >/dev/null 2>&1 || true; }
+
+if [[ "$(uname -s)" != "Darwin" ]]; then
+ echo "SKIP: LaunchAgent migration is macOS-only"
+ exit 0
+fi
+
+echo "=== run-bridge.sh missing: skip must not be sticky ==="
+setup
+run
+ck "plist not installed" "$([[ -f $PLIST ]] && echo yes || echo no)" "no"
+ck "sentinel not stamped" "$([[ -f $SENTINEL ]] && echo yes || echo no)" "no"
+
+echo
+echo "=== wrapper appears later: next run installs ==="
+make_wrapper
+run
+ck "plist installed on retry" "$([[ -f $PLIST ]] && echo yes || echo no)" "yes"
+ck "sentinel stamped on retry" "$([[ -f $SENTINEL ]] && echo yes || echo no)" "yes"
+if [[ -f "$PLIST" ]]; then
+ if grep -q "run-bridge.sh" "$PLIST"; then
+ echo " PASS: plist supervises run-bridge.sh"
+ PASS=$((PASS + 1))
+ else
+ echo " FAIL: plist does not reference run-bridge.sh"
+ FAIL=$((FAIL + 1))
+ fi
+fi
+
+echo
+echo "=== wrapper present from the start ==="
+setup
+make_wrapper
+run
+ck "plist installed" "$([[ -f $PLIST ]] && echo yes || echo no)" "yes"
+ck "sentinel stamped" "$([[ -f $SENTINEL ]] && echo yes || echo no)" "yes"
+
+echo
+echo " Passed: $PASS"
+echo " Failed: $FAIL"
+[[ $FAIL -eq 0 ]]