The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(update): narrow the supervised-child exemption to the sticky tail
liuhao102469f8b703fc8a
diff --git a/hermes_cli/venv_sync.py b/hermes_cli/venv_sync.pyindex 987ef8e9a98..ea57eb38e7a 100644--- a/hermes_cli/venv_sync.py+++ b/hermes_cli/venv_sync.py@@ -223,6 +223,20 @@ def _is_tail_script(root: Path, argv0: str) -> bool:return script.name in _TAIL_SCRIPTS and script.resolve().parent == root / "hermes_cli"+def _supervised_child() -> bool:+ """A launcher-marked child: booted by a manager, not a user's shell.++ Launcher markers only — not INVOCATION_ID, which systemd exports to every+ descendant: an ordinary hermes command inside a CI runner still owes its repair.+ Same truthy set as the neighbouring ``HERMES_DISABLE_LAZY_INSTALLS`` read, so+ an explicit ``0``/``false`` does not suppress the completion tail.+ """+ return any(+ os.environ.get(name, "").strip().lower() in ("1", "true", "yes", "on")+ for name in ("HERMES_SUPERVISED_CHILD", "HERMES_S6_SUPERVISED_CHILD")+ )++def prepare_launch(project_root: Path, argv: list[str]) -> Path | None:"""Finish a self-managed source update before importing app dependencies.@@ -235,6 +249,9 @@ def prepare_launch(project_root: Path, argv: list[str]) -> Path | None:every start, so a sticky marker would re-run the tail (and itsenvironment builds) on each boot until the disk fills. The tail staysthe CLI's to finish, via ``hermes update`` / ``hermes pm install``.+ Stale dependencies stay a supervised child's one-shot duty, though: it+ still syncs those and relaunches instead of booting on an out-of-date+ tree (or crash-looping under its manager's restart policy).Return the store interpreter when this process must restart cleanly."""import os@@ -251,8 +268,6 @@ def prepare_launch(project_root: Path, argv: list[str]) -> Path | None:if (command_argv(argv)[:1] == ["pm"]or _METADATA_FLAGS & set(argv)or os.environ.get("HERMES_DISABLE_LAZY_INSTALLS", "").lower() in ("1", "true", "yes")- or os.environ.get("HERMES_SUPERVISED_CHILD")- or os.environ.get("HERMES_S6_SUPERVISED_CHILD")or not (root / ".git").exists()or not (root / "pyproject.toml").is_file()):return None@@ -271,7 +286,7 @@ def prepare_launch(project_root: Path, argv: list[str]) -> Path | None:current = pm.venv_is_current(project_root=root)pending = completion_pending_path(root)- if not current or pending.is_file():+ if not current or (pending.is_file() and not _supervised_child()):lock = UpdateLock()if not lock.acquire():raise RuntimeError("an update is still running; wait for it to exit, then relaunch Hermes")diff --git a/tests/hermes_cli/test_update_launch_completion.py b/tests/hermes_cli/test_update_launch_completion.pyindex 695f2ed1fca..f63f208a5b4 100644--- a/tests/hermes_cli/test_update_launch_completion.py+++ b/tests/hermes_cli/test_update_launch_completion.py@@ -337,18 +337,22 @@ def test_supervised_launch_does_not_repay_a_pending_tail():"""A supervised start retries the tail on every manager restart (#123340).- systemd/launchd/Windows-task/s6 launchers all export a supervised-child marker and- restart the gateway under a policy; with a marker that never clears, each boot would- rebuild the completion environment until the disk fills. The obligation must stay- with the CLI (`hermes update` / `hermes pm install`), not the supervised process.+ systemd/launchd/s6 launchers export a supervised-child marker and restart the+ gateway under a policy (the Windows Scheduled-Task launcher sets the marker+ without a restart policy, #113670); with a marker that never clears, each boot+ would rebuild the completion environment until the disk fills. The obligation+ must stay with the CLI (`hermes update` / `hermes pm install`), not the+ supervised process."""import pm+ from hermes_cli import _launchersroot = _self_checkout(tmp_path, monkeypatch)pending = venv_sync.completion_pending_path(root)pending.parent.mkdir(parents=True)pending.write_text("owed\n")monkeypatch.setattr(pm, "venv_is_current", lambda **kw: True)+ monkeypatch.setattr(_launchers, "resolve_store_python", lambda _: Path(sys.executable))monkeypatch.setenv(marker, "1")assert venv_sync.prepare_launch(root, ["gateway", "run"]) is None@@ -357,3 +361,42 @@ def test_supervised_launch_does_not_repay_a_pending_tail("a supervised child discharged an obligation the CLI still owes")++def test_supervised_launch_with_stale_dependencies_still_syncs(+ tmp_path, monkeypatch, completion_tail+):+ """Stale dependencies stay one-shot for a supervised child (#123340 review).++ A hand-run ``git pull`` leaves the tree's lockfile ahead of the installed+ tools with no pending marker; a manager restart must still sync and finish+ (pre-image behavior) instead of booting on the stale dependency graph — or+ crash-looping under ``Restart=always`` with no sync at all. The sticky-tail+ exemption above must not swallow this one-shot condition.+ """+ import pm+ from hermes_cli import _launchers++ root = _self_checkout(tmp_path, monkeypatch)+ syncs = []+ monkeypatch.setattr(pm, "venv_is_current", lambda **kw: False)+ monkeypatch.setattr(pm, "sync_venv", lambda *a, **kw: syncs.append(a))+ monkeypatch.setattr(_launchers, "resolve_store_python", lambda _: Path(sys.executable))+ monkeypatch.setenv("HERMES_SUPERVISED_CHILD", "1")++ venv_sync.prepare_launch(root, ["gateway", "run"])+ assert syncs, "a supervised child booted on a stale dependency graph without syncing"+ assert completion_tail, "the tail armed by that sync was never finished"+ assert not venv_sync.completion_pending_path(root).is_file()+++ "value,supervised",+ [("1", True), ("true", True), ("on", True), ("0", False), ("false", False)],+)+def test_supervised_marker_off_values_do_not_suppress_the_tail(monkeypatch, value, supervised):+ """The marker parses like every other launcher env flag: `0`/`false` means off."""+ monkeypatch.delenv("HERMES_SUPERVISED_CHILD", raising=False)+ monkeypatch.delenv("HERMES_S6_SUPERVISED_CHILD", raising=False)+ monkeypatch.setenv("HERMES_SUPERVISED_CHILD", value)+ assert venv_sync._supervised_child() is supervised+