Anurag commited on
Commit
e66409d
·
unverified ·
2 Parent(s): 4b593ccce1687b

Merge pull request #175 from anurag008w/fix/whatsapp-runtime-ok-false-positive

Browse files
Files changed (2) hide show
  1. start.sh +40 -13
  2. wa-guardian.js +9 -2
start.sh CHANGED
@@ -1630,9 +1630,11 @@ _hc_allow_openclaw_plugins() {
1630
 
1631
  local plugins_json
1632
  plugins_json=$(printf '%s\n' "${plugins[@]}" | jq -R 'select(length > 0)' | jq -s 'unique') || return 0
1633
- jq --argjson plugins "$plugins_json" \
 
1634
  '.plugins.allow = (((.plugins.allow // []) + $plugins) | unique)' \
1635
- "$config" > "$config.tmp" && mv "$config.tmp" "$config"
 
1636
  }
1637
  _hc_has_arg() {
1638
  local needle="$1"
@@ -1986,7 +1988,7 @@ sync_installed_plugins_into_allow() {
1986
  return 0
1987
  }
1988
 
1989
- echo "$patched" > "$config.tmp" && mv "$config.tmp" "$config"
1990
  }
1991
 
1992
  hc_finish_startup_commands() {
@@ -2106,17 +2108,42 @@ if [ -s "$STARTUP_FILE" ]; then
2106
  echo "Workspace startup script complete."
2107
  fi
2108
  whatsapp_plugin_runtime_ok() {
 
 
 
2109
  local ext_dir="/home/node/.openclaw/extensions/whatsapp"
2110
- if [ -f "$ext_dir/dist/setup-entry.js" ] && [ -f "$ext_dir/dist/index.js" ]; then
2111
- return 0
2112
- fi
2113
 
2114
- # Prefer OpenClaw's own runtime inspector over hard-coded paths; plugin
2115
- # layout can differ across stable/beta releases. If inspect can load the
2116
- # WhatsApp plugin, do not attempt any install.
2117
- if command -v openclaw >/dev/null 2>&1; then
2118
- openclaw plugins inspect whatsapp --runtime --json \
2119
- >/tmp/openclaw-whatsapp-plugin-inspect.log 2>&1 && return 0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2120
  fi
2121
 
2122
  return 1
@@ -2223,7 +2250,7 @@ repair_broken_whatsapp_plugin_entry() {
2223
  echo "Warning: could not patch broken WhatsApp plugin entry; gateway may still reject config." >&2
2224
  return 0
2225
  }
2226
- echo "$patched" > "$config.tmp" && mv "$config.tmp" "$config"
2227
  }
2228
 
2229
  hc_finish_startup_commands
 
1630
 
1631
  local plugins_json
1632
  plugins_json=$(printf '%s\n' "${plugins[@]}" | jq -R 'select(length > 0)' | jq -s 'unique') || return 0
1633
+ local patched
1634
+ patched=$(jq --argjson plugins "$plugins_json" \
1635
  '.plugins.allow = (((.plugins.allow // []) + $plugins) | unique)' \
1636
+ "$config" 2>/dev/null) || { echo "Warning: could not update plugins.allow for $*" >&2; return 0; }
1637
+ write_json_atomic "$config" "$patched" || echo "Warning: could not write plugins.allow update to config." >&2
1638
  }
1639
  _hc_has_arg() {
1640
  local needle="$1"
 
1988
  return 0
1989
  }
1990
 
1991
+ write_json_atomic "$config" "$patched" || echo "Warning: could not write synced plugins.allow to config." >&2
1992
  }
1993
 
1994
  hc_finish_startup_commands() {
 
2108
  echo "Workspace startup script complete."
2109
  fi
2110
  whatsapp_plugin_runtime_ok() {
2111
+ # Check both the bare and scoped install paths that OpenClaw uses across
2112
+ # stable/beta releases. The scoped path (@openclaw/whatsapp) is used when
2113
+ # the plugin is installed via `openclaw plugins install @openclaw/whatsapp`.
2114
  local ext_dir="/home/node/.openclaw/extensions/whatsapp"
2115
+ local ext_dir_scoped="/home/node/.openclaw/extensions/@openclaw/whatsapp"
 
 
2116
 
2117
+ for dir in "$ext_dir" "$ext_dir_scoped"; do
2118
+ if [ -f "$dir/dist/setup-entry.js" ] && [ -f "$dir/dist/index.js" ]; then
2119
+ return 0
2120
+ fi
2121
+ done
2122
+
2123
+ # Use openclaw's own inspector to discover a non-standard install directory,
2124
+ # but ALWAYS verify the actual dist files exist afterwards.
2125
+ #
2126
+ # IMPORTANT: `openclaw plugins inspect whatsapp --runtime --json` exits with
2127
+ # code 0 based purely on the plugin registry record — even when the dist
2128
+ # files (dist/setup-entry.js, dist/index.js) are absent. That is exactly
2129
+ # the condition the gateway.startup_failed error reports. Trusting the exit
2130
+ # code alone (the previous behaviour) caused `install_whatsapp_plugin_runtime`
2131
+ # and `repair_broken_whatsapp_plugin_entry` to both return early thinking the
2132
+ # runtime was healthy, letting the gateway start with `enabled=true` and
2133
+ # missing dist files → crash loop.
2134
+ if command -v openclaw >/dev/null 2>&1 && command -v jq >/dev/null 2>&1; then
2135
+ local inspect_json
2136
+ inspect_json=$(openclaw plugins inspect whatsapp --runtime --json 2>/dev/null) || true
2137
+ if [ -n "$inspect_json" ]; then
2138
+ local root_dir
2139
+ root_dir=$(printf '%s' "$inspect_json" \
2140
+ | jq -r '(.rootDir // .root // .dir // .path // empty)' 2>/dev/null || true)
2141
+ if [ -n "$root_dir" ] && \
2142
+ [ -f "$root_dir/dist/setup-entry.js" ] && \
2143
+ [ -f "$root_dir/dist/index.js" ]; then
2144
+ return 0
2145
+ fi
2146
+ fi
2147
  fi
2148
 
2149
  return 1
 
2250
  echo "Warning: could not patch broken WhatsApp plugin entry; gateway may still reject config." >&2
2251
  return 0
2252
  }
2253
+ write_json_atomic "$config" "$patched" || echo "Warning: could not write patched WhatsApp plugin config; gateway may still reject config." >&2
2254
  }
2255
 
2256
  hc_finish_startup_commands
wa-guardian.js CHANGED
@@ -293,6 +293,13 @@ process.on("unhandledRejection", (reason) => {
293
  writeStatus({ configured: true, connected: false, pairing: false });
294
  console.log("[guardian] WhatsApp Guardian active. Monitoring pairing status...");
295
  _checkInterval = setInterval(checkStatus, CHECK_INTERVAL);
296
- // Allow the process to exit even if this interval is the only active handle.
297
- if (_checkInterval.unref) _checkInterval.unref();
 
 
 
 
 
 
 
298
  setTimeout(checkStatus, 15000);
 
293
  writeStatus({ configured: true, connected: false, pairing: false });
294
  console.log("[guardian] WhatsApp Guardian active. Monitoring pairing status...");
295
  _checkInterval = setInterval(checkStatus, CHECK_INTERVAL);
296
+ // NOTE: Do NOT call _checkInterval.unref() here.
297
+ // With unref(), Node.js exits between interval ticks the moment the
298
+ // short-lived WebSocket from checkStatus() closes in its finally block
299
+ // (typically ~25 s after the first run). The interval never fires again,
300
+ // so the guardian stops monitoring entirely after a single check.
301
+ // start_guardian_once() in start.sh has no monitoring loop that would
302
+ // revive it — it is only called at gateway startup. The comment above
303
+ // ("A previous one-shot exit caused 'works once then stops' behavior")
304
+ // documents exactly this failure; removing unref() is the correct fix.
305
  setTimeout(checkStatus, 15000);