From 02814db08019d796ab0e1282701462f0d7573617 Mon Sep 17 00:00:00 2001 From: techartdev Date: Tue, 10 Mar 2026 22:44:51 +0200 Subject: [PATCH] feat: update version to 0.5.60 and enhance session lock cleanup for non-default agents --- openclaw_assistant/CHANGELOG.md | 6 ++++++ openclaw_assistant/config.yaml | 2 +- openclaw_assistant/run.sh | 32 +++++++++++++++++++++++--------- 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/openclaw_assistant/CHANGELOG.md b/openclaw_assistant/CHANGELOG.md index 6edaff8..721fda2 100644 --- a/openclaw_assistant/CHANGELOG.md +++ b/openclaw_assistant/CHANGELOG.md @@ -2,12 +2,18 @@ All notable changes to the OpenClaw Assistant Home Assistant Add-on will be documented in this file. +## [0.5.60] - 2026-03-10 + +### Fixed +- **Session lock cleanup ignored non-default agents**: `cleanup_session_locks` was hardcoded to `agents/main/sessions`, skipping stale locks for any agent with a custom `forcedAgentId`. Stale locks could block the gateway from opening sessions for those agents, causing silent fallback to `main`. Cleanup now scans all `agents/*/sessions/` directories. + ## [0.5.59] - 2026-03-10 ### Fixed - **Gateway restart loop** (issue #95): when the agent or user ran `openclaw gateway restart`, the supervisor loop detected the old PID exiting and immediately spawned a second gateway instance, which collided with the already-restarted one and looped with "another gateway instance is already listening". The supervisor now detects a self-restart (new PID already running on the same port) and re-tracks it instead of spawning a duplicate. - **Remote mode URL not propagated** (issue #93): `start_openclaw_runtime` was reading `gateway.remote.url` back via `openclaw config get`, which can time out (2 s limit at startup) or return an empty/redacted result. The function now uses `$GATEWAY_REMOTE_URL` directly from the already-parsed add-on options, which is the same value the config helper writes to `openclaw.json`. - **Terminal CLI unreachable in tailnet mode** (issue #90): when `gateway_bind_mode=tailnet` (or `access_mode=tailnet_https`), the gateway binds only to the Tailscale IP. The local CLI always connects via `ws://127.0.0.1:PORT`, causing "Gateway not running" inside the add-on terminal. A lightweight loopback relay (Node.js) is now started automatically to forward `127.0.0.1:PORT → TAILSCALE_IP:PORT`, making all terminal CLI commands work normally. Token auth is still enforced end-to-end by the gateway. +- **Session lock cleanup ignored non-default agents**: `cleanup_session_locks` was hardcoded to `agents/main/sessions`, skipping stale locks for any agent with a custom `forcedAgentId`. Stale locks could block the gateway from opening sessions for those agents, causing silent fallback to `main`. Cleanup now scans all `agents/*/sessions/` directories. ### Added - **MCP auto-configuration for Home Assistant**: new option `auto_configure_mcp` (default: `false`). When enabled and `homeassistant_token` is set, the add-on automatically registers Home Assistant as an MCP server (`mcporter config add HA ...`) on startup. Auto-detects the HA API URL (supervisor proxy or localhost:8123). Re-configures only when the token changes. diff --git a/openclaw_assistant/config.yaml b/openclaw_assistant/config.yaml index e88496f..8cf2ad9 100644 --- a/openclaw_assistant/config.yaml +++ b/openclaw_assistant/config.yaml @@ -1,5 +1,5 @@ name: OpenClaw Assistant -version: "0.5.59" +version: "0.5.60" 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/run.sh b/openclaw_assistant/run.sh index 4e1547b..0a7ca9b 100644 --- a/openclaw_assistant/run.sh +++ b/openclaw_assistant/run.sh @@ -374,8 +374,9 @@ if [ ! -e /data ]; then ln -s /config /data || true fi -# Ensure these exist so cleanup doesn't fail -mkdir -p /config/.openclaw/agents/main/sessions || true +# Ensure the agents base directory exists so cleanup scans work even before first run. +# Do NOT pre-create agent-specific directories; OpenClaw creates them as needed. +mkdir -p /config/.openclaw/agents || true # ------------------------------------------------------------------------------ # SINGLE-INSTANCE GUARD (prevents multiple gateway runs racing each other) @@ -397,26 +398,39 @@ gateway_running() { } cleanup_session_locks() { - local sessions_dir="/config/.openclaw/agents/main/sessions" - local glob1="${sessions_dir}"/*.jsonl.lock + local agents_dir="/config/.openclaw/agents" + local total_locks=0 + local cleaned_dirs=() + # Scan all agent session directories, not just 'main'. + # This is needed for users who have gateway.forcedAgentId set to a non-default agent. shopt -s nullglob - local locks=( $glob1 ) + local all_locks=() + for agent_sessions_dir in "${agents_dir}"/*/sessions; do + local agent_locks=( "${agent_sessions_dir}"/*.jsonl.lock ) + if [ ${#agent_locks[@]} -gt 0 ]; then + all_locks+=( "${agent_locks[@]}" ) + cleaned_dirs+=( "$agent_sessions_dir" ) + total_locks=$(( total_locks + ${#agent_locks[@]} )) + fi + done shopt -u nullglob - if [ ${#locks[@]} -eq 0 ]; then + if [ "$total_locks" -eq 0 ]; then return 0 fi # If gateway is running, do NOT remove locks automatically (could be real). if gateway_running; then echo "INFO: Gateway appears to be running; leaving session lock files untouched." - echo "INFO: Locks present: ${#locks[@]}" + echo "INFO: Locks present: $total_locks" return 0 fi - echo "INFO: Removing stale session lock files (${#locks[@]}) from ${sessions_dir}" - rm -f "${sessions_dir}"/*.jsonl.lock || true + echo "INFO: Removing stale session lock files ($total_locks) across agents: ${cleaned_dirs[*]}" + for agent_sessions_dir in "${cleaned_dirs[@]}"; do + rm -f "${agent_sessions_dir}"/*.jsonl.lock || true + done } if [ "$CLEAN_LOCKS_ON_START" = "true" ]; then