Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@

## [Unreleased]

## [v0.51.304] — 2026-06-06 — Release JT (stage-p2a — un-held terminal reaper fix + opt-in Docker GPU image)

### Fixed
- **Embedded-terminal descendants are now reaped without clobbering unrelated subprocess exit codes.** Terminal descendants reparented to the WebUI process could linger as zombies. The reaper now runs `os.waitpid(-terminal_pgid, WNOHANG)` scoped to the terminal's own process group (terminals spawn with `start_new_session=True`, so the child's PID is its PGID) instead of a process-wide `waitpid(-1)` — the latter could reap an unrelated WebUI subprocess (update/git/provider) before its owner called `.wait()`, silently coercing that child's real exit code to `0`. Bounded by a 64-iteration limit, lock-guarded, and run on both reader cleanup and terminal close. (#3725 fixes #2577, @rodboev)

### Added
- **Optional GPU runtime image path.** The default image stays CPU-only. Building with `--build-arg INSTALL_GPU_LIBS=1` installs VA-API user-space libraries for users passing through host GPU devices, and `docker_init.bash` now preserves Docker `--group-add` supplemental device groups (e.g. `render`/`video` for `/dev/dri` access) when dropping privileges to the runtime user. With the default `INSTALL_GPU_LIBS=0` this is a no-op. (#3721 addresses #3243, @rodboev)

## [v0.51.303] — 2026-06-06 — Release JS (stage-p1a — low-risk fixes: cron toggle, config var expansion, git-discard hardening)

### Fixed
Expand Down
20 changes: 20 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,26 @@ RUN apt-get update -y --fix-missing --no-install-recommends \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

# Optional GPU user-space acceleration libraries for users who pass through
# host GPU devices. The default image remains CPU-only.
ARG INSTALL_GPU_LIBS=0
RUN if [ "$INSTALL_GPU_LIBS" = "1" ]; then \
apt-get update -y --fix-missing --no-install-recommends \
&& apt-get install -y --no-install-recommends \
libva2 \
vainfo \
mesa-va-drivers \
&& if apt-cache show intel-media-va-driver-non-free >/dev/null 2>&1; then \
apt-get install -y --no-install-recommends intel-media-va-driver-non-free; \
else \
echo "intel-media-va-driver-non-free is not available from the configured Debian repositories; skipping Intel non-free VA-API driver."; \
fi \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*; \
else \
echo "Skipping optional GPU user-space acceleration libraries (INSTALL_GPU_LIBS=0)."; \
fi

# UTF-8
RUN localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8
ENV LANG=en_US.utf8
Expand Down
30 changes: 30 additions & 0 deletions api/terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ def put_output(self, event: str, payload: dict) -> None:
_spawn_supervisor_started = False
_spawn_supervisor_lock = threading.Lock()
_spawn_supervisor_thread: threading.Thread | None = None
_terminal_descendant_reaper_lock = threading.Lock()
_TERMINAL_DESCENDANT_REAPER_LIMIT = 64
Comment on lines +92 to +93

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Global lock over-serializes independent PGIDs

_terminal_descendant_reaper_lock is process-wide, so two concurrent calls for different terminal sessions block each other even though waitpid(-pgid_A, …) and waitpid(-pgid_B, …) are completely independent at the kernel level. The lock is only required to prevent two callers from racing on the same terminal's PGID. In practice the impact is negligible (each call exits after one ECHILD in the common case), but a per-session lock stored on TerminalSession would be more precise if this code ever needs to scale to many concurrent terminal closings.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!



@dataclass
Expand Down Expand Up @@ -131,6 +133,32 @@ def _reap_abandoned_spawn(proc: subprocess.Popen) -> bool:
return True


def _reap_terminal_descendants(
terminal_pgid: int,
limit: int = _TERMINAL_DESCENDANT_REAPER_LIMIT,
) -> int:
"""Reap exited descendants that still belong to a terminal-owned process group."""
if not _TERMINAL_SUPPORTED:
return 0
try:
terminal_pgid = abs(int(terminal_pgid))
except (TypeError, ValueError):
return 0
if terminal_pgid <= 0:
return 0
reaped = 0
with _terminal_descendant_reaper_lock:
for _ in range(max(0, int(limit))):
try:
pid, _status = os.waitpid(-terminal_pgid, os.WNOHANG)
except (ChildProcessError, OSError):
break
if pid == 0:
break
reaped += 1
return reaped


def _spawn_supervisor_loop() -> None:
while True:
request = None
Expand Down Expand Up @@ -248,6 +276,7 @@ def _reader_loop(term: TerminalSession) -> None:
finally:
term.closed.set()
code = term.proc.poll()
_reap_terminal_descendants(term.proc.pid)
term.put_output("terminal_closed", {"exit_code": code})


Expand Down Expand Up @@ -416,6 +445,7 @@ def close_terminal(session_id: str) -> bool:
os.close(term.master_fd)
except OSError:
pass
_reap_terminal_descendants(term.proc.pid)
return True


Expand Down
23 changes: 23 additions & 0 deletions docker_init.bash
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,29 @@ if [ "A${whoami}" == "Aroot" ]; then
chmod 600 "$ENV_FILE" || error_exit "Failed to secure $ENV_FILE"
export _HW_ROOT_ENV_PATH="$ENV_FILE"

# Preserve Docker --group-add supplemental groups (for example render/video
# for /dev/dri GPU access) when dropping privileges. `su` rebuilds the target
# user's groups from /etc/group, so host-passed numeric groups must be made
# visible to hermeswebui before re-entering as the runtime user.
for gid in $(id -G); do
if [ "$gid" = "0" ] || [ "$gid" = "$WANTED_GID" ]; then
continue
fi
group_name="$(getent group "$gid" | cut -d: -f1 || true)"
if [ -z "$group_name" ]; then
group_name="hostgpu${gid}"
groupadd -g "$gid" "$group_name" 2>/dev/null || true
group_name="$(getent group "$gid" | cut -d: -f1 || true)"
fi
if [ -z "$group_name" ]; then
echo "!! WARNING: Could not create supplemental group for GID $gid; GPU device access may be unavailable"
continue
fi
if [ -n "$group_name" ]; then
usermod -a -G "$group_name" hermeswebui 2>/dev/null || echo "!! WARNING: Could not add hermeswebui to supplemental group $group_name ($gid)"
fi
Comment on lines +281 to +287

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 The if [ -n "$group_name" ] check on line 285 is unreachable dead code. The continue two lines above already guarantees that group_name is non-empty when execution reaches this point — any empty-group_name path has already bailed out. The guard adds noise and could mislead future readers into thinking there is a case where group_name is empty here.

Suggested change
if [ -z "$group_name" ]; then
echo "!! WARNING: Could not create supplemental group for GID $gid; GPU device access may be unavailable"
continue
fi
if [ -n "$group_name" ]; then
usermod -a -G "$group_name" hermeswebui 2>/dev/null || echo "!! WARNING: Could not add hermeswebui to supplemental group $group_name ($gid)"
fi
if [ -z "$group_name" ]; then
echo "!! WARNING: Could not create supplemental group for GID $gid; GPU device access may be unavailable"
continue
fi
usermod -a -G "$group_name" hermeswebui 2>/dev/null || echo "!! WARNING: Could not add hermeswebui to supplemental group $group_name ($gid)"

done

# restart the script as hermeswebui set with the correct UID/GID this time
echo "-- Restarting as hermeswebui user with UID ${WANTED_UID} GID ${WANTED_GID}"
exec su -s /bin/bash -c "exec \"${script_fullname}\"" hermeswebui || error_exit "subscript failed"
Expand Down
75 changes: 75 additions & 0 deletions docs/docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,80 @@ isolated Hermes home and follow
> for a one-off root run, use `sudo -E docker compose up -d` and verify the
> rendered mount with `docker compose config` first.

## Optional GPU runtime image

The default Hermes WebUI Docker image stays CPU-only. GPU user-space packages
are installed only when you build a custom image with the opt-in build arg:

```bash
docker build --build-arg INSTALL_GPU_LIBS=1 -t hermes-webui:gpu .
```

That build path installs VA-API basics (`libva2`, `vainfo`), AMD Mesa VA-API
drivers (`mesa-va-drivers`), and the Intel non-free media driver when that
package is available from the configured Debian repositories. NVIDIA host
runtime tooling is not installed into the app image; use the NVIDIA Container
Toolkit on the host and pass GPUs through at runtime.

GPU passthrough still depends on host drivers, Docker runtime support, and
device mappings. The commands below are configuration guidance for a suitable
Linux Docker host; they are not a claim that native GPU passthrough was verified
in this workspace.

### Intel and AMD VA-API

Expose the host render devices and add the runtime user to the common video and
render groups:

```bash
docker run --rm \
--device /dev/dri:/dev/dri \
--group-add video \
--group-add render \
hermes-webui:gpu vainfo
```

For Compose, add the same mapping to a custom service definition:

```yaml
services:
hermes-webui:
image: hermes-webui:gpu
devices:
- /dev/dri:/dev/dri
group_add:
- video
- render
```

`vainfo` should list the VA-API driver and supported profiles when the host
driver stack and container permissions are correct. The container entrypoint
preserves Docker-provided supplemental groups before it drops privileges to the
`hermeswebui` runtime user, so the WebUI process keeps access to `/dev/dri`.

### NVIDIA

Install and configure the NVIDIA Container Toolkit on the host first, then use
Docker's GPU runtime flag:

```bash
docker run --rm --gpus all hermes-webui:gpu nvidia-smi
```

For Compose, use a custom service with GPU access enabled:

```yaml
services:
hermes-webui:
image: hermes-webui:gpu
gpus: all
```

If `nvidia-smi` is unavailable or reports no devices, fix the host NVIDIA driver
and container toolkit setup before debugging Hermes WebUI. The container image
only supplies the WebUI plus optional user-space media libraries; it cannot
provide host kernel drivers or the NVIDIA runtime.

## Scheduled jobs and the gateway daemon

**Symptom**: Cron jobs created in the Tasks panel never fire. System Settings or Tasks shows:
Expand Down Expand Up @@ -347,6 +421,7 @@ volumes:
- #1399 — UID alignment in compose files (fixed in v0.50.260 via PR #1428 + this guide)
- #3012 — host `localhost` API URLs fail from Docker containers (use `host.docker.internal` / `host.containers.internal`)
- #3006 — `sudo docker compose` can mount `/root/.hermes` instead of the user's Hermes home
- #3243 — optional GPU runtime image/docs for containerized acceleration workloads
- #858 — two-container `/opt/hermes` path confusion
- #681 — tools running in WebUI container, not agent container (architectural)
- #668 — auto-detect UID/GID from mounted volume
Expand Down
96 changes: 96 additions & 0 deletions tests/test_docker_gpu_runtime_docs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
from __future__ import annotations

from pathlib import Path

REPO = Path(__file__).resolve().parents[1]


def _repo_text(path):
return (REPO / path).read_text(encoding="utf-8")


def test_dockerfile_gpu_libraries_are_opt_in():
"""The production image must stay CPU-only unless the GPU build arg is set."""
dockerfile = _repo_text("Dockerfile")

assert "ARG INSTALL_GPU_LIBS=0" in dockerfile
assert 'if [ "$INSTALL_GPU_LIBS" = "1" ]' in dockerfile

opt_in_block = dockerfile[dockerfile.index("ARG INSTALL_GPU_LIBS=0"):]
for package in (
"libva2",
"vainfo",
"mesa-va-drivers",
"intel-media-va-driver-non-free",
):
assert package in opt_in_block, (
f"{package} must only appear in the INSTALL_GPU_LIBS opt-in block."
)
assert package not in dockerfile[:dockerfile.index("ARG INSTALL_GPU_LIBS=0")]


def test_dockerfile_handles_missing_intel_non_free_driver():
"""Debian slim repos may not expose the non-free Intel VA-API package."""
dockerfile = _repo_text("Dockerfile")

assert "apt-cache show intel-media-va-driver-non-free" in dockerfile
assert "skipping Intel non-free VA-API driver" in dockerfile


def test_docker_docs_show_gpu_build_command():
docker_docs = _repo_text("docs/docker.md")

assert "Optional GPU runtime image" in docker_docs
assert "--build-arg INSTALL_GPU_LIBS=1" in docker_docs
assert "default Hermes WebUI Docker image stays CPU-only" in docker_docs


def test_docker_docs_cover_intel_amd_dri_mapping():
docker_docs = _repo_text("docs/docker.md")

assert "Intel and AMD VA-API" in docker_docs
assert "--device /dev/dri:/dev/dri" in docker_docs
assert "/dev/dri:/dev/dri" in docker_docs
assert "group_add:" in docker_docs
assert "video" in docker_docs
assert "render" in docker_docs
assert "vainfo" in docker_docs
assert "preserves Docker-provided supplemental groups" in docker_docs


def test_docker_docs_cover_nvidia_host_runtime_guidance():
docker_docs = _repo_text("docs/docker.md")

assert "NVIDIA Container Toolkit" in docker_docs
assert "--gpus all" in docker_docs
assert "gpus: all" in docker_docs
assert "host NVIDIA driver" in docker_docs
assert "host kernel drivers" in docker_docs
assert "NVIDIA runtime" in docker_docs


def test_docker_docs_do_not_claim_native_gpu_passthrough_verification():
docker_docs = _repo_text("docs/docker.md")

assert "not a claim that native GPU passthrough was verified" in docker_docs
assert "depends on host drivers" in docker_docs


def test_docker_init_preserves_supplemental_device_groups_for_runtime_user():
docker_init = _repo_text("docker_init.bash")
root_phase = docker_init[:docker_init.index("exec su -s /bin/bash")]

assert "for gid in $(id -G)" in root_phase
assert "groupadd -g \"$gid\"" in root_phase
assert "Could not create supplemental group for GID $gid" in root_phase
assert "usermod -a -G \"$group_name\" hermeswebui" in root_phase
assert "Docker --group-add supplemental groups" in root_phase


def test_changelog_mentions_optional_gpu_runtime_path():
changelog = _repo_text("CHANGELOG.md")
unreleased = changelog[changelog.index("## [Unreleased]"):changelog.index("## [v0.51.293]")]
Comment on lines +90 to +92

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 The test anchors the upper bound of the changelog slice on the literal string "## [v0.51.293]". If changelog history is ever trimmed and that entry is removed, the test raises ValueError: substring not found rather than giving a useful assertion failure. A safer sentinel is the nearest preceding release entry.

Suggested change
def test_changelog_mentions_optional_gpu_runtime_path():
changelog = _repo_text("CHANGELOG.md")
unreleased = changelog[changelog.index("## [Unreleased]"):changelog.index("## [v0.51.293]")]
def test_changelog_mentions_optional_gpu_runtime_path():
changelog = _repo_text("CHANGELOG.md")
# Use the immediately preceding release as the lower-bound sentinel so the
# slice stays valid even if older entries are pruned from the changelog.
unreleased = changelog[changelog.index("## [Unreleased]"):changelog.index("## [v0.51.303]")]


assert "Optional GPU runtime image path" in unreleased
assert "INSTALL_GPU_LIBS=1" in unreleased
assert "supplemental device groups" in unreleased
Loading
Loading