[Bug] Cancelling or timing out execute_bash on Windows leaves the command's child process running
Description
On Windows, BashExecutor runs commands as cmd /c <command>. When a command is cancelled or times out, killProcessTree (source/services/bash-executor.ts, win32 branch around lines 354-366) only calls proc.kill() on that cmd.exe wrapper. The real program that cmd.exe started keeps running. The tool reports "cancelled" or "timed out" and the agent moves on, but the process is still alive, so a dev server that hits the 2-minute default timeout keeps holding its port.
On Linux and macOS this is handled with a process group (see the tests around bash-executor.spec.ts:581). Those tests are skipped on Windows ("no process groups"), so nothing covers it.
Environment
- OS: Windows 11 (10.0.26300)
- Node version: 22.22.3
- Nanocoder version: 1.31.0 (main at 5c2e693)
- Provider / Model: not relevant (reproduced by calling the executor directly)
Steps to Reproduce
- On Windows, create
sleeper.jscontainingsetInterval(() => {}, 1000);. - Run
node sleeper.js MARKER1throughbashExecutor.execute(...)with anAbortSignal. - Wait 2 seconds, then abort the signal.
- Wait 4 seconds and look for the process:
Get-CimInstance Win32_Process | Where-Object { $_.CommandLine -like '*MARKER1*' -and $_.Name -eq 'node.exe' }. - Repeat with
{timeoutMs: 1500}instead of the signal.
Expected Behavior
The whole process tree is stopped, so no node.exe is left.
Actual Behavior
The tool result says Cancelled via AbortSignal (or Command timed out after 1500ms), but 4 seconds later the node.exe is still running:
[abort] 4s after cancel: node processes still running = ["38172"]
[timeout] 4s after timeout: node processes still running = ["18456"]
Suggested Fix
- Use the same approach as
source/services/lifecycle-hooks.ts(thekillProcessTreearound lines 388-412), which already runstaskkill /pid <pid> /T /Fon Windows. I checked thattaskkill /T /Fon thecmd.exepid stops the child that the current code leaves behind. - Best is to move that helper into a shared util and use it in
bash-executor.ts. - Add a Windows-only test (cancel by
AbortSignaland by timeout, then check that no process is left), and addbash-executor.spec.tsto the Windows CI job. source/custom-tools/handler.ts:176-205has the same gap and documents it as a known limitation. It could use the same helper.
Additional Context
- Closed #541 listed
taskkill /T /Ffor Windows in its suggested fix, but the merged fix (#547) only covers POSIX process groups. - [x] I have searched existing issues to ensure this is not a duplicate
- [x] I can reproduce this issue consistently
- [x] This issue occurs with the latest version of nanocoder
@addyCooks can i go for it
Go for it @Dhirenderchoudhary !