Skip to content

fix: keepalive process inspection can hang after PowerShell exits - #1168

Merged
shanselman merged 2 commits into
openclaw:mainfrom
SebTardif:fix/bound-process-cmdline-drain
Aug 26, 2026
Merged

shanselman merged 2 commits into
openclaw:mainfrom
SebTardif:fix/bound-process-cmdline-drain

Conversation

@SebTardif

@SebTardif SebTardif commented Aug 16, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where users starting or repairing a local Windows gateway could see the tray or setup wizard hang after PowerShell finished listing a process command line. The hang occurs when keepalive cleanup or port ownership inspection sees the PowerShell child exit while a descendant still holds the redirected stdout pipe.

Why This Change Was Made

The inspection waited five seconds for PowerShell to exit, then used an unbounded stdout read. WaitForExit completes when the child exits, but ReadToEnd completes only after every inherited write handle closes. The shared helper now bounds both child exit and stdout drain, observes abandoned reads, releases the owned stdout reader, and records distinct trace diagnostics for process, exit-timeout, and drain-timeout failures.

Tray keepalive and setup keepalive now use the same bounded command-line lookup instead of keeping separate implementations.

User Impact

Local gateway keepalive and setup process inspection return null (indeterminate command line) instead of hanging when stdout never closes. Successful output that completes during the drain grace period is preserved.

Evidence

Current-head Windows proof on a2ff98889cd92b4d5b2040f7dbc7683f7f23d472:

  • Windows NT 10.0.26340.0, x64, .NET SDK 10.0.303.
  • The real CIM/PowerShell lookup for the current process completed within the seven-second anti-hang bound.
  • A real cmd.exe parent exited while a ping.exe descendant retained stdout. The helper returned null within two seconds instead of waiting for pipe EOF.
  • The real inherited-pipe regression passed 20 of 20 repeated runs.
  • A successful output task completing during the post-exit drain grace returned the full expected output.
  • Setup and tray source guards verify both keepalive owners route through WindowsTcpListenerSnapshot.GetProcessCommandLine and do not reintroduce StandardOutput.ReadToEnd.

Change Type

  • Bug fix
  • Feature
  • Refactor
  • Docs or instructions
  • Tests or validation
  • Security hardening
  • Chore or infrastructure

Scope

  • Tray or WinUI UX
  • Windows node capability
  • Local MCP or winnode
  • Gateway, connection, or pairing
  • Setup or onboarding
  • Permissions, privacy, or security
  • Tests, CI, or docs

Validation

.\build.ps1
All builds succeeded.

dotnet test .\tests\OpenClaw.Connection.Tests\OpenClaw.Connection.Tests.csproj --no-restore --nologo
Passed: 686, Failed: 0, Skipped: 0

dotnet test .\tests\OpenClaw.SetupEngine.Tests\OpenClaw.SetupEngine.Tests.csproj --no-restore --nologo
Passed: 978, Failed: 0, Skipped: 0

dotnet test .\tests\OpenClaw.Shared.Tests\OpenClaw.Shared.Tests.csproj --no-restore --nologo
Passed: 3813, Failed: 0, Skipped: 32

dotnet test .\tests\OpenClaw.Tray.Tests\OpenClaw.Tray.Tests.csproj --no-restore --nologo
Passed: 2721, Failed: 0, Skipped: 0

# Repeated real descendant-held-pipe regression
Current-head inherited-pipe drain stress passed: 20/20 iterations.

The full validation tree included a normal merge of current origin/main before these commands, so the fix was exercised against the release-bound base without rewriting history.

Real behavior proof

  • Behavior addressed: command-line inspection no longer waits indefinitely after PowerShell exits while an inherited stdout handle remains open.
  • Environment: Microsoft Windows NT 10.0.26340.0, x64, .NET SDK 10.0.303.
  • Current PR head: a2ff98889cd92b4d5b2040f7dbc7683f7f23d472.
  • Production-path proof: GetProcessCommandLine(Environment.ProcessId) exercised the real Windows PowerShell and CIM path and completed within the bounded window.
  • Failure-path proof: a real parent/descendant process pair reproduced the inherited pipe-holder condition; the helper returned indeterminate rather than hanging, repeated 20 of 20 times.
  • Successful-output proof: output completing during the reserved drain grace was returned intact.
  • Review proof: adversarial Claude Opus and Codex reviews found no remaining release-blocking issue. Final confidence was 97% and 96%, respectively.

Security Impact

  • New permissions or capabilities? (No)
  • Secrets or tokens handling changed? (No)
  • New or changed network calls? (No)
  • Command or tool execution surface changed? (No)
  • Data access scope changed? (No)
  • If any answer is Yes, explain the risk and mitigation:

Compatibility and Migration

  • Backward compatible? (Yes)
  • Config or environment changes? (No)
  • Migration needed? (No)
  • If yes, list the exact upgrade steps:

Review Conversations

  • I replied to or resolved every bot review conversation addressed by this PR.
  • No unresolved review thread remains.

@clawsweeper

clawsweeper Bot commented Aug 16, 2026

Copy link
Copy Markdown

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@clawsweeper clawsweeper Bot added merge-risk: 🚨 availability 🚨 Merging this PR could cause crashes, hangs, restart loops, stalls, or process outages. P2 Normal priority bug or improvement with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Aug 16, 2026
@clawsweeper

clawsweeper Bot commented Aug 16, 2026 •

Copy link
Copy Markdown

Codex review: needs maintainer review before merge. Reviewed August 25, 2026, 9:12 PM ET / August 26, 2026, 01:12 UTC.

ClawSweeper review

What this changes

This PR bounds PowerShell command-line output draining and routes setup and tray keepalive inspection through the shared helper so inherited stdout handles cannot hang local gateway recovery.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

Keep open. Current main and v2026.7.1 retain the unbounded output drain, while this actively landing branch supplies a focused bounded fix with Windows runtime evidence.

Priority: P1
Reviewed head: a2ff98889cd92b4d5b2040f7dbc7683f7f23d472

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) Focused bounded behavior, caller consolidation, and current-head Windows proof make this a normal mergeable reliability patch.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The PR body provides current-head Windows evidence for a real CIM lookup, a real retained-pipe parent and descendant case repeated 20 times, and successful output during drain grace.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The PR body provides current-head Windows evidence for a real CIM lookup, a real retained-pipe parent and descendant case repeated 20 times, and successful output during drain grace.
Evidence reviewed 6 items Current main remains affected: Current main starts an asynchronous stdout read, waits only for the PowerShell child, then synchronously awaits EOF from the redirected pipe.
Bounded implementation: The branch bounds both child exit and stdout draining, disposes the owned reader on abandonment, and returns null on timeout.
Both production callers use the shared path: Setup and tray keepalive now delegate command-line lookup to the bounded helper; caller guards prohibit reintroducing direct ReadToEnd usage.
Findings None None.
Security None None.

Live Verification

Command: dotnet test .\tests\OpenClaw.Connection.Tests\OpenClaw.Connection.Tests.csproj --no-restore --filter FullyQualifiedName~WindowsTcpListenerSnapshotTests

Result: FAIL (failed) — execution before step 1 run: sh -lc pnpm install --ignore-scripts --frozen-lockfile failed: ! Corepack is about to download https://registry.npmjs.org/pnpm/-/pnpm-11.24.0.tgz

sh -lc pnpm install --ignore-scripts --frozen-lockfile failed: ! Corepack is about to download https://registry.npmjs.org/pnpm/-/pnpm-11.24.0.tgz

Assertions:

  • FAIL expect_output: Passed

How this fits together

Gateway setup and tray keepalive inspect Windows process command lines to identify owned local gateway processes. The result feeds safe recovery, cleanup, and ownership decisions.

flowchart LR
A[Tray keepalive] --> C[Command-line lookup]
B[Setup keepalive] --> C
C --> D[PowerShell CIM query]
D --> E{Process and stdout finish?}
E -->|yes| F[Command line]
E -->|timeout| G[Indeterminate result]
F --> H[Ownership and recovery]
G --> H
Loading

Before merge

  • Resolve merge risk (P1) - A timeout now makes process ownership indeterminate; current callers use null as a non-destructive or fail-closed outcome, but the Windows timing behavior remains availability-sensitive.
  • Complete next step (P2) - This active contributor patch has a current maintainer landing path and no concrete repair finding for a separate automation lane.
Agent review details

Security

None.

Review metrics

Metric Value Why it matters
Production versus tests production +63/-53, tests +133 The small centralization is backed by substantially more focused regression coverage.
Behavior coverage 4 focused behavior tests, 2 caller guards Coverage exercises the retained-pipe failure and prevents both keepalive callers from restoring unbounded reads.

Merge-risk options

Maintainer options:

  1. Land with bounded indeterminate handling (recommended)
    Accept the existing safe behavior that an expired process or drain budget returns an indeterminate result instead of blocking gateway recovery.

Technical review

Best possible solution:

Merge the shared bounded lookup through the active landing path so setup, tray keepalive, and listener provenance all avoid an inherited-pipe hang.

Do we have a high-confidence way to reproduce the issue?

Yes, with high source confidence: a child that retains inherited stdout leaves current main waiting at the unbounded post-exit read; the PR also reports a real Windows parent and descendant exercise of that condition.

Is this the best way to solve the issue?

Yes. Centralizing the existing PowerShell/CIM lookup is the narrowest maintainable repair and preserves callers' established null-as-indeterminate behavior.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against c446f34882af.

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient. The PR body provides current-head Windows evidence for a real CIM lookup, a real retained-pipe parent and descendant case repeated 20 times, and successful output during drain grace.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR body provides current-head Windows evidence for a real CIM lookup, a real retained-pipe parent and descendant case repeated 20 times, and successful output during drain grace.
  • remove status: 📣 needs proof: Current PR status label is status: 👀 ready for maintainer look.
  • remove rating: 🦪 silver shellfish: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.

Label justifications:

  • P1: A retained stdout pipe can block local gateway setup or recovery for active Windows users.
  • merge-risk: 🚨 availability: The patch changes timeout and cleanup behavior in process inspection used by gateway recovery paths.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR body provides current-head Windows evidence for a real CIM lookup, a real retained-pipe parent and descendant case repeated 20 times, and successful output during drain grace.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body provides current-head Windows evidence for a real CIM lookup, a real retained-pipe parent and descendant case repeated 20 times, and successful output during drain grace.

Evidence

What I checked:

Likely related people:

  • shanselman: Authored the current head that extends the shared bounded lookup to setup and tray callers, and applied the active-landing label. (role: recent area contributor and active landing owner; confidence: high; commits: a2ff98889cd9; files: src/OpenClaw.Connection/WindowsTcpListenerSnapshot.cs, src/OpenClaw.SetupEngine/KeepaliveProcessRuntime.cs, src/OpenClaw.Tray.WinUI/Services/WslGatewayKeepAliveService.cs)
  • bkudiess: The merged local gateway recovery work is the adjacent owner of listener provenance that consumes this command-line inspection path. (role: adjacent connection-recovery contributor; confidence: medium; commits: bc210e048aa9; files: src/OpenClaw.Connection/ManagedLocalGatewayPortProvenanceService.cs)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (3 earlier review cycles)
  • reviewed 2026-08-16T23:14:28.742Z sha 0096a23 :: needs real behavior proof before merge. :: none
  • reviewed 2026-08-25T09:18:52.618Z sha 2a2cac6 :: needs real behavior proof before merge. :: [P1] Cover setup's equivalent command-line reader
  • reviewed 2026-08-26T00:41:03.169Z sha 2a2cac6 :: needs real behavior proof before merge. :: [P1] Bound setup’s equivalent command-line reader

WaitForExit returns when PowerShell exits, but ReadToEnd only
finishes after the write end of stdout closes. A descendant that
inherited the pipe left GetResult hanging past the 5s timeout.
Drain the leftover budget (same pattern as the MXC probe) and
reuse the helper from setup and WSL keepalive copies.

Signed-off-by: Sebastien Tardif <[email protected]>
@SebTardif
SebTardif force-pushed the fix/bound-process-cmdline-drain branch from 0096a23 to 2a2cac6 Compare August 25, 2026 09:14
@clawsweeper clawsweeper Bot added P1 Urgent regression or broken agent/channel workflow affecting real users now. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. and removed P2 Normal priority bug or improvement with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Aug 25, 2026
@shanselman shanselman added the status: 🚢 actively landing A maintainer or agent is actively driving this item through implementation, validation, or merge. label Aug 26, 2026
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. labels Aug 26, 2026
@shanselman

Copy link
Copy Markdown
Collaborator

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 26, 2026 •

Copy link
Copy Markdown

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added proof: sufficient Contributor real behavior proof is sufficient. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Aug 26, 2026
@shanselman
shanselman merged commit 951c27a into openclaw:main Aug 26, 2026
18 checks passed
@SebTardif
SebTardif deleted the fix/bound-process-cmdline-drain branch September 24, 2026 00:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-risk: 🚨 availability 🚨 Merging this PR could cause crashes, hangs, restart loops, stalls, or process outages. P1 Urgent regression or broken agent/channel workflow affecting real users now. proof: sufficient Contributor real behavior proof is sufficient. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 🚢 actively landing A maintainer or agent is actively driving this item through implementation, validation, or merge. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants