You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(hub): terminate child process trees on POSIX - #515
On POSIX, terminate(), restart(), and stream cancel for a startChildProcess() session only send SIGTERM to the direct child. Task runners such as vp run exit on SIGTERM but do not forward it. The real process keeps running, keeps its port, and keeps the output pipe open. Because the pipe stays open, close never fires, getResult() never resolves, and the session stays running. The Terminals "Kill" button has the same problem.
Fix
killProcessTree() now reads the process table with ps -A -o pid=,ppid=, collects all descendants, and sends SIGTERM to them before the root. This matches the Windows taskkill /T path. If ps fails, it falls back to cp.kill(). Spawn options and signal handling do not change, so Ctrl+C in the host terminal works as before.
💭 analyzed by vercel-ai-gateway/anthropic/claude-sonnet-5
🕰️ 2026-12-01 04:29 UTC
🔗 head ba65678
🤖 automated by pulls.review
{
"headSha": "ba65678a93c30eff3e5f34d76b52c90cbb81fdbb",
"result": {
"overallSummary": "Fixes a bug where `terminate()`/`restart()`/stream-cancel on POSIX only killed the direct child process, leaving orphaned grandchildren (e.g. task runners that don't forward SIGTERM) running and holding ports/pipes open, which prevented `close` and `getResult()` from ever resolving. `killProcessTree()` now enumerates the full process tree via `ps` and signals it bottom-up, mirroring the existing Windows `taskkill /T` path; a related fix ensures `restart()` doesn't prematurely close the new run's stream while waiting for the old tree to die.",
"groups": [
{
"key": "core-fix",
"label": "POSIX tree kill fix",
"summary": "Makes `killProcessTree()` walk the process table on POSIX (via `ps -A -o pid=,ppid=`) and SIGTERM every descendant before the root, matching the existing Windows `taskkill /T` behavior, so task runners that don't forward SIGTERM no longer leave orphaned children holding ports/pipes open. Also fixes `restart()` so the old run's stream/listeners aren't torn down prematurely while the old tree is being killed, by bumping `runId` before awaiting `killRun` and letting `settle`/data handlers use `currentRun` correctly instead of bailing out based on a stale check.",
"category": "core",
"filePaths": [
"packages/hub/src/node/host-terminals.ts"
],
"critical": true,
"lineNotes": [
{
"path": "packages/hub/src/node/host-terminals.ts",
"side": "additions",
"line": 58,
"text": "Children are terminated before their parents (reversed tree order) so a parent can't respawn/reparent a child before it's killed."
},
{
"path": "packages/hub/src/node/host-terminals.ts",
"side": "additions",
"line": 65,
"text": "Falls back silently to `cp.kill()` if `ps` fails (e.g. not available), matching prior behavior for the direct child only."
}
]
},
{
"key": "tests",
"label": "Terminal lifecycle tests",
"summary": "Adds regression tests: one spawns a nested child process and asserts `terminate()` kills the whole tree, and one verifies that during `restart()` the old run's stream keeps flowing (and resolves without `exitCode`) while the new run's output is still delivered to the sink.",
"category": "tests",
"filePaths": [
"packages/hub/src/node/__tests__/host-terminals.test.ts"
],
"fileNotes": [
{
"path": "packages/hub/src/node/__tests__/host-terminals.test.ts",
"text": "Mocks `tinyexec`'s `exec` to intercept the `ps` snapshot call and deliberately delay it until the old process closes, to exercise the race condition fixed in `restart()`."
}
]
}
],
"schemaVersion": 1,
"source": "llm",
"generatedAt": "2026-12-01T04:29:56.683Z",
"model": "vercel-ai-gateway/anthropic/claude-sonnet-5",
"locale": "en"
}
}
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
A critical restart race allows the outgoing command to permanently close the shared stream during process snapshotting, discarding replacement output and causing subsequent restarts to fail.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Restart can spawn a replacement before the old process tree exits, risking EADDRINUSE; bounded shutdown waiting and a regression test with a delayed-shutdown descendant are needed.
No open issues 🎉
1 previously missed issue
In code that hasn't changed since last review
Wait for old process tree to exit before restarting
packages/hub/src/node/host-terminals.ts:75
process.kill() sends SIGTERM but does not wait for the processes to exit. Returning here lets restart() spawn the replacement while an old descendant is still doing asynchronous cleanup and holding its listening port, which can cause EADDRINUSE. Wait for the old tree to stop using a bounded shutdown policy, and add a restart test with a descendant that delays shutdown and reuses the same port.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On POSIX,
terminate(),restart(), and stream cancel for astartChildProcess()session only send SIGTERM to the direct child. Task runners such asvp runexit on SIGTERM but do not forward it. The real process keeps running, keeps its port, and keeps the output pipe open. Because the pipe stays open,closenever fires,getResult()never resolves, and the session stays running. The Terminals "Kill" button has the same problem.Fix
killProcessTree()now reads the process table withps -A -o pid=,ppid=, collects all descendants, and sends SIGTERM to them before the root. This matches the Windowstaskkill /Tpath. Ifpsfails, it falls back tocp.kill(). Spawn options and signal handling do not change, so Ctrl+C in the host terminal works as before.🤖 Generated with Claude Code