From 81390c643b96c9269fda17c2ff1ef2dd555791e2 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Mon, 27 Apr 2026 23:14:17 +0100 Subject: [PATCH] fix(update): restart Windows startup gateway after update --- src/cli/update-cli/restart-helper.test.ts | 8 +++++++- src/cli/update-cli/restart-helper.ts | 20 ++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/cli/update-cli/restart-helper.test.ts b/src/cli/update-cli/restart-helper.test.ts index 722c9c630a5..99c841e7659 100644 --- a/src/cli/update-cli/restart-helper.test.ts +++ b/src/cli/update-cli/restart-helper.test.ts @@ -313,14 +313,19 @@ exit 0 expect(scriptPath.endsWith(".cmd")).toBe(true); expect(content).toContain("@echo off"); expect(content).toContain("powershell -NoProfile -ExecutionPolicy Bypass -Command"); - expect(content).not.toContain("-File"); + expect(content).not.toContain("powershell -NoProfile -ExecutionPolicy Bypass -File"); expect(content).toContain('$ErrorActionPreference = "Continue"'); expect(content).toContain("gateway-restart.log"); expect(content).toContain("$taskName = 'OpenClaw Gateway'"); expect(content).toContain("function Invoke-OpenClawSchtasksWithTimeout"); expect(content).toContain("function Get-OpenClawScheduledTaskState"); + expect(content).toContain("function Invoke-OpenClawStartupLauncher"); expect(content).toContain("Get-ScheduledTask -TaskName $TaskName"); expect(content).toContain("openclaw restart skipped schtasks end"); + expect(content).toContain( + '$launcherPath = Join-Path $env:USERPROFILE ".openclaw\\gateway.cmd"', + ); + expect(content).toContain("openclaw restart launched startup fallback"); expectWindowsRestartWaitOrdering(content); expect(content).toContain('del "%~f0" >nul 2>&1'); await cleanupScript(scriptPath); @@ -338,6 +343,7 @@ exit 0 expect(content).toContain( 'Invoke-OpenClawSchtasksWithTimeout -Arguments @("/End", "/TN", $taskName) -TimeoutSeconds 10', ); + expect(content).toContain("$status = Invoke-OpenClawStartupLauncher"); expectWindowsRestartWaitOrdering(content); await cleanupScript(scriptPath); }); diff --git a/src/cli/update-cli/restart-helper.ts b/src/cli/update-cli/restart-helper.ts index b796c77fb2c..82958898d3e 100644 --- a/src/cli/update-cli/restart-helper.ts +++ b/src/cli/update-cli/restart-helper.ts @@ -281,6 +281,23 @@ function Get-OpenClawListenerPids { $listenerPids | Sort-Object -Unique } +function Invoke-OpenClawStartupLauncher { + $launcherPath = Join-Path $env:USERPROFILE ".openclaw\\gateway.cmd" + if (-not (Test-Path -LiteralPath $launcherPath)) { + Write-RestartLog "openclaw restart startup launcher missing source=update path=$launcherPath" + return 1 + } + + try { + Start-Process -FilePath $launcherPath -WindowStyle Hidden | Out-Null + Write-RestartLog "openclaw restart launched startup fallback source=update path=$launcherPath" + return 0 + } catch { + Write-RestartLog "openclaw restart startup fallback failed source=update error=$($_.Exception.Message)" + return 1 + } +} + $taskName = ${quotedTaskName} $port = ${port} Write-RestartLog "openclaw restart attempt source=update target=$taskName" @@ -317,6 +334,9 @@ for ($attempt = 1; $attempt -le 10; $attempt++) { } $status = Invoke-OpenClawSchtasksWithTimeout -Arguments @("/Run", "/TN", $taskName) -TimeoutSeconds 30 +if ($status -ne 0) { + $status = Invoke-OpenClawStartupLauncher +} if ($status -eq 0) { Write-RestartLog "openclaw restart done source=update" } else {