fix(gateway): fall back to PowerShell when wmic is unavailable on Win…#43624
Open
litaohz wants to merge 2 commits intoopenclaw:mainfrom
Open
fix(gateway): fall back to PowerShell when wmic is unavailable on Win…#43624litaohz wants to merge 2 commits intoopenclaw:mainfrom
litaohz 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) <[email protected]>
Contributor
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) <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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