[Bug] On Windows jobs started with `start /b` are not tracked, so stopAll() and exit leave them running
Description
After a command finishes, execute_bash keeps track of any process group that is still alive so stopAll() can stop it. On Windows the liveness check only asks whether the leader (cmd.exe) is alive. start /b ... returns right away and cmd.exe exits, so the background process is never tracked.
Environment
- OS: Windows 11 Home 10.0.26300
- Node version: v22.22.3
- Nanocoder version: 1.32.0 (built from main at eb7dee57)
- Provider: Not provider-specific
- Model: Not model-specific
Steps to Reproduce
await bashExecutor.execute('start /b node -e "setTimeout(()=>{},60000)" ncmarker123').promiseawait bashExecutor.stopAll()- Wait 1.5 seconds, then look for
node.exewithncmarker123in its command line (Get-CimInstance Win32_Process).
Expected Behavior
No such process is left.
Actual Behavior
The node process is still running (pid 7048 in my run) and has to be killed by hand.
Additional Context
- [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 (main)
Suggested fix:
source/services/bash-executor.ts:63-65(isGroupAlive): on Windowsreturn proc.exitCode === null && ...is false oncecmd.exeexits. Check for child processes of the leader's pid instead (for examplewmic/Get-CimInstancebyParentProcessId), or keep the job object.trackLeftovers(:762) then adds the process andstopAll()can usesignalProcessTree.- Add a Windows-only test like the steps above.
Related: #1657 / PR #1699 (cancel and timeout), #1833 (leftover commands on exit).
I'd like to pick this up. I reproduced it on Windows 11 (10.0.26300), Node 22.12, upstream main at 214823ce, 3 out of 3 runs:
command complete: exitCode = 0
tracked leftovers: 0
after execute : 29124 parent=32712 node.exe
after stopAll : 29124 parent=32712 node.exe
parent 32712 alive? no (cmd.exe already exited)
taskkill /T on parent: ERROR: The process "32712" not found.
Besides the missing tracking, there is a second gap: tracking the leftover alone would not fix this. Once cmd.exe has exited, taskkill /pid <cmd> /T fails with "not found", so killProcessTree / signalProcessTree also need to reach the orphan by its own pid. The orphan still reports the dead cmd.exe pid as its ParentProcessId, so we can find it that way.
Plan:
- In
finish()on Windows, when the shell has exited, list the processes whoseParentProcessIdis the shell pid. Keep only processes created after the shell started, so a recycled pid is never matched.taskkill /Ton each of them then covers whatever they started. - Track the pids it finds as leftovers.
isGroupAliveon Windows then checks those pids instead of thecmd.exeexit code, andstopAll()/killAll()runtaskkill /pid <pid> /T /Fon each one. - Use
Get-CimInstance Win32_Processrather thanwmic, which is no longer installed on current Windows 11 builds (it is missing here). The PowerShell call takes about 350–400 ms here, so do the lookup once when the command exits, not in the 1 s prune loop. The prune loop can check the tracked pids withprocess.kill(pid, 0). - Add a Windows-only test that follows the steps in the issue and checks that the marker process is gone after
stopAll().
I looked at a Job Object too. Node has no API for one, so it would need a native addon or a helper process, which seems like too much for this fix. Happy to change direction if you'd prefer something else.