fix(gateway): harden Docker/container gateway pathway - #8573
Closed
alt-glitch wants to merge 3 commits into
Closed
Conversation
Extract `is_container()` detection logic from scattered locations (`config.py`, `voice_mode.py`) into a centralized, cached function in `hermes_constants.py`. This follows the same pattern as `is_wsl()` and `is_termux()` — checking `/.dockerenv`, `/run/.containerenv`, and cgroup markers. Update gateway status detection (`status.py`, `dump.py`) to use the new utility and handle Docker/Podman differently from systemd-based systems. Update setup guidance (`setup.py`) to show Docker restart instructions when running in a container. Add Dockerfile.test for CI integration testing and spec.md as a Python module taste guide for contributors.
Remove `_is_inside_container()` from `hermes_cli/config.py` and migrate callers to use `is_container()` from `hermes_constants`. This centralizes container environment detection in a single, reusable location.
Contributor
|
Contributor
|
@alt-glitch — Salvaged your work in #8614 onto current main. Your authorship is preserved in the commit. Changes from your original PR:
All 113 targeted tests pass. Thanks for the thorough fix! |
This was referenced Apr 12, 2026
5 tasks
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.
What does this PR do?
Fixes the
FileNotFoundError: systemctlcrash when running gateway commands inside Docker containers, and goes further to make the entire CLI Docker-aware — correct status output, helpful guidance instead of generic errors, and defense-in-depth against any future systemctl calls leaking through.Before:
hermes gateway installinside Docker crashed or showed "not supported" with exit code 1.hermes statuslied with "Manager: systemd (user)".hermes dumpshowed "gateway: unknown".After: All gateway commands detect containers, show Docker-specific guidance (restart policies,
docker restart,hermes gateway run), and exit cleanly. Status and dump report accurate container-aware information.Related Issue
Fixes #7420
Type of Change
Changes Made
Core: centralized container detection
hermes_constants.py— Addedis_container()with process-lifetime caching. Checks/.dockerenv,/run/.containerenv,/proc/1/cgroupfor Docker/Podman/LXC markers. Same pattern as existingis_wsl()andis_termux().hermes_cli/config.py— Deduplicated_is_inside_container()to delegate to the newis_container().tools/voice_mode.py— Replaced inline/.dockerenvcheck withis_container().Gateway: defense-in-depth
hermes_cli/gateway.py— Added_run_systemctl()wrapper that catchesFileNotFoundErrorand raisesRuntimeErrorwith container-aware messaging. Replaced all 10 baresubprocess.run(_systemctl_cmd(...))call sites. Addedis_container()branches ingateway_command()forinstall,uninstall, andstartsubcommands — these now exit 0 with Docker-specific guidance instead of exit 1 with "not supported".CLI: accurate Docker status
hermes_cli/status.py—hermes statusnow shows "Manager: docker (foreground)" inside containers, usingfind_gateway_pids()instead of systemctl.hermes_cli/dump.py—hermes dumpnow shows "running (docker, pid N)" or "stopped (docker)" instead of "unknown".hermes_cli/setup.py—setup_gateway()shows Docker restart policy instructions in containers.Tests
tests/test_hermes_constants.py— 5 tests foris_container(): dockerenv, containerenv, cgroup, negative, caching.tests/hermes_cli/test_gateway_service.py— 5 tests:_run_systemctlerror/passthrough, install/uninstall/start Docker guidance (exit 0 + correct output).tests/hermes_cli/test_setup.py— 1 test:setup_gatewayshows Docker instructions in containers.How to Test
Unit tests
pytest tests/test_hermes_constants.py tests/hermes_cli/test_gateway_service.py tests/hermes_cli/test_setup.py -x # 99 passedDocker end-to-end
Checklist
Code
pytest tests/ -qand all tests passDocumentation & Housekeeping