Skip to content

fix: Windows cleanup targets child PIDs after they exit - #140753

Merged
steipete merged 1 commit into
mainfrom
steipete/windows-pid-ownership-split-132180
Sep 7, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/windows-pid-ownership-split-132180

Conversation

@steipete

@steipete steipete commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

Related: #132180

What Problem This Solves

Resolves a problem where Windows tooling and test-instance cleanup could target a process ID again after its original child had already exited, while inherited output was still open. That ID may no longer belong to the child being cleaned up.

Why This Change Was Made

The shared managed-child terminator now checks the child's recorded exit before invoking taskkill and returns its existing indeterminate-cleanup result. Existing callers retain unresolved cleanup and its diagnostic state instead of targeting a retired PID or declaring descendants gone. POSIX process groups, live Windows termination, and explicit direct-child signaling remain unchanged.

This is the Windows process-ownership slice of the original PR, applied to current main without its unrelated CLI deadline-test rewrite. No new configuration, schema, public API, retries, or timeout changes.

User Impact

Windows development and test workflows no longer reuse a known-exited child's numeric PID for tree termination. When inherited output remains open and descendant cleanup cannot be verified, callers continue to report incomplete cleanup and retain their state rather than claiming success. Ordinary completed commands, successful output drainage, and live-child shutdown retain their existing behavior.

Evidence

  • Tests-only reproduction on main 4648bb0a70c54599630f21ace2a28c017ca65f8b: four intended failures and one pass. Both exited-child variants invoked taskkill; the held-pipe Gateway case reported success; the exited-leader diagnostic case attempted taskkill twice.
  • With the owner fix, the complete three-file suite passed 147 tests, with two platform skips on macOS. This includes the previously failing cases, live Windows termination via platform-controlled unit tests, POSIX descendant cleanup, run-with-env, and unchanged successful-drain/large-output deadline cases.
  • Native Windows proof passed in exact-head CI, Windows test-2 job. The actual inherited-stderr retention fixture passed with its new no-taskkill assertion (13.635 seconds), along with the successful-drain, large-output deadline, exited-Gateway, and diagnostic cases. This is native Windows execution, separate from the local platform-override tests.
  • Dependency contracts inspected directly: Node child exit versus stdio close and PID-reuse warning and Microsoft taskkill's numeric PID and tree-selection contract. Stable tag v2026.9.2 also lacks the guard.

Reproduction:

node scripts/run-vitest.mjs test/scripts/managed-child-process.test.ts test/helpers/openclaw-test-instance.test.ts -t 'does not target a known-exited Windows child|does not target an exited Windows gateway|observes Windows unverified exited leader'

Post-fix owner and sibling proof:

node scripts/run-vitest.mjs test/scripts/managed-child-process.test.ts test/helpers/openclaw-test-instance.test.ts test/scripts/run-with-env.test.ts

Changed checks:

node scripts/check-changed.mjs -- scripts/lib/managed-child-process.mts test/scripts/managed-child-process.test.ts test/helpers/openclaw-test-instance.test.ts test/helpers/openclaw-test-instance.cli.test-support.mjs

Changed formatting/type/lint/guard checks passed (117 seconds), and a fresh isolated Codex review returned scoped-clean at P0 on tree 44ed5a9c9b8cb2b7ad4f96b2c033ce55b91b22cb. Production/tooling +6/-1 (net +5); tests/test support +53/-30 (net +23). The small owner-level guard and its explanation protect the concrete retired-PID boundary; no consumer workaround or parallel cleanup path is added. The original PR remains open for its other replacements.

Retire numeric PID targeting once the original Windows child has exited.
Preserve indeterminate descendant cleanup and existing retained-state
behavior instead of claiming termination or retargeting another owner.

Keep POSIX group signals, live Windows shutdown, direct-child signaling,
and successful output drainage unchanged. Four pre-fix regressions fail;
147 focused tests pass with two platform skips, changed checks pass, and
fresh isolated P0 review is scoped-clean. Native Windows proof follows in CI.

Split from #132180.
@clawsweeper

clawsweeper Bot commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added scripts Repository scripts size: S maintainer Maintainer-authored PR labels Sep 7, 2026
@steipete steipete self-assigned this Sep 7, 2026
@steipete
steipete marked this pull request as ready for review September 7, 2026 04:00
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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. labels Sep 7, 2026
@clawsweeper

clawsweeper Bot commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 7, 2026, 12:30 AM ET / 04:30 UTC.

ClawSweeper review

What this changes

Windows tooling cleanup stops targeting an exited child’s process ID and preserves incomplete-cleanup diagnostics when descendants remain unverified.

Merge readiness

✅ Ready for maintainer review

This focused split remains necessary: fetched main and v2026.9.2 lack the guard. The review found no introduced correctness defect, and the supplied native Windows evidence covers the changed boundary.

Priority: P2
Reviewed head: 28b691b52671a19f4fda529cb4ce5dc7216404e2

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-level repair with meaningful regression coverage and native Windows boundary evidence; no blocking defect was found.
Proof confidence 🦞 diamond lobster (5/6) ✨ media proof bonus Sufficient (linked_artifact): The supplied native Windows result covers the real test-instance CLI and shared termination owner: an exited leader retains a live stderr writer, no taskkill is issued, incomplete cleanup retains state, and external rescue is verified. The fixture was inspected; linked job logs could not be independently retrieved.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (linked_artifact): The supplied native Windows result covers the real test-instance CLI and shared termination owner: an exited leader retains a live stderr writer, no taskkill is issued, incomplete cleanup retains state, and external rescue is verified. The fixture was inspected; linked job logs could not be independently retrieved.
Evidence reviewed 8 items Introduced guard and execution boundary: The guard precedes Windows taskkill invocation and returns the existing indeterminate result. POSIX signaling and explicitly selected direct-child signaling return through earlier branches. The introduced delta depends on Node child lifecycle and Windows taskkill, not the Codex contracts discussed in the broader related PR.
Current main and release still need the repair: Both fetched main and v2026.9.2 invoke numeric-PID taskkill without checking recorded exit. This establishes that the requested protection is still absent; no merged replacement is established by the supplied related context.
Existing callers preserve unresolved ownership: Managed command finalization throws an indeterminate cleanup error before releasing ownership when Windows termination cannot be verified. Gateway stopping similarly records failure and retains the child; successful pipe drainage remains a separate completion path.
Findings None None.
Security None None.

How this fits together

OpenClaw’s tooling shares a child-process cleanup helper for command runners and test instances. It receives shutdown requests and child lifecycle state, then signals owned processes or reports that cleanup could not be verified.

flowchart TD
  A[Command runner or test instance] --> B[Shared child cleanup]
  C[Recorded child exit state] --> B
  B --> D{Windows child already exited?}
  D -->|Yes| E[Retain incomplete cleanup]
  D -->|No| F[Existing process termination]
  E --> G[Caller diagnostics and retained ownership]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Tests +23, Other +5. Total +28 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 0 0 0 0
Tests 3 53 30 +23
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 6 1 +5
Total 4 59 31 +28

Review metrics

None.

Technical review

Best possible solution:

Keep termination tied to the original child’s live ownership and preserve unresolved descendant cleanup until it can be verified.

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

Yes, source establishes the trigger: Windows cleanup receives an exited child while inherited output remains open and current main still invokes taskkill for its PID. The contributor reports four pre-fix failures; this read-only review did not rerun them.

Is this the best way to solve the issue?

Yes. The shared-owner guard repairs the invalid targeting decision while reusing existing failure reporting, retention, and successful-drain behavior.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 86f5429e5a61.

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient. The supplied native Windows result covers the real test-instance CLI and shared termination owner: an exited leader retains a live stderr writer, no taskkill is issued, incomplete cleanup retains state, and external rescue is verified. The fixture was inspected; linked job logs could not be independently retrieved.

Label justifications:

  • P2: This repairs a concrete Windows tooling cleanup defect with a bounded development and test-workflow impact.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (linked_artifact): The supplied native Windows result covers the real test-instance CLI and shared termination owner: an exited leader retains a live stderr writer, no taskkill is issued, incomplete cleanup retains state, and external rescue is verified. The fixture was inspected; linked job logs could not be independently retrieved.
  • proof: sufficient: Contributor real behavior proof is sufficient. The supplied native Windows result covers the real test-instance CLI and shared termination owner: an exited leader retains a live stderr writer, no taskkill is issued, incomplete cleanup retains state, and external rescue is verified. The fixture was inspected; linked job logs could not be independently retrieved.

Evidence

What I checked:

  • Introduced guard and execution boundary: The guard precedes Windows taskkill invocation and returns the existing indeterminate result. POSIX signaling and explicitly selected direct-child signaling return through earlier branches. The introduced delta depends on Node child lifecycle and Windows taskkill, not the Codex contracts discussed in the broader related PR. (scripts/lib/managed-child-process.mts:169, 28b691b52671)
  • Current main and release still need the repair: Both fetched main and v2026.9.2 invoke numeric-PID taskkill without checking recorded exit. This establishes that the requested protection is still absent; no merged replacement is established by the supplied related context. (scripts/lib/managed-child-process.mts:169, 86f5429e5a61)
  • Existing callers preserve unresolved ownership: Managed command finalization throws an indeterminate cleanup error before releasing ownership when Windows termination cannot be verified. Gateway stopping similarly records failure and retains the child; successful pipe drainage remains a separate completion path. (scripts/lib/managed-child-process.mts:526, 28b691b52671)
  • Native Windows proof exercises the repaired owner: The inspected fixture uses real child processes and delegates spawn/spawnSync to their original implementations. It establishes an exited leader with a live inherited-stderr writer, asserts zero taskkill calls, verifies retained state and admission rejection, and verifies cleanup after external rescue. The captured body and comment report this fixture passing in 13.635 seconds at the reviewed head in the linked Windows job: https://github.com/openclaw/openclaw/actions/runs/34081514762/job/101617673209. Direct job retrieval failed in this review environment; the supplied positive result is retained as reported evidence, not represented as independently reread logs. No target code was executed. (test/helpers/openclaw-test-instance.cli.test-support.mjs:119, 28b691b52671)
  • Node records exit before output closure: The directly inspected Node v24.15.0 implementation sets exitCode or signalCode before emitting exit and flushing remaining stdio. This supports using those fields to retire PID targeting independently of pipe closure. Sources: Node implementation and child-process lifecycle documentation. (lib/internal/child_process.js:257)
  • Windows termination selects a numeric PID: Microsoft’s taskkill documentation defines /PID as selecting the process to terminate and /T as including its children; neither supplies the original child’s retained identity. (WindowsServerDocs/administration/windows-commands/taskkill.md)

Likely related people:

  • Peter Steinberger: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Vincent Koc: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

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 (1 earlier review cycle)
  • reviewed 2026-09-07T04:06:09.225Z sha 28b691b :: needs maintainer review before merge. :: none

@steipete

steipete commented Sep 7, 2026

Copy link
Copy Markdown
Contributor Author

Land-ready at 28b691b52671a19f4fda529cb4ce5dc7216404e2. Exact-head CI is green; native Windows test-2 passed the real inherited-stderr retention fixture with the no-taskkill assertion (13.635s), plus successful-drain, large-output deadline, exited-Gateway and diagnostic cases.

Tests-only main reproduced four intended failures. After the owner repair, all 147 local owner/sibling tests passed with two platform skips. Changed formatting/type/lint/guard checks and fresh isolated P0 review passed. Native review artifacts validated and OPENCLAW_TESTBOX=1 scripts/pr prepare-run 140753 completed without changing the reviewed head. ClawSweeper's current review has no findings or before-merge requirements.

Local commands:

node scripts/run-vitest.mjs test/scripts/managed-child-process.test.ts test/helpers/openclaw-test-instance.test.ts -t 'does not target a known-exited Windows child|does not target an exited Windows gateway|observes Windows unverified exited leader'
node scripts/run-vitest.mjs test/scripts/managed-child-process.test.ts test/helpers/openclaw-test-instance.test.ts test/scripts/run-with-env.test.ts
node scripts/check-changed.mjs -- scripts/lib/managed-child-process.mts test/scripts/managed-child-process.test.ts test/helpers/openclaw-test-instance.test.ts test/helpers/openclaw-test-instance.cli.test-support.mjs

Production/tooling +6/-1; tests/support +53/-30. No configuration, schema, permissions or timeout changes. The first review admission refused before execution due local CPU capacity; after the local checks finished, protected admission and review passed. No test or CI rerun was needed. The original node-session PR remains open for the other split replacements.

@steipete
steipete merged commit 2eae7eb into main Sep 7, 2026
191 checks passed
@steipete
steipete deleted the steipete/windows-pid-ownership-split-132180 branch September 7, 2026 04:30
@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Sep 7, 2026
@steipete

steipete commented Sep 7, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 8, 2026
Retire numeric PID targeting once the original Windows child has exited.
Preserve indeterminate descendant cleanup and existing retained-state
behavior instead of claiming termination or retargeting another owner.

Keep POSIX group signals, live Windows shutdown, direct-child signaling,
and successful output drainage unchanged. Four pre-fix regressions fail;
147 focused tests pass with two platform skips, changed checks pass, and
fresh isolated P0 review is scoped-clean. Native Windows proof follows in CI.

Split from openclaw#132180.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. scripts Repository scripts size: S 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.

1 participant