fix(tools): run_shell process-group kill + background mode; propagate cancellation - #36
Merged
Merged
Conversation
… cancellation
run_shell hung forever on long-lived commands (e.g. `npm start` → `ng serve`):
the dev-server grandchild inherited the stdout pipe, so terminating only the
direct zsh left it holding the pipe open and readDataToEndOfFile never saw EOF —
the 120s timeout fired but killed the wrong process, and Stop couldn't reach it.
- Launch commands in their own process group (posix_spawn + POSIX_SPAWN_SETPGROUP)
and SIGKILL the whole group on timeout or cancellation, so the read unblocks and
execute() always returns.
- Make ShellTool cancellation-aware via withTaskCancellationHandler.
- Mark pipe fds close-on-exec to stop concurrent spawns inheriting each other's
write-end (which defeated EOF).
- Add `background: true` (auto-detected for npm start/ng serve/vite/etc.): launch
detached, redirect output to a temp log, return promptly with pid + log path.
- ToolDispatcher: run parallel tools in a structured withTaskGroup instead of
detached Task {}, so run-task cancellation propagates into running tools.
Tests reproduce the 30s hang (now ~2s), the background fast-return, and prompt
cancellation.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Caution The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
run_shellhung forever on long-lived commands (e.g.npm start→ng serve). The dev-server grandchild inherited the stdout pipe, so terminating only the directzshleft the grandchild holding the pipe open →readDataToEndOfFile()never saw EOF →execute()never returned. The 120s timeout fired but killed the wrong process, and the app's Stop button (a between-turns flag) couldn't reach a mid-tool hang.Fix
posix_spawnwithPOSIX_SPAWN_SETPGROUP; on timeout or cancellation, SIGKILL the entire group so the read unblocks andexecute()always returns.withTaskCancellationHandlerkills the group when the task is cancelled (Stop).background: true(auto-detected fornpm start,ng serve,vite,next dev, …) launches detached, redirects output to a temp log, and returns promptly with the pid + log path — servers no longer block the agent by design.withTaskGroupinstead of detachedTask {}, so run-task cancellation propagates into running tools (parallelism + ordering preserved).Tests
New tests reproduce the exact failure and its fix:
shellTimesOutEvenWhenOrphanHoldsStdout— orphan-holds-stdout hang: 30s → ~2s, reported as a timeout.shellBackgroundReturnsPromptlyWithPid— background returns within the grace window with a pid.shellCancellationStopsPromptly— cancellation SIGKILLs and returns in ~0.4s.Full suite: 134/134 passing.
🤖 Generated with Claude Code