fix(windows): replace cmd handoff with Node.js subprocess for gateway restart#92726
fix(windows): replace cmd handoff with Node.js subprocess for gateway restart#92726likuoping136 wants to merge 1 commit into
Conversation
|
Thanks for the context here. I swept through the related work, and this is now duplicate or superseded. Keep this PR open: it targets a real Windows gateway restart availability problem, but the current patch is not merge-ready because it bypasses existing quoting, configured-port, PID-verification, locale-independent status, and helper-cleanup contracts, and the supplied proof is still too thin for the Windows user path. Canonical path: Close this PR as superseded by #52487. So I’m closing this here and keeping the remaining discussion on #52487. Review detailsBest possible solution: Close this PR as superseded by #52487. Do we have a high-confidence way to reproduce the issue? Yes for the PR-introduced defects: source inspection shows raw cmd task-name interpolation, hard-coded port killing, localized task-state parsing, and missing helper cleanup. I did not live-reproduce the original Windows scheduler race in this read-only review. Is this the best way to solve the issue? No: the proposed rewrite is plausible but bypasses existing safety contracts in the scheduled-task owner path. The safer solution is to keep the restart handoff repair inside those established quoting, port, PID-verification, and cleanup contracts. Security review: Security review needs attention: Needs attention: the diff introduces raw cmd command-string parsing and an unverified taskkill fallback in a Windows restart path.
AGENTS.md: found and applied where relevant. What I checked:
Likely related people:
Codex review notes: model internal, reasoning high; reviewed against b3968f69c910. |
d923027 to
4d5668a
Compare
… restart The existing cmd.exe handoff script has two critical bugs on Windows: 1. Race condition: After /restart, the old gateway exits but the Windows Task Scheduler still reports the task as Running due to delayed state updates. The handoff script checks for Running and skips schtasks /Run, incorrectly assuming another restart path already started a new instance. This leaves the gateway offline until manual intervention. Root cause: commit 6d26609 (openclaw#52487) added a PowerShell+findstr check for Running state before retrying schtasks /Run. The intent was to avoid duplicate /Run calls, but the check treats the stale Running state from the dying old process as evidence of a successful restart. 2. Visible console windows: The cmd script spawns powershell.exe piped to findstr.exe, which creates visible console popups even with windowsHide. This is confusing and disruptive to users. Fix: Replace the entire cmd.exe handoff script with a detached Node.js subprocess that: - First signals schtasks /End to stop the old task - Polls until the task is confirmed not running (with timeout + force-kill) - Then runs schtasks /Run to start the new instance - Falls back to gateway.cmd if schtasks /Run fails - Uses windowsHide on all child processes (no visible windows) Tested on Windows 10 with /restart command: gateway restarts reliably in under 1 second with no visible console windows.
4d5668a to
9e19a5f
Compare
|
ClawSweeper applied the proposed close for this PR.
|
Problem
On Windows, the
/restartcommand (and config-change triggered restarts) frequently fail to relaunch the gateway. The gateway shuts down but never comes back, requiring manualopenclaw gateway restart.Root Cause
Commit
6d26609(#52487) added a "Running" state check to the cmd.exe handoff script to avoid duplicateschtasks /Runcalls. However, this introduces a race condition:/restartfires → gateway process exitsGet-ScheduledTask.StatecleanupThe cmd script also spawns
powershell.exe | findstr.exe, which creates visible console popup windows even withwindowsHide: true, because the piped child processes aren't hidden.Fix
Replace the cmd.exe handoff script with a detached Node.js subprocess that:
.mjsrestart launcherschtasks /End— signals the Task Scheduler to stop the old taskschtasks /Queryuntil the task is confirmed NOT runningschtasks /Run— starts the new instance once the old one is confirmed gonegateway.cmddirectly ifschtasks /RunfailsWhy Node.js instead of cmd script?
windowsHide: trueworks correctly on Node.js child processesReal behavior proof (required for external PRs)
Behavior or issue addressed: Windows
/restartshould relaunch the managedOpenClaw GatewayScheduled Task without leaving the gateway offline and without visiblecmd/findstrconsole popups.Real environment tested: Real Windows 10 machine (Build 19045), OpenClaw 2026.6.6, managed Windows Scheduled Task named
OpenClaw Gateway, WebChat/restartcommand.Exact steps or command run after this patch:
/restartshut down the gateway and leave it offline until manualopenclaw gateway restart./restarttwice from WebChat.Evidence after fix (screenshot, recording, terminal capture, console output, redacted runtime log, linked artifact, or copied live output):
Observed result after fix:
/restartcompleted successfully on both attempts, the gateway came back immediately, and no visiblefindstr/ cmd console windows appeared.What was not tested: Windows 11 and non-default gateway ports.
Proof limitations or environment constraints: The proof used copied redacted runtime logs instead of screenshots/recordings. The task name tested was the default
OpenClaw Gateway; custom task names are covered by unit tests but not by the live Windows proof.Before evidence (optional but encouraged):
Those 60s+ gaps corresponded to the old handoff path; the gateway did not reliably relaunch and the user had to manually recover it. During this path, visible black console windows appeared with
findstrinvolved.Tests and validation
Which commands did you run?
What regression coverage was added or updated?