Skip to content

fix(process): handle async spawn errors in taskkill force-kill fallback - #101409

Closed
krissding wants to merge 1 commit into
openclaw:mainfrom
krissding:fork/fix/taskkill-async-error
Closed

krissding wants to merge 1 commit into
openclaw:mainfrom
krissding:fork/fix/taskkill-async-error

Conversation

@krissding

Copy link
Copy Markdown
Contributor

What Problem This Solves

Closes #101381

In src/process/exec.ts, the force-kill taskkill fallback on Windows spawns taskkill /PID /T /F inside a try/catch block. However, Node's spawn() does not throw synchronously when the binary is missing or fails to execute — it emits an 'error' event asynchronously. The catch block (child.kill("SIGKILL")) never executes, so the child process tree is permanently leaked.

This happens specifically at the force-kill site (line 546), which is the safety-net fallback after the first graceful taskkill attempt. If taskkill.exe can't be spawned (missing system32 path, misconfigured environment, etc.), the child process and its descendants silently leak.

Why This Change Was Made

The fix adds an 'error' event listener on the spawned taskkill process that calls child.kill("SIGKILL") — mirroring the existing catch-block fallback. Both the sync catch and the async 'error' handler now produce the same final outcome.

The change is minimal: 3 added lines that save the spawn result and attach the error handler.

Evidence

New regression test: "falls back to SIGKILL when force-kill taskkill spawn emits async error"

The test simulates the Windows kill path with vi.spyOn(process, 'platform', 'get').mockReturnValue('win32'):

  1. Spawns a child with killProcessTree: true and a short timeout
  2. Advances timers past the timeout to trigger the force-kill spawn
  3. Emits an 'error' event on the spawned taskkill process
  4. Asserts child.kill("SIGKILL") was called

All tests pass (20/20)

$ npx vitest run src/process/exec.test.ts --no-coverage --pool forks

 Test Files  1 passed (1)
      Tests  20 passed (20)
   Start at  14:17:20
   Duration  2.38s

Not tested

  • Real Windows taskkill.exe behavior (fix verified through Vitest mocking on Linux)
  • End-to-end process tree cleanup on a Windows machine

Merge Risk

Low. The change:

  • Adds 3 lines (error listener on spawned process)
  • Only affects the Windows process.platform === "win32" code path
  • Both the sync catch and async error handler call the same child.kill("SIGKILL")
  • No new dependencies, no data model changes, no config changes

Node's spawn() emits 'error' asynchronously when the binary is missing or
fails to execute. The try/catch at the force-kill taskkill site (line 546)
only catches synchronous throws, so an async spawn error permanently
leaks the child process tree on Windows.

Add an 'error' event listener that falls back to child.kill("SIGKILL"),
mirroring the existing catch-block behavior.

Fixes openclaw#101381

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@clawsweeper

clawsweeper Bot commented Jul 7, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed July 7, 2026, 2:35 AM ET / 06:35 UTC.

Summary
The PR adds an async error handler for the Windows taskkill /F force-kill fallback and a mocked regression test for that path.

PR surface: Source +3, Tests +79. Total +82 across 2 files.

Reproducibility: yes. for source-level reproduction: current source returns after taskkill spawns that lack async error listeners, and a focused Node check confirms missing executables emit error instead of throwing through the surrounding try/catch. No live Windows end-to-end reproduction was attached.

Review metrics: 1 noteworthy metric.

  • Taskkill spawn coverage: 1 changed, 2 sibling sites unchanged. All three taskkill launches use the same async spawn contract, so a one-site handler can leave the linked bug partially fixed.

Root-cause cluster
Relationship: fixed_by_candidate
Canonical: #101381
Summary: This PR explicitly targets the open Windows taskkill async spawn error issue, but the current patch needs repair before it is a complete candidate fix.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge readiness
Overall: 🦪 silver shellfish
Proof: 🦪 silver shellfish
Patch quality: 🦪 silver shellfish
Result: blocked until real behavior proof from a real setup is added.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • Handle async taskkill errors consistently across all Windows cleanup taskkill spawns.
  • [P1] Fix the eslint(curly) failure in the added regression test.
  • [P1] Add redacted live Windows/runtime proof or logs for the cleanup path if feasible.

Proof guidance:

  • [P1] Needs real behavior proof before merge: The PR body provides mocked Vitest output only; the contributor should add redacted live Windows/runtime proof or logs if feasible, and updating the PR body should trigger a fresh ClawSweeper review. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Risk before merge

  • [P1] No live Windows or runtime proof is attached; the PR body only shows mocked Vitest output, so the real process cleanup path remains unproven.

Maintainer options:

  1. Decide the mitigation before merge
    Route the Windows taskkill launches through one small helper, or equivalent shared logic, so every taskkill child observes async spawn failures and falls back to direct child.kill("SIGKILL") when appropriate.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Next step before merge

  • [P1] Contributor follow-up is needed for the incomplete taskkill error handling, lint failure, and missing real behavior proof; ClawSweeper should not run a repair lane until the contributor-owned proof gate is satisfied.

Security
Cleared: The diff only changes process cleanup fallback handling and a test, with no new dependencies, workflow changes, secrets handling, or package-resolution surface.

Review findings

  • [P2] Handle errors on every taskkill spawn — src/process/exec.ts:550-552
  • [P2] Add braces around the spawn-count branch — src/process/exec.test.ts:459
Review details

Best possible solution:

Route the Windows taskkill launches through one small helper, or equivalent shared logic, so every taskkill child observes async spawn failures and falls back to direct child.kill("SIGKILL") when appropriate.

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

Yes for source-level reproduction: current source returns after taskkill spawns that lack async error listeners, and a focused Node check confirms missing executables emit error instead of throwing through the surrounding try/catch. No live Windows end-to-end reproduction was attached.

Is this the best way to solve the issue?

No: adding the handler only to the delayed force-kill spawn is narrower than the bug boundary because sibling taskkill spawns in the same cleanup helper still share the async-error failure mode.

Full review comments:

  • [P2] Handle errors on every taskkill spawn — src/process/exec.ts:550-552
    This adds an error fallback only for the delayed /F taskkill child, but the same function still returns after the initial process-tree taskkill and the non-tree Windows taskkill without attaching error listeners. Since Node emits error when a spawn fails, those paths can still miss the direct child.kill("SIGKILL") fallback and this PR would close the linked bug while leaving the same failure mode in place.
    Confidence: 0.9
  • [P2] Add braces around the spawn-count branch — src/process/exec.test.ts:459
    The current head fails check-lint on this changed test line with eslint(curly). Add braces around the if (spawnCount === 1) branch so the focused regression test can pass the repository lint gate.
    Confidence: 0.99

Overall correctness: patch is incorrect
Overall confidence: 0.9

AGENTS.md: found and applied where relevant.

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

Label changes

Label changes:

  • add P2: This is a focused Windows process cleanup bugfix PR with limited blast radius but concrete merge blockers.
  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦪 silver shellfish.
  • add status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The PR body provides mocked Vitest output only; the contributor should add redacted live Windows/runtime proof or logs if feasible, and updating the PR body should trigger a fresh ClawSweeper review. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Label justifications:

  • P2: This is a focused Windows process cleanup bugfix PR with limited blast radius but concrete merge blockers.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦪 silver shellfish.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The PR body provides mocked Vitest output only; the contributor should add redacted live Windows/runtime proof or logs if feasible, and updating the PR body should trigger a fresh ClawSweeper review. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed

PR surface:

Source +3, Tests +79. Total +82 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 4 1 +3
Tests 1 79 0 +79
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 83 1 +82

Acceptance criteria:

  • [P1] pnpm lint --threads=8.
  • [P1] pnpm test src/process/exec.test.ts src/process/exec.windows.test.ts.

What I checked:

  • Repository policy read: The root policy was read fully and applied because this PR touches core process cleanup, where the review requires source, tests, dependency-contract proof, sibling-surface checks, and history. (AGENTS.md:1, 33163d427391)
  • Current source has multiple taskkill spawn sites: runCommandWithTimeout launches taskkill for initial process-tree cleanup, delayed /F cleanup, and non-tree Windows cleanup; current main has synchronous catches but no taskkill child error listener at those launch sites. (src/process/exec.ts:526, 33163d427391)
  • PR handles only the delayed force-kill spawn: The diff attaches an error listener only to the delayed /F taskkill child and does not change the initial process-tree taskkill spawn or the non-tree Windows taskkill spawn. (src/process/exec.ts:546, 4cf26f9d1741)
  • Dependency contract and focused probe: Node documents that a ChildProcess emits error when the process could not be spawned; a focused Node probe showed a missing executable did not throw through try/catch and instead emitted error with ENOENT. (nodejs.org)
  • Adjacent Windows coverage: Current Windows-specific exec coverage verifies timeout cleanup spawns trusted System32 taskkill with /T /F, but it does not cover async taskkill child error events. (src/process/exec.windows.test.ts:485, 33163d427391)
  • CI lint failure: The live check-lint job fails on the new test at src/process/exec.test.ts:459:31 with eslint(curly) for the one-line if branch. (src/process/exec.test.ts:459, 4cf26f9d1741)

Likely related people:

  • vincentkoc: Recent path history shows several src/process/exec.ts changes, including the trusted System32 taskkill resolver and adjacent Windows exec tests. (role: recent area contributor; confidence: high; commits: a192b2ea52b3, 66b94ba577b8, 1425bb3a0318; files: src/process/exec.ts, src/process/exec.windows.test.ts)
  • sauerdaniel: Authored the graceful process-tree termination helper that defines the related Windows taskkill escalation behavior, even though this PR changes the direct exec cleanup path. (role: adjacent feature contributor; confidence: medium; commits: 20957efa4674; files: src/process/kill-tree.ts)
  • mbelinky: Recent path history ties command-job timeout cleanup to runCommandWithTimeout, and src/cron/command-runner.ts currently exercises killProcessTree: true through this process helper. (role: feature caller contributor; confidence: medium; commits: b8adc11977ab; files: src/process/exec.ts, src/cron/command-runner.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

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.

How this review workflow works
  • 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.

@clawsweeper clawsweeper Bot added 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. P2 Normal backlog priority with limited blast radius. labels Jul 7, 2026
@steipete

steipete commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Closing as a duplicate of #101392.

#101409 correctly identifies the asynchronous taskkill /F spawn-error hole, but it covers only the delayed force-kill branch. #101392 is the earlier, broader canonical base: it centralizes taskkill spawning, handles synchronous and asynchronous failures for graceful, forced, and non-tree paths, falls back to direct SIGKILL, and covers the sibling kill-tree helper.

Thank you for the precise regression test. A failure mode not covered by those canonical paths would be new evidence to reopen or split follow-up work.

@steipete steipete closed this Jul 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: S status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: taskkill fallback swallows spawn errors, permanently leaking Windows process trees

2 participants