Skip to content

The agent that grows with you

fix(docker): use packaged Python for TUI gateway

Gille48353b2b8958
diff --git a/Dockerfile b/Dockerfile
index 3091eb2768c..a245d55f391 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -490,6 +490,8 @@ ENV PATH="/opt/hermes/bin:/opt/hermes/.venv/bin:/opt/data/.local/bin:${PATH}"
# them after all builds; never relax permissions on mutable PM/home state.
RUN mkdir -p /opt/data && chmod 0644 /opt/hermes/tools/facts.json && \
rm -f /opt/hermes/.venv/.lock /opt/hermes/pm-runtime/.lock
+# Build helpers use system Python above; TUI gateway children need the sealed runtime.
+ENV HERMES_PYTHON=/opt/hermes/.venv/bin/python
VOLUME [ "/opt/data" ]
# The image ENTRYPOINT is a tiny dispatcher rather than `/init` directly.
diff --git a/tests/docker/test_tui_prebuilt_bundle.py b/tests/docker/test_tui_prebuilt_bundle.py
index fd053725bbe..69283389e79 100644
--- a/tests/docker/test_tui_prebuilt_bundle.py
+++ b/tests/docker/test_tui_prebuilt_bundle.py
@@ -82,3 +82,44 @@ def test_prebuilt_bundle_present_and_no_runtime_install(built_image: str) -> Non
assert "npm" not in out["argv"][0].lower(), (
f"launcher resolved to an npm invocation, not the prebuilt bundle: {out['argv']!r}"
)
+
+
+def test_tui_gateway_child_uses_packaged_python(built_image: str) -> None:
+ """The TUI child must inherit the image's dependency environment."""
+ py = '''
+import json
+import os
+import subprocess
+import sys
+from hermes_cli.main_tui_launch import _apply_tui_python_env
+
+env = dict(os.environ)
+_apply_tui_python_env(env)
+child = subprocess.run(
+ [env["HERMES_PYTHON"], "-c",
+ "import os, sys; print(os.path.realpath(sys.executable), flush=True); import tui_gateway.entry"],
+ cwd="/opt/hermes", env=env, capture_output=True, text=True, timeout=30,
+)
+print(json.dumps({
+ "parent": os.path.realpath(sys.executable),
+ "child": child.stdout.strip().splitlines()[0] if child.stdout.strip() else "",
+ "returncode": child.returncode,
+ "stderr": child.stderr[-1000:],
+}))
+'''
+ # Run as the image user without `su`, which would erase Docker's
+ # HERMES_PYTHON and hide the broken runtime environment.
+ inner = (
+ "source /opt/hermes/.venv/bin/activate && "
+ "cd /opt/hermes && "
+ f"python3 -c {shlex.quote(py)}"
+ )
+ r = subprocess.run(
+ ["docker", "run", "--rm", "--network=none", "--user", "hermes",
+ "--entrypoint", "/bin/bash", built_image, "-c", inner],
+ capture_output=True, text=True, timeout=120,
+ )
+ assert r.returncode == 0, r.stderr[-2000:]
+ out = json.loads(r.stdout.strip())
+ assert out["returncode"] == 0, out["stderr"]
+ assert out["child"] == out["parent"], out