From 9824f7c138d58c9b4e2a40ff6d029a4414c404f7 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 27 May 2026 23:28:33 +0300 Subject: [PATCH] fix: bundle local embeddings runtime in addon --- DOCS.md | 8 +- openclaw_assistant/CHANGELOG.md | 42 ++++++++++ openclaw_assistant/Dockerfile | 8 +- openclaw_assistant/config.yaml | 2 +- openclaw_assistant/oc-gateway | 133 ++++++++++++++++++++++++++++++++ 5 files changed, 187 insertions(+), 6 deletions(-) create mode 100755 openclaw_assistant/oc-gateway diff --git a/DOCS.md b/DOCS.md index e175ba6..259ab32 100644 --- a/DOCS.md +++ b/DOCS.md @@ -113,8 +113,9 @@ Save this token — you'll need it to access the Gateway Web UI and for API inte 1. In the terminal, confirm the gateway is running: ```sh - openclaw gateway status + oc-gateway status ``` + > In this add-on, the gateway is supervised by `run.sh` (not systemd), so `openclaw gateway status` can show misleading service-manager warnings. 2. Click the **Open Gateway Web UI** button on the landing page 3. If prompted for a token, paste the one from Step 2 or go to the Overview tab, paste the token in the 'Gateway Token' field and press Connect. @@ -705,6 +706,7 @@ The add-on image includes these tools, available in the terminal: | Chromium | `chromium` | Headless browser for automation | | SSH | `ssh` | Remote access | | oc-cleanup | `oc-cleanup` | Interactive disk space monitor & cache cleanup helper | +| oc-gateway | `oc-gateway status` / `oc-gateway restart` | Add-on-native gateway status/restart helper (`run.sh` supervised, no systemd) | ### oc-cleanup @@ -806,7 +808,7 @@ Go to **Settings → Add-ons → OpenClaw Assistant → Log** tab. Logs show sta **Symptom**: Browser shows connection refused when opening the Gateway Web UI. **Checks**: -1. Is the gateway running? In the terminal: `openclaw gateway status` +1. Is the gateway running? In the terminal: `oc-gateway status` 2. Is the bind mode correct? `openclaw config get gateway.bind` — must be `lan` for direct LAN access, or `loopback` if using `lan_https` mode 3. Is the port correct? `openclaw config get gateway.port` 4. Is the firewall blocking the port? Check your HA host firewall rules @@ -872,7 +874,7 @@ jq 'del(.tools.web.search.provider)' /config/.openclaw/openclaw.json > /tmp/open "allowedOrigins": ["https://YOUR_IP:18789"] } ``` - Then restart the gateway: `openclaw gateway restart` + Then restart only the gateway process: `oc-gateway restart` 3. Alternatively, approve devices individually without disabling auth: ```sh openclaw devices list # show pending pairing requests diff --git a/openclaw_assistant/CHANGELOG.md b/openclaw_assistant/CHANGELOG.md index 7c340a1..1e1dfff 100644 --- a/openclaw_assistant/CHANGELOG.md +++ b/openclaw_assistant/CHANGELOG.md @@ -2,15 +2,52 @@ All notable changes to the OpenClaw Assistant Home Assistant Add-on will be documented in this file. +## [0.5.74] - 2026-05-27 + +### Fixed +- Bundle `node-llama-cpp` inside the add-on image so the default local memory/embeddings provider works in HAOS without manual package installs. +- Add `cmake` to the image so `node-llama-cpp` can fall back to a source build when a prebuilt binary is unavailable for the target architecture. + +## [0.5.73] - 2026-05-26 + +### Added +- New add-on-native `oc-gateway` helper for container-supervised runtime management: + - `oc-gateway status` shows gateway state in the HA add-on model (`run.sh` supervisor, not systemd) + - `oc-gateway restart` requests gateway self-restart via `SIGUSR1` without full add-on restart + +### Changed +- Troubleshooting and setup docs now use `oc-gateway status` / `oc-gateway restart` in add-on contexts to avoid confusing systemd-related CLI output. + ## [0.5.72] - 2026-05-04 ### Fixed - Repair startup when a persisted OpenClaw config still selects the unavailable `tools.web.search.provider=brave` provider. The add-on now clears that provider before launching the gateway so OpenClaw can start; users can reinstall/enable the Brave provider later if they want web search through Brave. +## [0.5.71] - 2026-05-03 + +### Changed +- Bump OpenClaw through the 2026.4.29 and 2026.5.2 upstream releases. + ## [0.5.70] - 2026-04-30 +### Changed - Bump OpenClaw to 2026.4.27. +## [0.5.69] - 2026-04-27 + +### Changed +- Bump OpenClaw through the 2026.4.23 and 2026.4.24 upstream releases. + +## [0.5.68] - 2026-04-25 + +### Changed +- Bump OpenClaw through the 2026.4.14, 2026.4.15, 2026.4.21, and 2026.4.22 upstream releases. + +## [0.5.67] - 2026-04-25 + +### Changed +- Bump OpenClaw through the 2026.4.5, 2026.4.8, 2026.4.9, 2026.4.10, 2026.4.11, and 2026.4.12 upstream releases. + ## [0.5.66] - 2026-04-04 ### Fixed @@ -31,6 +68,11 @@ All notable changes to the OpenClaw Assistant Home Assistant Add-on will be docu ### Fixed - **Gateway restart loop** (issue #95): `openclaw gateway run` is a thin wrapper that spawns `openclaw-gateway` as a long-running daemon then exits immediately. On self-restart (SIGUSR1 / `openclaw gateway restart`), the old daemon forks a new one and exits — the new PID is not a child of run.sh. The supervisor now uses a 3-tier daemon detection function (`find_gateway_daemon_pid`): (1) port ownership via `ss -tlnp`, (2) process title via `pgrep -f "openclaw-gateway"`, (3) `/proc/*/cmdline` scan for "openclaw" (catches the daemon immediately after fork, even before process.title or port bind — critical on Pi/eMMC where initialization takes 20-30 s). Detection retries up to 10 times with a final port-occupancy guard before any supervisor-initiated restart. Non-child PIDs are monitored with `kill -0` polling instead of `wait`. The loopback relay (tailnet mode) is stopped/restarted around gateway restarts to prevent port conflicts. +## [0.5.61] - 2026-03-10 + +### Fixed +- **Gateway restart loop** (issue #95): stop the tailnet loopback relay before supervisor-initiated gateway restarts and start it again after the new daemon is launched, preventing the relay from holding the local port and trapping the add-on in an `already listening` restart loop. + ## [0.5.60] - 2026-03-10 ### Fixed diff --git a/openclaw_assistant/Dockerfile b/openclaw_assistant/Dockerfile index e9cf3f3..8995999 100644 --- a/openclaw_assistant/Dockerfile +++ b/openclaw_assistant/Dockerfile @@ -18,6 +18,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ xz-utils \ file \ python3 \ + cmake \ nginx \ gnupg \ build-essential \ @@ -113,8 +114,10 @@ RUN if [ -x /home/linuxbrew/.linuxbrew/bin/brew ]; then \ USER root # Install OpenClaw globally +# Bundle node-llama-cpp in the image so the default local memory/embeddings +# provider works in HAOS without requiring manual npm installs in /usr/lib. RUN npm config set fund false && npm config set audit false \ - && npm install -g openclaw@2026.5.22 + && npm install -g openclaw@2026.5.22 node-llama-cpp@3.18.1 # Shell aliases and color options for interactive use RUN tee -a /etc/bash.bashrc <<'EOF' @@ -138,10 +141,11 @@ COPY run.sh /run.sh COPY oc_config_helper.py /oc_config_helper.py COPY render_nginx.py /render_nginx.py COPY oc-cleanup.sh /usr/local/bin/oc-cleanup +COPY oc-gateway /usr/local/bin/oc-gateway COPY openclaw-proxy-shim.cjs /usr/local/lib/openclaw-proxy-shim.cjs COPY nginx.conf.tpl /etc/nginx/nginx.conf.tpl COPY landing.html.tpl /etc/nginx/landing.html.tpl -RUN chmod +x /run.sh /oc_config_helper.py /render_nginx.py /usr/local/bin/oc-cleanup \ +RUN chmod +x /run.sh /oc_config_helper.py /render_nginx.py /usr/local/bin/oc-cleanup /usr/local/bin/oc-gateway \ && mkdir -p /run/nginx CMD [ "/run.sh" ] diff --git a/openclaw_assistant/config.yaml b/openclaw_assistant/config.yaml index 1d70573..c16d29b 100644 --- a/openclaw_assistant/config.yaml +++ b/openclaw_assistant/config.yaml @@ -1,5 +1,5 @@ name: OpenClaw Assistant -version: "0.5.73" +version: "0.5.74" slug: openclaw_assistant description: Run OpenClaw Assistant (OpenClaw-compatible) as a Home Assistant add-on. url: https://github.com/techartdev/OpenClawHomeAssistant diff --git a/openclaw_assistant/oc-gateway b/openclaw_assistant/oc-gateway new file mode 100755 index 0000000..201c572 --- /dev/null +++ b/openclaw_assistant/oc-gateway @@ -0,0 +1,133 @@ +#!/usr/bin/env bash +set -euo pipefail + +cmd="${1:-status}" +shift || true + +find_gateway_pid() { + local port="${1:-18789}" + local pid="" + + # 1) Port owner (most accurate) + if command -v ss >/dev/null 2>&1; then + pid=$(ss -tlnp 2>/dev/null \ + | grep ":${port} " \ + | sed -n 's/.*pid=\([0-9]*\).*/\1/p' \ + | head -1 || true) + if [ -n "$pid" ] && [ -r "/proc/$pid/cmdline" ]; then + local cmdline + cmdline=$(tr '\0' ' ' < "/proc/$pid/cmdline" 2>/dev/null || true) + if echo "$cmdline" | grep -qi "openclaw\|node"; then + echo "$pid" + return 0 + fi + fi + fi + + # 2) Process title + pid=$(pgrep -f "openclaw-gateway" 2>/dev/null | head -1 || true) + if [ -n "$pid" ]; then + echo "$pid" + return 0 + fi + + # 3) /proc cmdline fallback + for f in /proc/[0-9]*/cmdline; do + [ -r "$f" ] || continue + if tr '\0' ' ' < "$f" 2>/dev/null | grep -qi "openclaw"; then + echo "${f#/proc/}" | cut -d/ -f1 + return 0 + fi + done + + return 1 +} + +get_gateway_port() { + python3 - <<'PY' +import json, os +p = os.environ.get('OPENCLAW_CONFIG_PATH', '/config/.openclaw/openclaw.json') +try: + with open(p, 'r', encoding='utf-8') as f: + cfg = json.load(f) + print(int(cfg.get('gateway', {}).get('port', 18789))) +except Exception: + print(18789) +PY +} + +status_cmd() { + local port pid + port="$(get_gateway_port)" + pid="$(find_gateway_pid "$port" || true)" + + echo "OpenClaw add-on gateway status" + echo "Supervisor: run.sh (not systemd)" + echo "Configured port: ${port}" + + if [ -n "$pid" ] && kill -0 "$pid" 2>/dev/null; then + echo "Gateway process: running (PID ${pid})" + if command -v ss >/dev/null 2>&1 && ss -tlnp 2>/dev/null | grep -q ":${port} "; then + echo "Listener: active on :${port}" + else + echo "Listener: process found, port bind not detected yet" + fi + exit 0 + fi + + echo "Gateway process: not detected" + echo "Tip: Check add-on logs in Home Assistant for startup errors." + exit 1 +} + +restart_cmd() { + local port pid + port="$(get_gateway_port)" + pid="$(find_gateway_pid "$port" || true)" + + if [ -z "$pid" ] || ! kill -0 "$pid" 2>/dev/null; then + echo "No running gateway process found to restart." + echo "Tip: If startup failed, inspect add-on logs." + exit 1 + fi + + echo "Requesting gateway self-restart via SIGUSR1 (PID ${pid})..." + kill -USR1 "$pid" + + for _ in $(seq 1 20); do + sleep 1 + local new_pid + new_pid="$(find_gateway_pid "$port" || true)" + if [ -n "$new_pid" ] && kill -0 "$new_pid" 2>/dev/null; then + echo "Gateway active (PID ${new_pid})" + exit 0 + fi + done + + echo "Restart signal sent; gateway may still be reinitializing." + echo "Run 'oc-gateway status' again in a few seconds." + exit 0 +} + +case "$cmd" in + status) + status_cmd + ;; + restart|reload) + restart_cmd + ;; + help|-h|--help) + cat <<'EOF' +Usage: oc-gateway + +status Show add-on-native gateway status (run.sh-supervised) +restart Request gateway self-restart via SIGUSR1 +reload Alias of restart +EOF + ;; + *) + echo "Unknown command: $cmd" >&2 + echo "Run: oc-gateway help" >&2 + exit 2 + ;; +esac