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.
Shell agent-teamsai-agentai-automationanthropicautonomous-agentawsbusiness-operationsclaudeclaude-codeclaude-code-plugindevopsecommerceinbox-zeroklaviyomarketingmcpmorning-briefingpr-automationshopifyterminal
fix(whatsapp): canonicalize 180s restart-floor in wa-inbox-fresh + wa-bridge-keepalive (survive reinstall) (#454)
Aurora Capital1cee118dc4d4
diff --git a/claude-ops/bin/wa-bridge-keepalive.sh b/claude-ops/bin/wa-bridge-keepalive.shindex bd7cc85c..a87bc7da 100755--- a/claude-ops/bin/wa-bridge-keepalive.sh+++ b/claude-ops/bin/wa-bridge-keepalive.sh@@ -31,5 +31,21 @@ if probe; then exit 0; fistate=$(systemctl --user show "$UNIT" -p ActiveState --value 2>/dev/null || echo unknown)if [ "$state" = "activating" ]; then exit 0; fi+# Shared cross-caller restart floor — same stamp file claude_once uses for the key+# "whatsapp-bridge-restart" (wa-inbox-fresh.sh writes it). Read/write the stamp+# DIRECTLY here: a 2nd claude_once call would clobber the self-throttle's EXIT trap+# (bash allows one EXIT trap) and orphan wa-bridge-keepalive.lock, self-disabling the+# watchdog until the 60-min stale-reclaim. A stamp-only floor auto-expires at 180s and+# can never self-block, which is what keepalive needs. One restart / 180s across this+# script + wa-inbox-fresh.sh + whatsapp-bridge-up.sh.+FLOOR_STAMP="$HOME/.claude/.once.whatsapp-bridge-restart.last"+if [ -f "$FLOOR_STAMP" ]; then+ last=$(cat "$FLOOR_STAMP" 2>/dev/null || echo 0)+ if [ $(( $(date +%s) - ${last:-0} )) -lt 180 ]; then+ logger -t wa-bridge-keepalive 'restart floor active (<180s) — skip'+ exit 0+ fi+filogger -t wa-bridge-keepalive "bridge unresponsive on $PROBE (state=$state) — restarting $UNIT"systemctl --user restart "$UNIT"+date +%s > "$FLOOR_STAMP" 2>/dev/nulldiff --git a/claude-ops/bin/wa-inbox-fresh.sh b/claude-ops/bin/wa-inbox-fresh.shindex 3a54ee81..4fc6f8f6 100755--- a/claude-ops/bin/wa-inbox-fresh.sh+++ b/claude-ops/bin/wa-inbox-fresh.sh@@ -32,18 +32,45 @@ log() { printf '%s\n' "$*"; }# (bridge still starting up) triggered a restart loop. The fix: fail-fast# probe × 2 with a 1s gap; only then restart; then wait up to 20s for it to# come back up before declaring dead.-alive() { curl -s -o /dev/null -m 4 "$BRIDGE/" >/dev/null 2>&1; }+alive() { curl -s -o /dev/null -m 10 "$BRIDGE/" >/dev/null 2>&1; }probe_dead() { ! alive && { sleep 1; ! alive; }; } # two consecutive failures = truly dead+bridge_restarted=0if probe_dead; then- log "wa-fresh: bridge :8080 not responding (2 consecutive probes failed) — restarting…"- systemctl --user restart whatsapp-bridge.service 2>/dev/null+ # Startup-grace gate: if the bridge (re)started <120s ago it is almost certainly+ # mid-reconnect (opening the SQLite store + WhatsApp websocket), and a probe that+ # fails here would re-trigger a restart → reconnect → probe-fail loop. Skip.+ started=$(systemctl --user show whatsapp-bridge.service -p ActiveEnterTimestampMonotonic --value 2>/dev/null)+ now=$(awk '{print int($1*1000000)}' /proc/uptime)+ if [ -n "$started" ] && [ "$started" -gt 0 ] && [ $(( now - started )) -lt 120000000 ]; then+ log "wa-fresh: bridge started <120s ago — skip restart (reconnect in progress)"+ else+ # Shared cross-caller restart floor: the SAME stamp every other restart caller+ # uses (wa-bridge-keepalive.sh, whatsapp-bridge-up.sh). One restart / 180s max,+ # no matter how many parallel agents invoke this script. claude_once is a one-shot+ # guard (not a recurring loop), allowed under the cost rule.+ do_restart=1+ if [ -r "$HOME/.claude/scripts/lib/once.sh" ]; then+ # shellcheck disable=SC1091+ . "$HOME/.claude/scripts/lib/once.sh"+ claude_once whatsapp-bridge-restart 180 || { log "wa-fresh: another caller restarted bridge <180s ago — skip"; do_restart=0; }+ fi+ if [ "$do_restart" = 1 ]; then+ bridge_restarted=1+ log "wa-fresh: bridge :8080 not responding (2 consecutive probes failed) — restarting…"+ systemctl --user restart whatsapp-bridge.service 2>/dev/null+ fi+ fi# Wait up to 20 s for the bridge to come back (it needs a few seconds to# open the SQLite store and establish the WhatsApp websocket).for i in $(seq 1 10); do sleep 2; alive && break; donefiif ! alive; then- log "wa-fresh: ERROR bridge still down after restart — store is STALE, do not trust it"+ if [ "$bridge_restarted" = 1 ]; then+ log "wa-fresh: ERROR bridge still down after restart — store is STALE, do not trust it"+ else+ log "wa-fresh: ERROR bridge still down — store is STALE, do not trust it"+ fiexit 2fi