Skip to content

The agent that grows with you

fix(docker): end a hung s6 command at the runtime deadline

unsupportedpastelsfb6349f84b63
diff --git a/hermes_cli/gateway_runtime_service.py b/hermes_cli/gateway_runtime_service.py
index d167cc8d731..cec8c49910e 100644
--- a/hermes_cli/gateway_runtime_service.py
+++ b/hermes_cli/gateway_runtime_service.py
@@ -149,7 +149,7 @@ def _systemd(home: Path, deadline: float) -> ExistingService | None:
return found[0] if found else None
-def _s6(home: Path) -> ExistingService | None:
+def _s6(home: Path, deadline: float) -> ExistingService | None:
"""Find the container gateway slot that owns ``home``.
TUI clients call ``ensure_gateway_runtime`` inside the Docker image too.
@@ -261,10 +261,8 @@ def _no_supervisor(home: Path, deadline: float) -> None:
def discover_existing_gateway_service(home: Path, *, deadline: float) -> ExistingService | None:
from hermes_cli.service_manager import _s6_running
- if _s6_running():
- return _s6(home)
- backend = {"linux": _systemd, "darwin": _launchd, "win32": _windows,
- "android": _no_supervisor}.get(sys.platform)
+ backend = _s6 if _s6_running() else {"linux": _systemd, "darwin": _launchd, "win32": _windows,
+ "android": _no_supervisor}.get(sys.platform)
if backend is None:
raise RuntimeStartError("unsupported_supervisor_platform")
try:
@@ -283,6 +281,8 @@ def start_existing_gateway_service(service: ExistingService, *, deadline: float)
from hermes_cli.service_manager import S6ServiceManager
try:
S6ServiceManager().start(service.start_argv[0])
+ except subprocess.TimeoutExpired:
+ raise TimeoutError from None
except (OSError, RuntimeError, ValueError) as exc:
raise RuntimeStartError("service_start_failed") from exc
return
diff --git a/tests/hermes_cli/test_gateway_runtime_service.py b/tests/hermes_cli/test_gateway_runtime_service.py
index dfde9344411..94c66e379cf 100644
--- a/tests/hermes_cli/test_gateway_runtime_service.py
+++ b/tests/hermes_cli/test_gateway_runtime_service.py
@@ -371,6 +371,35 @@ def test_s6_runtime_ensure_starts_the_registered_gateway_slot(tmp_path, monkeypa
assert started == ["gateway-default"]
+def test_s6_command_timeout_ends_at_the_runtime_deadline(tmp_path, monkeypatch):
+ """A hung s6-svstat or s6-svc reaches ensure as its deadline, not an uncaught TimeoutExpired."""
+ from hermes_cli import gateway_runtime_service as service
+ from hermes_cli import service_manager
+
+ home = tmp_path / "data"
+ home.mkdir()
+ scandir = tmp_path / "run-service"
+ (scandir / "gateway-default").mkdir(parents=True)
+
+ def hang(cmd, *_args, timeout=5, **_kwargs):
+ raise subprocess.TimeoutExpired(cmd, timeout)
+
+ monkeypatch.setattr(service_manager, "_s6_running", lambda: True)
+ monkeypatch.setattr(service_manager, "_s6_run", hang)
+ monkeypatch.setattr(service_manager.S6ServiceManager, "__init__",
+ lambda self: setattr(self, "scandir", scandir))
+ read_text = Path.read_text
+ monkeypatch.setattr(Path, "read_text", lambda path, *args, **kwargs: (
+ str(home) if str(path).replace("\\", "/") == "/run/s6/container_environment/HERMES_HOME"
+ else read_text(path, *args, **kwargs)))
+
+ with pytest.raises(TimeoutError):
+ service.discover_existing_gateway_service(home, deadline=time.monotonic() + 5)
+ stopped = service.ExistingService("s6", ("gateway-default",), False)
+ with pytest.raises(TimeoutError):
+ service.start_existing_gateway_service(stopped, deadline=time.monotonic() + 5)
+
+
def test_windows_startup_folder_entry_still_restarts_a_stopped_owner(tmp_path, monkeypatch):
"""The Startup-folder fallback is login persistence only (no start verb, no identity): with it
present and no Scheduled Task registered, ensure takes the same detached direct spawn manual