Skip to content

fix(sdk): kill a timed-out sync hook's whole process group - #6614

Merged
VascoSch92 merged 2 commits into
mainfrom
vasco/hook-timeout-kills-group
Nov 8, 2026
Merged

VascoSch92 merged 2 commits into
mainfrom
vasco/hook-timeout-kills-group

Conversation

@VascoSch92

@VascoSch92 VascoSch92 commented Nov 7, 2026 •

Copy link
Copy Markdown
Member

HUMAN:

just fixing a bug


AGENT:

Why

Command hooks run through shell=True. For a synchronous hook, subprocess.run(..., timeout=...) only kills the shell process when the timeout fires, so anything the hook started (a script, sleep, a server) keeps running in the background after the hook reports "timed out". Async hooks don't have this problem: they start in a new session and AsyncProcessManager._terminate_process kills the whole process group (or uses taskkill /T on Windows).

Summary

  • Run sync hooks with Popen(..., start_new_session=True) (POSIX) and communicate(timeout=...). On timeout, stop them with the existing _terminate_process, then re-raise so the existing TimeoutExpired branch returns the same "Hook timed out" result.
  • The rest of the method is unchanged: the result is wrapped in a CompletedProcess, so stdout/stderr/JSON parsing reads the same fields as before.
  • Ports the pinned test from [Bug]: Edge-case tests expose ~70 bugs across the SDK, agent server, tools and workspaces #6348 without its xfail marker.

Issue Number

Part of #6348 (item: "a timed-out sync hook only kills the shell; its child processes keep running (the async path kills the process group)").

How to Test

uv run pytest tests/sdk/hooks

test_timed_out_hook_does_not_leave_its_child_running fails on main (the hook's sleep 30 child is still alive after the timeout) and passes here; tests/sdk/hooks passes (153).

Type

  • Bug fix
  • Feature
  • Refactor
  • Breaking change
  • Docs / chore

🐳 Agent Server images for this PR — GHCR package, pull/run commands, and all pushed tags (click to expand)

• GHCR package: https://github.com/OpenHands/agent-sdk/pkgs/container/agent-server

Variants & Base Images

Variant Architectures Base Image Docs / Tags
java amd64, arm64 eclipse-temurin:17-jdk Link
python-slim amd64, arm64 python-node-runtime Link
python-minimal amd64, arm64 python-node-runtime Link
python amd64, arm64 python-node-runtime Link
golang amd64, arm64 golang:1.21-bookworm Link

Pull (multi-arch manifest)

# Each variant is a multi-arch manifest supporting both amd64 and arm64
docker pull ghcr.io/openhands/agent-server:6ba0544-python

Run

docker run -it --rm \
  -p 8000:8000 \
  --name agent-server-6ba0544-python \
  ghcr.io/openhands/agent-server:6ba0544-python

All tags pushed for this build

ghcr.io/openhands/agent-server:6ba0544-golang-amd64
ghcr.io/openhands/agent-server:6ba05448c76db63bfb374ffb11e2b916b1f6dd5f-golang-amd64
ghcr.io/openhands/agent-server:vasco-hook-timeout-kills-group-golang-amd64
ghcr.io/openhands/agent-server:6ba0544-golang_tag_1.21-bookworm-amd64
ghcr.io/openhands/agent-server:6ba0544-golang-arm64
ghcr.io/openhands/agent-server:6ba05448c76db63bfb374ffb11e2b916b1f6dd5f-golang-arm64
ghcr.io/openhands/agent-server:vasco-hook-timeout-kills-group-golang-arm64
ghcr.io/openhands/agent-server:6ba0544-golang_tag_1.21-bookworm-arm64
ghcr.io/openhands/agent-server:6ba0544-java-amd64
ghcr.io/openhands/agent-server:6ba05448c76db63bfb374ffb11e2b916b1f6dd5f-java-amd64
ghcr.io/openhands/agent-server:vasco-hook-timeout-kills-group-java-amd64
ghcr.io/openhands/agent-server:6ba0544-eclipse-temurin_tag_17-jdk-amd64
ghcr.io/openhands/agent-server:6ba0544-java-arm64
ghcr.io/openhands/agent-server:6ba05448c76db63bfb374ffb11e2b916b1f6dd5f-java-arm64
ghcr.io/openhands/agent-server:vasco-hook-timeout-kills-group-java-arm64
ghcr.io/openhands/agent-server:6ba0544-eclipse-temurin_tag_17-jdk-arm64
ghcr.io/openhands/agent-server:6ba0544-python-amd64
ghcr.io/openhands/agent-server:6ba05448c76db63bfb374ffb11e2b916b1f6dd5f-python-amd64
ghcr.io/openhands/agent-server:vasco-hook-timeout-kills-group-python-amd64
ghcr.io/openhands/agent-server:6ba0544-python-node-runtime-amd64
ghcr.io/openhands/agent-server:6ba0544-python-arm64
ghcr.io/openhands/agent-server:6ba05448c76db63bfb374ffb11e2b916b1f6dd5f-python-arm64
ghcr.io/openhands/agent-server:vasco-hook-timeout-kills-group-python-arm64
ghcr.io/openhands/agent-server:6ba0544-python-node-runtime-arm64
ghcr.io/openhands/agent-server:6ba0544-python-minimal-amd64
ghcr.io/openhands/agent-server:6ba05448c76db63bfb374ffb11e2b916b1f6dd5f-python-minimal-amd64
ghcr.io/openhands/agent-server:vasco-hook-timeout-kills-group-python-minimal-amd64
ghcr.io/openhands/agent-server:6ba0544-python-node-runtime-minimal-amd64
ghcr.io/openhands/agent-server:6ba0544-python-minimal-arm64
ghcr.io/openhands/agent-server:6ba05448c76db63bfb374ffb11e2b916b1f6dd5f-python-minimal-arm64
ghcr.io/openhands/agent-server:vasco-hook-timeout-kills-group-python-minimal-arm64
ghcr.io/openhands/agent-server:6ba0544-python-node-runtime-minimal-arm64
ghcr.io/openhands/agent-server:6ba0544-python-slim-amd64
ghcr.io/openhands/agent-server:6ba05448c76db63bfb374ffb11e2b916b1f6dd5f-python-slim-amd64
ghcr.io/openhands/agent-server:vasco-hook-timeout-kills-group-python-slim-amd64
ghcr.io/openhands/agent-server:6ba0544-python-node-runtime-slim-amd64
ghcr.io/openhands/agent-server:6ba0544-python-slim-arm64
ghcr.io/openhands/agent-server:6ba05448c76db63bfb374ffb11e2b916b1f6dd5f-python-slim-arm64
ghcr.io/openhands/agent-server:vasco-hook-timeout-kills-group-python-slim-arm64
ghcr.io/openhands/agent-server:6ba0544-python-node-runtime-slim-arm64
ghcr.io/openhands/agent-server:6ba0544-golang
ghcr.io/openhands/agent-server:6ba05448c76db63bfb374ffb11e2b916b1f6dd5f-golang
ghcr.io/openhands/agent-server:vasco-hook-timeout-kills-group-golang
ghcr.io/openhands/agent-server:6ba0544-golang_tag_1.21-bookworm
ghcr.io/openhands/agent-server:6ba0544-java
ghcr.io/openhands/agent-server:6ba05448c76db63bfb374ffb11e2b916b1f6dd5f-java
ghcr.io/openhands/agent-server:vasco-hook-timeout-kills-group-java
ghcr.io/openhands/agent-server:6ba0544-eclipse-temurin_tag_17-jdk
ghcr.io/openhands/agent-server:6ba0544-python-minimal
ghcr.io/openhands/agent-server:6ba05448c76db63bfb374ffb11e2b916b1f6dd5f-python-minimal
ghcr.io/openhands/agent-server:vasco-hook-timeout-kills-group-python-minimal
ghcr.io/openhands/agent-server:6ba0544-python-node-runtime-minimal
ghcr.io/openhands/agent-server:6ba0544-python-slim
ghcr.io/openhands/agent-server:6ba05448c76db63bfb374ffb11e2b916b1f6dd5f-python-slim
ghcr.io/openhands/agent-server:vasco-hook-timeout-kills-group-python-slim
ghcr.io/openhands/agent-server:6ba0544-python-node-runtime-slim
ghcr.io/openhands/agent-server:6ba0544-python
ghcr.io/openhands/agent-server:6ba05448c76db63bfb374ffb11e2b916b1f6dd5f-python
ghcr.io/openhands/agent-server:vasco-hook-timeout-kills-group-python
ghcr.io/openhands/agent-server:6ba0544-python-node-runtime

About Multi-Architecture Support

  • Each variant tag (e.g., 6ba0544-python) is a multi-arch manifest supporting both amd64 and arm64
  • Docker automatically pulls the correct architecture for your platform
  • Individual architecture tags (e.g., 6ba0544-python-amd64) are also available if needed

subprocess.run's timeout only kills the shell it started, so commands the
hook launched kept running after "Hook timed out". Run the hook in its own
session and, on timeout, stop the group with the same _terminate_process
the async hooks already use.
@github-actions

github-actions Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

REST API breakage checks (OpenAPI) — ✅ PASSED

Result: ✅ PASSED

Action log

@datadog-official

This comment has been minimized.

@github-actions

github-actions Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Coverage

Coverage Report •
FileStmtsMissCoverMissing
openhands-sdk/openhands/sdk/hooks
   executor.py2712491%68, 121–123, 128–135, 492, 502, 534–535, 547–548, 611–612, 626–627, 632–633
TOTAL54583850484% 

@all-hands-bot all-hands-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This review was posted by an AI agent (OpenHands).

Scope: In-repo change to openhands-sdk/openhands/sdk/hooks/executor.py (SDK core) fixing the pinned item in #6348 ("a timed-out sync hook only kills the shell; its child processes keep running"). The linked issue is open and labeled ready-for-dev; no maintainer decision is needed.

Mechanism review: On POSIX, sync hooks now run under Popen(start_new_session=True), so on TimeoutExpired the existing AsyncProcessManager._terminate_process reaches the whole process group (killpg SIGTERM → SIGKILL) instead of only the shell. The Windows path keeps start_new_session=False and uses the same taskkill /F /T branch the async path already uses. The exception is re-raised so the existing TimeoutExpired branch still returns the identical "Hook timed out after N seconds" result, and the CompletedProcess wrapper preserves the stdout/stderr/JSON parsing contract. The with block closes the pipes and reaps the process on all paths, so there is no fd or zombie leak. Running sync hooks in their own session mirrors the established async-hook behavior and the documented Python idiom for timeout-killable subprocesses; no public API, serialization, or persisted-shape change is involved.

Verification in this workspace (head b16dcb48):

  • uv run pytest tests/sdk/hooks → 153 passed, including the new test_timed_out_hook_does_not_leave_its_child_running.
  • The pinned test run against main's executor in a throwaway worktree fails (assert not child_alive — the hook's sleep 30 child survives the timeout), confirming the original symptom on the base revision and that this head fixes it through the real executor path, not mocked state.
  • The failing sdk-tests check on this head is test_failing_mcp_server_keeps_the_other_servers_tools[invalid-entry] (pydantic ValidationError in MCP config parsing). I reproduced that exact failure identically on main locally; it is pre-existing and unrelated to this PR, which touches no MCP or conversation code. windows-tests, cross-tests, and the Windows/macOS binary builds passed on this head.

No material correctness, security, compatibility, or acceptance-criterion defects found.

✅ APPROVED

#5796 rejects an MCP server with neither command nor url at config
validation, so {} can no longer reach the runtime and this case fails on
main. Same change as #6606.
@VascoSch92
VascoSch92 merged commit 03f461a into main Nov 8, 2026
50 checks passed
@VascoSch92
VascoSch92 deleted the vasco/hook-timeout-kills-group branch November 8, 2026 19:22
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.

2 participants