Anurag commited on
Commit
66b3f0d
·
unverified ·
2 Parent(s): 08da72a58d9010

Merge pull request #200 from anurag008w/codex/investigate-key-rotator-issue

Browse files

Improve key-rotator hostname handling and sync-layer isolation; avoid inheriting NODE_OPTIONS and persisting provider secrets

Files changed (1) hide show
  1. start.sh +34 -16
start.sh CHANGED
@@ -63,6 +63,33 @@ PYBUNDLE
63
 
64
  load_env_bundle
65
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66
  # Normalize core env values so accidental surrounding spaces in HF Variables
67
  # do not block updates or cause stale comparisons/merges.
68
  LLM_MODEL="$(trim_var "${LLM_MODEL:-}")"
@@ -1622,7 +1649,7 @@ start_jupyter_once() {
1622
 
1623
  # Use explicit Python to avoid PATH issues; set memory-friendly limits
1624
  export PYTHONPATH=""
1625
- python3 -m jupyterlab \
1626
  --ip 127.0.0.1 \
1627
  --port "$JUPYTER_PORT" \
1628
  --no-browser \
@@ -2046,7 +2073,7 @@ hc_run_startup_command() {
2046
 
2047
  echo "[startup:${source_label}] $command_text"
2048
  set +e
2049
- HUGGINGCLAW_CAPTURE_DISABLE=1 bash -lc "$command_text"
2050
  local rc=$?
2051
  set -e
2052
  if [ "$rc" -eq 0 ]; then
@@ -2078,7 +2105,7 @@ hc_run_startup_script() {
2078
 
2079
  echo "[startup:${source_label}] running script (${script_file})"
2080
  set +e
2081
- bash "$script_file"
2082
  local rc=$?
2083
  set -e
2084
  rm -f "$script_file"
@@ -2200,7 +2227,7 @@ if [ -n "${HUGGINGCLAW_PIP_PACKAGES:-}" ]; then
2200
  echo "Installing Python packages from HUGGINGCLAW_PIP_PACKAGES..."
2201
  _HC_PIP_NORM=$(printf '%s' "$HUGGINGCLAW_PIP_PACKAGES" | tr ',\n\r' ' ' | tr -s ' ')
2202
  read -r -a HC_PIP_PACKAGES <<< "$_HC_PIP_NORM"
2203
- if python3 -m pip install --user --break-system-packages "${HC_PIP_PACKAGES[@]}"; then
2204
  echo "HUGGINGCLAW_PIP_PACKAGES install complete."
2205
  else
2206
  HC_STARTUP_FAILURES=$((HC_STARTUP_FAILURES + 1))
@@ -2211,7 +2238,7 @@ if [ -n "${HUGGINGCLAW_NPM_PACKAGES:-}" ]; then
2211
  echo "Installing global npm packages from HUGGINGCLAW_NPM_PACKAGES..."
2212
  _HC_NPM_NORM=$(printf '%s' "$HUGGINGCLAW_NPM_PACKAGES" | tr ',\n\r' ' ' | tr -s ' ')
2213
  read -r -a HC_NPM_PACKAGES <<< "$_HC_NPM_NORM"
2214
- if npm install -g "${HC_NPM_PACKAGES[@]}"; then
2215
  echo "HUGGINGCLAW_NPM_PACKAGES install complete."
2216
  else
2217
  HC_STARTUP_FAILURES=$((HC_STARTUP_FAILURES + 1))
@@ -2222,7 +2249,7 @@ if [ -n "${HUGGINGCLAW_OPENCLAW_PLUGINS:-}" ]; then
2222
  echo "Installing OpenClaw plugins from HUGGINGCLAW_OPENCLAW_PLUGINS..."
2223
  _HC_PLUGINS_NORM=$(printf '%s' "$HUGGINGCLAW_OPENCLAW_PLUGINS" | tr ',\n\r' ' ' | tr -s ' ')
2224
  read -r -a HC_OPENCLAW_PLUGINS <<< "$_HC_PLUGINS_NORM"
2225
- if openclaw plugins install "${HC_OPENCLAW_PLUGINS[@]}"; then
2226
  echo "HUGGINGCLAW_OPENCLAW_PLUGINS install complete."
2227
  else
2228
  HC_STARTUP_FAILURES=$((HC_STARTUP_FAILURES + 1))
@@ -2282,16 +2309,7 @@ hc_clean_node_options_for_openclaw_maintenance() {
2282
  # traffic. Keep it isolated from HuggingClaw's gateway preloads because those
2283
  # hooks patch fetch/undici globally and can redirect package downloads through
2284
  # Cloudflare or emit rotator startup logs into installer output.
2285
- local cleaned=" ${NODE_OPTIONS:-} "
2286
- local preload pattern
2287
- for preload in "/opt/cloudflare-proxy.js" "$IFRAME_FIX_PRELOAD" "$KEY_ROTATOR_PRELOAD"; do
2288
- [ -n "$preload" ] || continue
2289
- pattern="--require ${preload} "; cleaned="${cleaned//$pattern/ }"
2290
- pattern="--require=${preload} "; cleaned="${cleaned//$pattern/ }"
2291
- pattern="-r ${preload} "; cleaned="${cleaned//$pattern/ }"
2292
- done
2293
- # Normalize whitespace after removing known preload pairs.
2294
- printf '%s' "$cleaned" | tr -s ' ' | sed 's/^ //;s/ $//'
2295
  }
2296
 
2297
  hc_openclaw_maintenance() {
 
63
 
64
  load_env_bundle
65
 
66
+ # Run package-manager and OpenClaw maintenance commands without HuggingClaw's
67
+ # gateway preloads. NODE_OPTIONS is inherited by child Node/npm processes; if the
68
+ # rotator preload stays enabled there, npm registry downloads and plugin
69
+ # dependency installs can be instrumented, spam logs, or inherit provider auth in
70
+ # surprising ways. User installs are maintenance traffic, not LLM gateway calls.
71
+ hc_clean_node_options_value() {
72
+ local cleaned=" ${1:-} "
73
+ local preload pattern
74
+ for preload in "/opt/cloudflare-proxy.js" "${IFRAME_FIX_PRELOAD:-}" "${KEY_ROTATOR_PRELOAD:-}"; do
75
+ [ -n "$preload" ] || continue
76
+ pattern="--require ${preload} "; cleaned="${cleaned//$pattern/ }"
77
+ pattern="--require=${preload} "; cleaned="${cleaned//$pattern/ }"
78
+ pattern="-r ${preload} "; cleaned="${cleaned//$pattern/ }"
79
+ done
80
+ printf '%s' "$cleaned" | tr -s ' ' | sed 's/^ //;s/ $//'
81
+ }
82
+
83
+ hc_env_without_gateway_preloads() {
84
+ local cleaned_node_options
85
+ cleaned_node_options="$(hc_clean_node_options_value "${NODE_OPTIONS:-}")"
86
+ if [ -n "$cleaned_node_options" ]; then
87
+ env NODE_OPTIONS="$cleaned_node_options" "$@"
88
+ else
89
+ env -u NODE_OPTIONS "$@"
90
+ fi
91
+ }
92
+
93
  # Normalize core env values so accidental surrounding spaces in HF Variables
94
  # do not block updates or cause stale comparisons/merges.
95
  LLM_MODEL="$(trim_var "${LLM_MODEL:-}")"
 
1649
 
1650
  # Use explicit Python to avoid PATH issues; set memory-friendly limits
1651
  export PYTHONPATH=""
1652
+ hc_env_without_gateway_preloads python3 -m jupyterlab \
1653
  --ip 127.0.0.1 \
1654
  --port "$JUPYTER_PORT" \
1655
  --no-browser \
 
2073
 
2074
  echo "[startup:${source_label}] $command_text"
2075
  set +e
2076
+ HUGGINGCLAW_CAPTURE_DISABLE=1 hc_env_without_gateway_preloads bash -lc "$command_text"
2077
  local rc=$?
2078
  set -e
2079
  if [ "$rc" -eq 0 ]; then
 
2105
 
2106
  echo "[startup:${source_label}] running script (${script_file})"
2107
  set +e
2108
+ hc_env_without_gateway_preloads bash "$script_file"
2109
  local rc=$?
2110
  set -e
2111
  rm -f "$script_file"
 
2227
  echo "Installing Python packages from HUGGINGCLAW_PIP_PACKAGES..."
2228
  _HC_PIP_NORM=$(printf '%s' "$HUGGINGCLAW_PIP_PACKAGES" | tr ',\n\r' ' ' | tr -s ' ')
2229
  read -r -a HC_PIP_PACKAGES <<< "$_HC_PIP_NORM"
2230
+ if hc_env_without_gateway_preloads python3 -m pip install --user --break-system-packages "${HC_PIP_PACKAGES[@]}"; then
2231
  echo "HUGGINGCLAW_PIP_PACKAGES install complete."
2232
  else
2233
  HC_STARTUP_FAILURES=$((HC_STARTUP_FAILURES + 1))
 
2238
  echo "Installing global npm packages from HUGGINGCLAW_NPM_PACKAGES..."
2239
  _HC_NPM_NORM=$(printf '%s' "$HUGGINGCLAW_NPM_PACKAGES" | tr ',\n\r' ' ' | tr -s ' ')
2240
  read -r -a HC_NPM_PACKAGES <<< "$_HC_NPM_NORM"
2241
+ if hc_env_without_gateway_preloads npm install -g "${HC_NPM_PACKAGES[@]}"; then
2242
  echo "HUGGINGCLAW_NPM_PACKAGES install complete."
2243
  else
2244
  HC_STARTUP_FAILURES=$((HC_STARTUP_FAILURES + 1))
 
2249
  echo "Installing OpenClaw plugins from HUGGINGCLAW_OPENCLAW_PLUGINS..."
2250
  _HC_PLUGINS_NORM=$(printf '%s' "$HUGGINGCLAW_OPENCLAW_PLUGINS" | tr ',\n\r' ' ' | tr -s ' ')
2251
  read -r -a HC_OPENCLAW_PLUGINS <<< "$_HC_PLUGINS_NORM"
2252
+ if hc_env_without_gateway_preloads openclaw plugins install "${HC_OPENCLAW_PLUGINS[@]}"; then
2253
  echo "HUGGINGCLAW_OPENCLAW_PLUGINS install complete."
2254
  else
2255
  HC_STARTUP_FAILURES=$((HC_STARTUP_FAILURES + 1))
 
2309
  # traffic. Keep it isolated from HuggingClaw's gateway preloads because those
2310
  # hooks patch fetch/undici globally and can redirect package downloads through
2311
  # Cloudflare or emit rotator startup logs into installer output.
2312
+ hc_clean_node_options_value "${NODE_OPTIONS:-}"
 
 
 
 
 
 
 
 
 
2313
  }
2314
 
2315
  hc_openclaw_maintenance() {