Skip to content

The agent that grows with you

fix(update): "Already up to date" re-syncs a venv installed from an older release

teknium144945d224c2c
diff --git a/hermes_cli/update_cmd.py b/hermes_cli/update_cmd.py
index 60264fb7a5b..70930d542e0 100644
--- a/hermes_cli/update_cmd.py
+++ b/hermes_cli/update_cmd.py
@@ -85,8 +85,8 @@ from hermes_cli.update_cmd_deps import ( # noqa: F401
_repair_node_deps_on_current_checkout, _restore_active_tool_dependencies,
_sync_python_dependencies_after_pull, _update_node_dependencies,
_upgrade_pip_before_lazy_refresh, _validate_critical_modules_import,
- _venv_core_imports_healthy, _venv_foreign_owned_paths, _web_build_toolchain_ready,
- _web_toolchain_roots)
+ _venv_core_imports_healthy, _venv_dependency_set_stale, _venv_foreign_owned_paths,
+ _web_build_toolchain_ready, _web_toolchain_roots)
from hermes_cli.update_cmd_git import ( # noqa: F401
OFFICIAL_REPO_URL, OFFICIAL_REPO_URLS, SKIP_UPSTREAM_PROMPT_FILE, _ORPHAN_RESCUE_REFS_TO_KEEP,
_ORPHAN_RESCUE_REF_MAX_AGE_DAYS, _add_upstream_remote, _assess_parked_branch_switch,
@@ -712,13 +712,21 @@ def _repair_current_checkout(
# The Windows shim hand-off child is current BY DESIGN; its one job is the pending sync,
# not venv health — without this it would print "Already up to date!" and skip it.
handed_off_sync = os.environ.get(_m()._UPDATE_REEXEC_ENV) == "1"
+ # Importable is not synced: a venv installed from an older release imports fine while its
+ # pins lag the checkout (the sync after the pull was refused or died, #97208).
+ stale, stale_detail = (
+ _venv_dependency_set_stale() if healthy and not handed_off_sync else (False, ""))
if handed_off_sync:
print("→ Finishing the dependency install handed off by hermes.exe...")
elif not healthy:
print("⚠ Checkout is current, but the venv is unhealthy:")
print(f" {detail}")
print("→ Repairing Python dependencies...")
- if handed_off_sync or not healthy:
+ elif stale:
+ print("⚠ Checkout is current, but its dependencies were never synced after the last pull:")
+ print(f" {stale_detail}")
+ print("→ Syncing Python dependencies...")
+ if handed_off_sync or not healthy or stale:
current_checkout_complete = _repair_venv_on_current_checkout(
assume_yes=assume_yes, gateway_mode=gateway_mode,
pre_update_snapshot_id=pre_update_snapshot_id,
diff --git a/hermes_cli/update_cmd_deps.py b/hermes_cli/update_cmd_deps.py
index 2bf2c5114ff..4597384f813 100644
--- a/hermes_cli/update_cmd_deps.py
+++ b/hermes_cli/update_cmd_deps.py
@@ -723,6 +723,37 @@ def _venv_core_imports_healthy() -> tuple[bool, str]:
return True, ""
+def _venv_dependency_set_stale() -> tuple[bool, str]:
+ """Whether the venv's ``hermes-agent`` distribution was installed from an OLDER checkout than
+ the one on disk. The sync after a pull can be skipped (Windows hand-off child refused because
+ the Desktop backend held the venv, or died mid-install); the next run then finds git current,
+ passes the import probe — the old release imports fine — and prints "Already up to date!" over
+ stale pins (#97208). Probed in the venv's own interpreter; ``(stale, detail)``, unknown = not stale."""
+ from hermes_cli.update_cmd import _m, _read_project_version
+ expected = _read_project_version()
+ venv_dir = project_venv_dir(_m().PROJECT_ROOT) or _m().PROJECT_ROOT / "venv"
+ venv_python = venv_python_path(venv_dir, windows=_m()._is_windows())
+ if not expected or not venv_python.exists():
+ return False, ""
+ try:
+ result = subprocess.run(
+ [str(venv_python), "-c", "import importlib.metadata as m; print(m.version('hermes-agent'))"],
+ capture_output=True, text=True, encoding="utf-8", errors="replace", timeout=60,
+ cwd=_m().PROJECT_ROOT)
+ except Exception as exc:
+ logger.debug("installed-version probe failed to run: %s", exc)
+ return False, ""
+ installed = (result.stdout or "").strip()
+ if result.returncode != 0 or not installed:
+ return False, "" # not installed as a distribution: nothing to compare against
+ try:
+ from packaging.version import Version
+ stale = Version(installed) != Version(expected)
+ except Exception:
+ stale = installed != expected
+ return stale, f"installed hermes-agent {installed}, checkout is {expected}" if stale else ""
+
+
# Native extensions that pin venv files once imported: if the updater holds one, Windows blocks
# REPLACE on the mapped ``.pyd`` and the sync dies with ``os error 5``. PyYAML's ``_yaml`` is in
# every CLI process, so the guard must be HONEST: fire only when the sync would actually REWRITE
diff --git a/tests/hermes_cli/test_update_venv_health.py b/tests/hermes_cli/test_update_venv_health.py
index 71dbf4c6cf5..1c7c7dd5933 100644
--- a/tests/hermes_cli/test_update_venv_health.py
+++ b/tests/hermes_cli/test_update_venv_health.py
@@ -241,3 +241,61 @@ def _run_update_until_guard(args):
def test_venv_holder_guard_force_semantics(force, force_venv, expected, capsys):
result = _run_update_until_guard(_update_args(force=force, force_venv=force_venv))
assert result == expected, capsys.readouterr().out
+
+
+# ---------------------------------------------------------------------------
+# "Already up to date" must not hide a venv the last pull never re-synced (#97208)
+# ---------------------------------------------------------------------------
+
+
+def test_venv_dependency_set_stale_compares_installed_distribution_with_checkout(tmp_path):
+ """Reporter's state: git current at 0.21.2, venv metadata still 0.20.6 (the hand-off child
+ refused the sync); core imports pass, so only the distribution version reveals the drift."""
+ from hermes_cli import update_cmd_deps
+
+ (tmp_path / "pyproject.toml").write_text('[project]\nname = "hermes-agent"\nversion = "0.21.2"\n', encoding="utf-8")
+ venv_python = _fake_venv_python(tmp_path)
+ probes = []
+
+ def fake_run(cmd, **kwargs):
+ probes.append(cmd)
+ return SimpleNamespace(returncode=0, stdout=f"{fake_run.installed}\n", stderr="")
+
+ with patch.object(cli_main, "PROJECT_ROOT", tmp_path), patch.object(cli_main, "_is_windows", return_value=False), \
+ patch.object(update_cmd_deps.subprocess, "run", fake_run):
+ fake_run.installed = "0.20.6"
+ assert update_cmd._venv_dependency_set_stale() == (True, "installed hermes-agent 0.20.6, checkout is 0.21.2")
+ fake_run.installed = "0.21.2"
+ assert update_cmd._venv_dependency_set_stale() == (False, "")
+ # Asked in the venv's own interpreter (the updater may run under another Python).
+ assert {cmd[0] for cmd in probes} == {str(venv_python)}
+
+
+def test_current_checkout_with_stale_dependency_set_runs_the_sync(monkeypatch, capsys):
+ """Drift on the commit_count == 0 path triggers the same repair as an unhealthy venv instead
+ of ``✓ Already up to date!``; a synced venv keeps the cheap node-only path."""
+ from hermes_cli import main as hm
+
+ calls = []
+ monkeypatch.setattr(update_cmd, "_venv_core_imports_healthy", lambda: (True, ""))
+ monkeypatch.setattr(hm, "_is_windows", lambda: False)
+ monkeypatch.delenv(hm._UPDATE_REEXEC_ENV, raising=False)
+ monkeypatch.setattr("hermes_cli.managed_uv.update_managed_uv", lambda **kwargs: None)
+ monkeypatch.setattr("hermes_cli.managed_uv.ensure_uv", lambda **kwargs: "uv")
+ monkeypatch.setattr(update_cmd, "_repair_venv_on_current_checkout",
+ lambda **kwargs: calls.append("sync") or True)
+ monkeypatch.setattr(update_cmd, "_repair_node_deps_on_current_checkout",
+ lambda *a, **kwargs: calls.append(kwargs["completion_message"]) or True)
+
+ def run(stale):
+ monkeypatch.setattr(update_cmd, "_venv_dependency_set_stale", lambda: stale)
+ return update_cmd._repair_current_checkout(
+ assume_yes=True, gateway_mode=False, pre_update_snapshot_id=None,
+ had_desktop_app_before_update=False, active_lazy_features=[], active_tool_dependencies=[],
+ upstream_checked=True, _windows_gateway_resume=None)
+
+ assert run((True, "installed hermes-agent 0.20.6, checkout is 0.21.2")) is True
+ assert calls == ["sync"]
+ assert "never synced after the last pull" in capsys.readouterr().out
+ assert run((False, "")) is True
+ assert calls == ["sync", "✓ Already up to date!"]
diff --git a/website/docs/getting-started/updating.md b/website/docs/getting-started/updating.md
index cf310ee4efd..db94bc193b1 100644
--- a/website/docs/getting-started/updating.md
+++ b/website/docs/getting-started/updating.md
@@ -38,7 +38,7 @@ When you run `hermes update`, the following steps occur:
2. **Git pull** — pulls the latest code from the `main` branch and updates submodules
3. **Post-pull syntax validation + auto-rollback** — after the pull, Hermes compiles the nine critical files every `hermes` invocation imports at startup. If any fails to parse (e.g. an orphan merge-conflict marker, an accidentally truncated file), Hermes runs `git reset --hard <pre-pull-sha>` to roll the install back so your shell stays bootable. Re-run `hermes update` once the upstream fix lands.
After this point the updater re-executes itself on the freshly pulled code (`update.log` shows `=== hermes update continued on the pulled code ===`), so the remaining steps never mix old and new modules in one process. If you see two `hermes update` processes for a moment, that is the hand-off.
-4. **Dependency install** — runs `uv pip install -e ".[all]"` to pick up new or changed dependencies
+4. **Dependency install** — runs `uv pip install -e ".[all]"` to pick up new or changed dependencies. When the checkout is already current this step still runs if the venv is unhealthy (core imports fail) **or** if its installed `hermes-agent` distribution is from an older release than the checkout — the sign that a previous run's dependency install was refused or interrupted (`⚠ Checkout is current, but its dependencies were never synced after the last pull`), so `✓ Already up to date!` never hides a half-updated environment.
5. **Config migration** — detects new config options added since your version and prompts you to set them
6. **Desktop rebuild (stage-and-swap)** — if the Hermes Desktop app was built from this checkout, it is rebuilt so the GUI matches the new code. The rebuild packs into a temporary staging directory next to `apps/desktop/release/`, verifies the staged app, and only then renames it over the previous build (on Windows a real-time scanner briefly holding `release/win-unpacked` is ridden out with a few short retries). A rebuild that fails at any point — corrupt Electron download, missing dependency, disk full — leaves the previous app untouched and launchable; the update reports `⚠ Update partially complete` and `hermes desktop` retries the rebuild. On macOS the rebuilt bundle is then copied (with `ditto`, signature intact) over a stale `/Applications/Hermes.app` or `~/Applications/Hermes.app`, so the copy Finder and the Dock launch matches the backend; an installed copy that is currently running is left alone and the update tells you to quit it and run `hermes update` again.
7. **Gateway auto-restart**: running gateways are refreshed after the update completes. Service-managed gateways (systemd on Linux, launchd on macOS) restart through the service manager. Manual gateways are relaunched when Hermes can map their PID to a profile. Manually launched `hermes serve` / `hermes dashboard` backends are different: the updater leaves them running and asks their owner to restart them. See [Manual backend restart reminders](#manual-backend-restart-reminders). Backends owned by a running Desktop app remain the app's responsibility.