Skip to content

The agent that grows with you

fix(update): hermes update's own tail no longer starts a second tail

kshitijk4poor6c7ebd1c010e
diff --git a/hermes_cli/venv_sync.py b/hermes_cli/venv_sync.py
index 199d861223d..38de5c405e0 100644
--- a/hermes_cli/venv_sync.py
+++ b/hermes_cli/venv_sync.py
@@ -211,6 +211,20 @@ def refuse_foreign_owned_venv(project_root: Path) -> None:
)
+#: The two tails the pending marker owes: the launch-time repair's and `hermes update`'s.
+#: Each imports the CLI, and so runs prepare_launch, while that marker is still armed. The
+#: lock-ancestry guard below covers this only while the owning claim is live; an unwritable
+#: claim, one past its age ceiling, or none at all (an installer run) would start another
+#: tail inside this one, and that tail another.
+_TAIL_SCRIPTS = frozenset({"source_completion.py", "update_completion.py"})
+
+
+def _is_tail_script(root: Path, argv0: str) -> bool:
+ """Exact own-script identity; argv is not inherited by the processes a tail spawns."""
+ script = Path(argv0)
+ return script.name in _TAIL_SCRIPTS and script.resolve().parent == root / "hermes_cli"
+
+
def prepare_launch(project_root: Path, argv: list[str]) -> Path | None:
"""Finish a self-managed source update before importing app dependencies.
@@ -225,11 +239,7 @@ def prepare_launch(project_root: Path, argv: list[str]) -> Path | None:
import sys
root = Path(project_root).resolve()
- # Post-build maintenance imports hermes_cli.main while this worker still owns the
- # completion marker. Re-entering the launch repair here starts another tail before
- # this one can clear it, recursively rebuilding the products on every pass.
- if (Path(sys.argv[0]).name == "source_completion.py"
- and Path(sys.argv[0]).resolve() == root / "hermes_cli" / "source_completion.py"):
+ if _is_tail_script(root, sys.argv[0]):
return None
from hermes_cli._parser import command_argv
diff --git a/tests/hermes_cli/test_update_launch_completion.py b/tests/hermes_cli/test_update_launch_completion.py
index e61b40e51da..233c2b26a07 100644
--- a/tests/hermes_cli/test_update_launch_completion.py
+++ b/tests/hermes_cli/test_update_launch_completion.py
@@ -102,13 +102,14 @@ def test_failed_completion_tail_is_retried_without_rebuilding_dependencies(tmp_p
assert len(completion_tail) == 3, "a finished tail was run again"
-def test_prepared_completion_import_does_not_start_another_tail(tmp_path, monkeypatch, completion_tail):
[email protected]("script", ["source_completion.py", "update_completion.py"])
+def test_prepared_completion_import_does_not_start_another_tail(tmp_path, monkeypatch, completion_tail, script):
"""Maintenance imports the CLI while its own completion marker is still present."""
import pm
from hermes_cli import _launchers
root = _self_checkout(tmp_path, monkeypatch)
- worker = root / "hermes_cli" / "source_completion.py"
+ worker = root / "hermes_cli" / script
worker.parent.mkdir()
worker.touch()
venv_sync.arm_completion(root)