Skip to content

fix(exec): kill child process tree on timeout to prevent orphaned tasks#378

Open
lunareed720 wants to merge 1 commit intosipeed:mainfrom
lunareed720:fix/exec-timeout-process-tree
Open

fix(exec): kill child process tree on timeout to prevent orphaned tasks#378
lunareed720 wants to merge 1 commit intosipeed:mainfrom
lunareed720:fix/exec-timeout-process-tree

Conversation

@lunareed720
Copy link

@lunareed720 lunareed720 commented Feb 17, 2026

Summary

This fixes orphaned background processes when exec commands time out.

What changed

  • Run shell commands in a dedicated process group on Unix (Setpgid: true)
  • On timeout/cancel, terminate the full process tree instead of only the parent shell
    • Unix: kill process group (kill -SIGKILL -pgid)
    • Windows: taskkill /T /F /PID fallback
  • Switch ExecTool execution flow to Start + Wait with explicit timeout path and cleanup
  • Add regression test (Unix): verifies timed-out command with spawned child (sleep) does not leave child process alive

Why

Issue #311 reports that failed/timed-out shell commands keep running in background. This can leak resources and degrade long-running agent stability.

Testing

  • go test ./pkg/tools -run TestShellTool -count=1

Closes #311

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.

[BUG] Shell process need kill

1 participant