Repository navigation
fix: gateway stop/restart refuses a healthy gateway when the Windows process snapshot misses - #146387
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs real behavior proof before merge. Reviewed September 13, 2026, 3:00 AM ET / 07:00 UTC (Revision 4). ClawSweeper reviewWhat this changesAdds per-process ownership verification when Windows cannot retrieve its full process snapshot, and includes listener identities and recovery instructions in Gateway stop/restart errors. Merge readiness⛔ Blocked before merge - 3 items remain This remains a useful fix absent from current main. The updated Windows evidence addresses the earlier stop/restart reproduction gap, and no blocking code defect was found; the required published-updater compatibility evidence remains outstanding. Priority: P2 Review scores
Verification
How this fits togetherThe Windows service controller translates Gateway lifecycle commands into Scheduled Task operations and process termination. It compares running processes with the installed launch command before stopping them, then verifies that the listening port is released. flowchart TD
A[Gateway stop or restart] --> B[Installed task command]
B --> C[Read Windows process snapshot]
C --> D[Verify command and port]
C -->|Snapshot unavailable| E[Inspect individual port listeners]
E --> D
D -->|Owned| F[Terminate and verify port release]
D -->|Unverified| G[Refuse and describe listeners]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +66, Tests +80. Total +146 across 3 files. View PR surface stats
Review metricsNone. Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep the existing ownership checks and resilient per-PID retrieval, with published-updater compatibility demonstrated for an existing Windows installation. Do we have a high-confidence way to reproduce the issue? Yes: current main returns no owned process after snapshot failure, and the contributor reports a concrete Windows ENOBUFS reproduction against v2026.9.4. This read-only review did not execute a current-main reproduction. Is this the best way to solve the issue? Yes: reusing per-PID process inspection and the existing exact-argv ownership predicate is a focused repair; the separate launcher-redirection fix does not cover this failure. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 1cc5eea5e2d6. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (3 earlier review cycles)
|
…misses (openclaw#145984) On Windows, stop/restart ownership proof for the Scheduled Task gateway relied entirely on the full Win32_Process CIM snapshot. When that snapshot is unavailable (CIM timeout/failure) the CLI refused to touch a healthy gateway with "remaining listener ownership could not be verified", forcing manual process hunting. - Fall back to verifying the actual port listeners per PID (CIM CommandLine, WMIC fallback) with the same persisted-argv + port proof standard, so a healthy owned gateway is still stopped cleanly. - When ownership still cannot be verified, include the remaining listener PIDs, whether each looks like an OpenClaw gateway, and the manual Stop-Process remediation in the thrown error. Unverified or foreign-checkout listeners are still never killed.
0636dc0 to
9ad33b3
Compare
|
Merged via squash.
|
* commit '2acbeee461474b6ba41f5186ae1a4e0e80f4087a': (117 commits) fix(ui): import the shared deferred helper in sidebar scope tests (#146862) fix(ui): copy chat content from its context menu (#146679) perf(memory): defer legacy sidecar writer imports (#146815) fix(e2e): accept expected Kitchen Sink worker rejection (#146681) fix(ui): distinguish absolute and relative file links (#146572) feat(ui): keep file previews in tabs and render HTML (#146672) refactor: reuse shared deferred promises in UI tests (#146670) fix: gateway stop/restart refuses a healthy gateway when the Windows process snapshot misses (#146387) improve(crabbox): keep healthy cloud desktops warm on resume (#146816) fix: report blocked SQLite WAL checkpoints in status and doctor (#146775) feat: share browser dashboards with agents (#146702) fix(doctor): continue repairs after legacy agent directory collisions (#146092) feat(agents): retry cyber-refused embedded turns on Daybreak (#145291) fix: restore media uploads through protected egress (#144902) refactor(qa): share capture filter rendering (#146696) fix(cli): keep running stream jobs visible as running (#146793) refactor(parallels): share gateway readiness loop (#146694) fix(sessions): avoid rewriting already-consumed input on release (#146795) fix: preserve scheduled conversation delivery after Doctor (#146794) perf(ui): avoid redundant session-row provenance work (#146797) ...
…process snapshot misses (openclaw#146387) Windows Scheduled Task Gateway stop/restart now verifies actual listening PIDs when the full Win32_Process snapshot is unavailable, including CIM failure or oversized snapshot output. The existing persisted argv, port, supervisor, and lifecycle-authority checks remain in place; foreign listeners are refused with their identities and recovery guidance. Exact-head CI and focused ownership/diagnostic tests pass. The restart-listener diagnostic regression fails before the fix and passes after it. Contributor-reported Windows evidence is preserved in the PR; independent native Windows and published-updater compatibility runs remain documented proof gaps accepted for this landing. Closes openclaw#145984 Co-authored-by: ggbond <[email protected]>
Closes #145984
What Problem This Solves
Fixes an issue where users on Windows running
openclaw gateway stop --forceorgateway restart --forcewould be refused withgateway port 18789 is still busy ... remaining listener ownership could not be verifiedeven though the gateway on the configured port is healthy, serving, and plainly killable (Stop-Process -Id <pid> -Forceworks from a non-elevated shell).On Windows, ownership proof for the Scheduled Task gateway depended entirely on the full
Win32_ProcessCIM snapshot (readWindowsProcessSnapshot). When that snapshot is unavailable (CIM timeout/failure — or, as demonstrated below, its JSON output exceeding Node's 1 MBspawnSyncbuffer on a busy machine), the CLI gave up on a gateway it should be able to identify as its own, and the error named no PID to act on.Why This Change Was Made
Two narrow changes, keeping the existing conservative kill contract:
CommandLine, WMIC fallback) with the exact same proof standard as before — persisted task argv plus--portmatch, with and without the supervisor flag. Same proof, more resilient retrieval.Stop-Process -Id <pid> -Force), per option (b) in the issue.Non-goals: no loosening of ownership proof (unverified or foreign-checkout listeners are never killed), no behavior change when the CIM snapshot works, no changes off the Windows path besides the error text. The argv-mismatch trigger family (e.g. hand-edited launcher redirections) is intentionally left to #137374 and to the new actionable diagnostics here, rather than relaxing the exact-argv kill proof.
User Impact
Get-NetTCPConnectionhunting.Evidence
Real Windows 11 runs — this branch built from source, packed via
scripts/package-openclaw-for-docker.mjs, installed from the tarball, gateway installed as the realOpenClaw GatewayScheduled Task (build stampOpenClaw 2026.9.4 (6141a57)).schtasks /Endcannot kill); the full-process CIM snapshot forced to fail for real by flooding ~850 processes with long command lines, pushing the snapshot JSON past Node's 1 MBspawnSyncmaxBuffer(verified directly:spawnSyncreturnsENOBUFS; output was 1,140,175 bytes). This mirrors a genuinely busy developer machine.[email protected] (3a9d69d):gateway stop --force→Gateway stop failed: Error: gateway port 18789 is still busy after stop; remaining listener ownership could not be verified; listener still alive and serving afterwards — the exact reported failure.gateway stop --force→Stopped Scheduled Task: OpenClaw Gateway; port free, owned process gone (per-PID CIM verification →taskkill→ port release confirmed).gateway restart --forcein the same setup →Restarted Scheduled Task: OpenClaw Gateway; old listener terminated, new task-spawned gateway listening on 18789.gateway restart --forceandstop --forceagainst the task-owned gateway both succeed.node dist\index.js gateway --port 18789):... remaining listener ownership could not be verified— dead end.... could not be verified. Remaining listener(s): pid 47792 (node.exe, openclaw gateway). If one of these is this gateway, stop it with "Stop-Process -Id <pid> -Force" and retry.Following the hint then letsstop --forcesucceed.openclaw updateflow with the candidate served as[email protected]from a loopback registry (OPENCLAW_UPDATE_PACKAGE_SPEC=openclaw+NPM_CONFIG_REGISTRY=http://127.0.0.1, the repo's documented local integration seam). The updater resolved the target, staged and packed the candidate, ran candidate Doctor including a live inference probe (HTTP 200 from the configured provider) and migration rehearsal, and exercised the gateway service stop/start machinery this PR touches. The run then stopped at a deterministic WindowsEBUSYonunlink openclaw-agent-exec-*\state\openclaw.sqliteinside the rehearsal's agent-exec cleanup — a pre-existing Windows temp-file race in the rehearsal harness (no processes hold the file afterwards; same failure withTEMPredirected to a different drive), in code this PR does not touch. After every failed attempt the installation rolled back cleanly: still 2026.9.4, gateway running and listening (pid unchanged). The update path was equally exercised with a same-version control target, which passed staging/install until the intentionally faked version check.Tests —
src/daemon/schtasks.stop.test.ts(Windows host): 194/196 pass across the stop/restart/install/startup-fallback files; the only 2 failures (accepts a localized /End failure when COM proves the task is disabled/ready) fail identically on unmodifiedmainhere (pre-existing Windows environment issue, unrelated). New/updated coverage:refuses a same-port gateway from another checkout when the CIM snapshot is unavailable— the per-PID fallback still refuses a foreign gateway; the error namespid 6262+openclaw gateway.reports remaining listeners when the port stays busy before restart— restart error now includes the remaining listener PID.taskkillon Windows, whiledoes not kill an unrelated listener...asserts the unrelated PID is never touched.Static checks —
pnpm tsgo,pnpm tsgo:core:test,pnpm tsgo:test:root: clean.oxlinton the three touched files: clean.oxfmt --check: clean.