fix(gateway): fall back to PowerShell when wmic is unavailable on Win…#43624
fix(gateway): fall back to PowerShell when wmic is unavailable on Win…#43624litaohz wants to merge 2 commits intoopenclaw:mainfrom
Conversation
…dows On modern Windows (11+), Microsoft has deprecated and removed wmic.exe. This causes resolveWindowsCommandLine() to silently fail, returning no command line for port listeners. The health check then only sees "node.exe" (the image name), which classifyPortListener() cannot identify as a gateway process — it requires "openclaw" in the command string. This results in ownsPort=false → healthy=false, and the restart health check loops for 60s before timing out, even though the gateway restarted successfully. Fix: when wmic fails (non-zero exit or no output), fall back to PowerShell Get-CimInstance Win32_Process to retrieve the full command line. This restores correct process classification on wmic-less systems. Related: openclaw#32620 (same class of bug on Linux when lsof is missing) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Greptile SummaryThis PR adds a PowerShell
Confidence Score: 3/5
Prompt To Fix All With AIThis is a comment left during a code review.
Path: src/infra/ports-inspect.ts
Line: 278-291
Comment:
**PowerShell fallback triggered even when wmic succeeds**
The fallback to PowerShell is called in two cases, but it should only be called when `wmic` itself fails (non-zero exit code):
1. ✅ `wmic` returns non-zero (unavailable) → fallback to PowerShell — **intended**
2. ❌ `wmic` returns exit code 0 but produces no non-empty `commandline=` line → also falls through to PowerShell — **unintended regression**
Case 2 happens on machines where `wmic` **is** present (Windows 10 and earlier, the currently-working case). For any process that `wmic` can't report a commandline for (e.g. a system process with an inaccessible command line, or a process that has already exited), the code will now redundantly spawn `powershell.exe`. Since `powershell -NoProfile` can still take hundreds of milliseconds to start, this adds latency to every port inspection on the "working" Windows platform.
The fix is to only fall back to PowerShell when `wmic` returns a non-zero exit code:
```suggestion
if (res.code === 0) {
for (const rawLine of res.stdout.split(/\r?\n/)) {
const line = rawLine.trim();
if (!line.toLowerCase().startsWith("commandline=")) {
continue;
}
const value = line.slice("commandline=".length).trim();
if (value) {
return value;
}
}
return undefined;
}
// Fallback to PowerShell Get-CimInstance when wmic is unavailable.
return resolveWindowsCommandLineViaPowerShell(pid);
```
How can I resolve this? If you propose a fix, please make it concise.Last reviewed commit: 9f4d01e |
Address CI check failure (oxfmt) and Greptile review feedback: - Only fall back to PowerShell when wmic exits with non-zero code - When wmic succeeds (exit 0) but returns no commandline, return undefined directly instead of spawning an unnecessary PowerShell process (avoids latency regression on Windows 10 where wmic works) - Fix function signature formatting to satisfy oxfmt Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
Closing this as implemented after Codex review. Current What I checked:
So I’m closing this as already implemented rather than keeping a duplicate issue open. Review notes: reviewed against 28fc03c386e1; fix evidence: release v2026.4.22, commit 00bd2cf7a376. |
Summary
openclaw gateway restartalways times out (60s) on Windows machines wherewmichas been removed (Windows 11+), even though the gatewayrestarts successfully
Get-CimInstance Win32_Processwhenwmicfails, restoring correct process classification on modern WindowsRoot Cause
Microsoft deprecated and removed
wmic.exeon modern Windows (11+). This causesresolveWindowsCommandLine()insrc/infra/ports-inspect.tstosilently fail, returning no command line for port listeners. The restart health check then only sees
"node.exe"(the image name fromtasklist),which
classifyPortListener()cannot identify as a gateway process — it requires"openclaw"in the command string. This results in:ownsPort = false → healthy = false → 60s timeout loop → false failure report
The gateway is actually running and healthy the entire time.
Fix
When
wmicreturns a non-zero exit code or produces no output, fall back topowershell -NoProfile -Command "(Get-CimInstance Win32_Process -Filter 'ProcessId=<pid>').CommandLine"to retrieve the full command line. This is the Microsoft-recommended replacement forwmic process get CommandLine.Related
lsofis missing (open)Test plan
wmic: health check now correctly identifies the gateway process via PowerShell fallbackwmicis available, behavior is unchanged (wmic path taken first)wmicandpowershellfail, returnsundefinedgracefully (same as before)🤖 Generated with Claude Code