Skip to content

fix(hub): kill the whole child-process tree on Windows - #407

Merged
antfu merged 2 commits into
mainfrom
fix/hub-kill-child-process-tree-windows-tinyexec
Sep 25, 2026
Merged

antfu merged 2 commits into
mainfrom
fix/hub-kill-child-process-tree-windows-tinyexec

Conversation

@antfubot

Copy link
Copy Markdown
Collaborator

Description

Reworks #404 (from @zahidzorbaz, whose fork branch we can't push to) so the Windows tree kill goes through tinyexec instead of a hand-rolled node:child_process spawn.

On Windows, stopping a startChildProcess() session left the real program running: tinyexec runs anything that isn't a .exe/.com (including node_modules/.bin/*.cmd shims) through cmd.exe /d /s /c, so the pid the host holds is the wrapper's, and cp.kill() doesn't reach descendants.

This PR keeps the approach and behaviour of #404 unchanged:

  • killProcessTree() in host-terminals.ts: on Windows it runs taskkill /pid <pid> /T /F and falls back to cp.kill(); elsewhere it is cp.kill() as before.
  • Used in terminate(), restart() and the stream's cancel(); restart() waits for the old tree to exit so the new run can take the same ports.
  • Host-initiated stops report status: 'stopped', exitCode: undefined, killed: true on every platform.

What changed vs #404: taskkill is spawned with tinyexec's exec (already a dependency and already used in this file) rather than raw spawn plus manual promise/event wiring — tinyexec itself has no built-in tree kill (kill() is plain child.kill), so taskkill stays, but the wrapper shrinks from ~20 lines to ~10.

Linked Issues

Fixes #402
Supersedes #404

Additional context

Tests are carried over verbatim from #404: a describe.runIf(win32) block exercising a real .cmd shim (skipped on Linux/macOS CI). On Linux: pnpm lint, pnpm knip, pnpm test, pnpm typecheck, pnpm build all pass.

Created with the help of an agent, based on the original work in #404.

zahidzorbaz and others added 2 commits September 25, 2026 00:38
On Windows, tinyexec runs `.cmd` shims (e.g. `node_modules/.bin/vitest.cmd`)
through `cmd.exe`, so `terminate()`, `restart()` and stream cancel only killed
the wrapper and left the real program running and holding its ports. Kill
the tree with `taskkill /T /F` there, wait for it before `restart()` spawns
the next run, and keep reporting host-initiated kills as `stopped` with an
`undefined` exit code on every platform.

Fixes #402

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@coldtea-pr-lens

coldtea-pr-lens Bot commented Sep 25, 2026 •

Copy link
Copy Markdown

◈ PR Lens

🟢 +0 new · 🟠 ~1 changed · 🔴 -0 removed · 1 flow · 3 files · commit dbc8449


Architecture

Architecture diagram for devframes/devframe at dbc8449

1 component touched across 2 lanes.

Play the interactive walkthrough


Data flow

Data flow diagram for devframes/devframe at dbc8449

Terminating and restarting child process runs

Follow each request, response and payload


View

  • Architecture lens
  • Data flow lens
  • Expand every detail

Tip

Run npx @coldtea/pr-lens-cli analyze --base origin/main on a branch, then npx @coldtea/pr-lens-cli render .pr-lens/graph.json. Same lenses, your own model key, before the pull request exists

🪧 More tips
  • Run npx skills add coldteadotai/pr-lens, then tell your coding agent: "Diagram the change you just made with PR Lens and attach it to the pull request."
  • Untick Architecture lens or Data flow lens under View to hide a diagram, or tick Expand every detail to open every section. The comment redraws in a few seconds
  • Click the link under each diagram to open it on a canvas you can zoom, pan and step through
  • The diagrams are links. Click one to open it on the canvas, then press W or click play to walk through the change
  • Open a diagram on the canvas, then press W or click play to walk through the change one step at a time
  • The CLI's render reads .github/pr-lens.yml and applies your renames, exclusions and lane pins at draw time
  • Set github.comment.collapsed: true in .github/pr-lens.yml to fold the comment behind one View architecture and data flow row. Drawing still runs on every push
  • Set github.draw: on-demand in .github/pr-lens.yml and PR Lens stops drawing every push. Comment @pr-lens draw on a pull request when you want that one drawn
  • Add .github/workflows/pr-lens.yml with coldteadotai/pr-lens/packages/action@v0 and your model provider's key as its api-key to run PR Lens from your own CI. Any /chat/completions endpoint works
  • Push a commit and the comment redraws for the new head. A slow older run never overwrites a newer one
  • Switch GitHub to dark mode and the diagrams follow. The moving dots are this pull request's data in motion

Thanks for using PR Lens! It's built by Coldtea, free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

@vercel

vercel Bot commented Sep 25, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
devframe Skipped Skipped Sep 25, 2026 12:46am UTC

@antfu
antfu merged commit 781ceed into main Sep 25, 2026
14 checks passed
@antfu
antfu deleted the fix/hub-kill-child-process-tree-windows-tinyexec branch September 25, 2026 00:50

This branch was previously deployed

1 inactive deployment
Preview — dbc84499 Deployed Sep 25, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(hub): terminate()/restart() of a startChildProcess session orphans the real process on Windows

3 participants