Repository navigation
fix: Windows cleanup targets child PIDs after they exit - #140753
Conversation
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.
|
🦞👀 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 maintainer review before merge. Reviewed September 7, 2026, 12:30 AM ET / 04:30 UTC. ClawSweeper reviewWhat this changesWindows 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 Review scores
Verification
How this fits togetherOpenClaw’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]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceTests +23, Other +5. Total +28 across 4 files. View PR surface stats
Review metricsNone. Technical reviewBest 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. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (1 earlier review cycle)
|
|
Land-ready at 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 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.tsnode 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.mjsProduction/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. |
|
Merged via squash.
|
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.
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
taskkilland 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
4648bb0a70c54599630f21ace2a28c017ca65f8b: four intended failures and one pass. Both exited-child variants invokedtaskkill; the held-pipe Gateway case reported success; the exited-leader diagnostic case attemptedtaskkilltwice.run-with-env, and unchanged successful-drain/large-output deadline cases.taskkillassertion (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.v2026.9.2also 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:
Changed checks:
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.