The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
feat(update): sibling profiles' configs migrate with the fleet — no more silent version drift (#20438/#54926/#79048)
Teknium706f33d42415
diff --git a/hermes_cli/update_cmd.py b/hermes_cli/update_cmd.pyindex 43c845ef705..600b934d29c 100644--- a/hermes_cli/update_cmd.py+++ b/hermes_cli/update_cmd.py@@ -226,6 +226,68 @@ def _run_migrate_config_fresh(*, interactive: bool = False, quiet: bool = False)return migrate_config(interactive=interactive, quiet=quiet)+def _migrate_sibling_profile_configs() -> list[tuple[str, int, int]]:+ """Migrate every SIBLING profile's config.yaml to the current version.++ #91277 Phase 2 (fleet-wide config migration; #20438/#54926/#79048): the+ shared checkout serves every profile, but ``hermes update`` historically+ migrated only the active profile's config — siblings drifted versions+ until their gateway hit a config the new code couldn't read.++ Per profile home (skipping the active one, already migrated by the+ caller): scope config reads/writes via the context-local HERMES_HOME+ override (thread-safe — never ``os.environ``), check the version, and+ run the NON-INTERACTIVE, quiet migration. Prompt-requiring settings are+ left for the profile's own next interactive session, identical to the+ gateway-mode contract for the active profile.++ Returns ``[(profile_name, from_version, to_version), ...]`` for profiles+ actually migrated. Never raises; a failing profile is skipped (its own+ startup migration remains the fallback).+ """+ migrated: list[tuple[str, int, int]] = []+ try:+ from hermes_constants import (+ get_process_hermes_home,+ reset_hermes_home_override,+ set_hermes_home_override,+ )+ from hermes_cli.profiles import _get_profiles_root, _PROFILE_ID_RE++ active_home = get_process_hermes_home()+ root = _get_profiles_root()+ if not root.is_dir():+ return migrated+ for entry in sorted(root.iterdir()):+ if not entry.is_dir() or not _PROFILE_ID_RE.match(entry.name):+ continue+ try:+ if entry.resolve() == Path(active_home).resolve():+ continue+ except OSError:+ continue+ if not (entry / "config.yaml").is_file():+ continue # profile never configured — nothing to migrate+ token = set_hermes_home_override(entry)+ try:+ current_ver, latest_ver = _run_config_check_fresh()+ if current_ver >= latest_ver:+ continue+ _run_migrate_config_fresh(interactive=False, quiet=True)+ after_ver, _ = _run_config_check_fresh()+ if after_ver > current_ver:+ migrated.append((entry.name, current_ver, after_ver))+ except Exception as exc:+ logger.debug(+ "Config migration for profile %s failed: %s", entry.name, exc+ )+ finally:+ reset_hermes_home_override(token)+ except Exception as exc:+ logger.debug("Sibling profile enumeration failed: %s", exc)+ return migrated++# Critical files that Hermes must be able to import immediately after an# update/install. Most are imported on every CLI startup; ``web_server.py``# is the desktop/dashboard backend path that a fresh Windows install launches@@ -7184,6 +7246,25 @@ def _cmd_update_impl(args, gateway_mode: bool):else:print(" ✓ Configuration is up to date")+ # Fleet-wide config migration (#91277 Phase 2; #20438 earliest report,+ # #54926, #79048): the shared checkout serves EVERY profile, but the+ # migration above only touched the active profile's config.yaml.+ # Sibling profiles kept their old _config_version and silently+ # drifted (field repro: sibling gateway restarted onto new code but+ # stayed at config v33 vs v37). Run the same NON-INTERACTIVE safe+ # migration for every sibling profile home, scoped via the+ # context-local HERMES_HOME override (never os.environ — other+ # threads must not see it).+ try:+ _migrated_siblings = _migrate_sibling_profile_configs()+ for _name, _from_ver, _to_ver in _migrated_siblings:+ print(+ f" ✓ Profile '{_name}': config format updated "+ f"(v{_from_ver} → v{_to_ver})"+ )+ except Exception as exc:+ logger.debug("Sibling config migration failed: %s", exc)+# Safety net: config-version migrations have been observed to leave# cron/jobs.json valid-but-empty, silently dropping every scheduled# job (issue #34600). The desktop scheduler can also overwrite withdiff --git a/tests/hermes_cli/test_fleet_config_migration_windows_live.py b/tests/hermes_cli/test_fleet_config_migration_windows_live.pynew file mode 100644index 00000000000..95b5767d8d4--- /dev/null+++ b/tests/hermes_cli/test_fleet_config_migration_windows_live.py@@ -0,0 +1,51 @@+"""LIVE Windows E2E for the fleet-wide config migration (wine2e lane).++Real profile homes on the Windows filesystem, real migration pipeline,+fresh-process semantics via HERMES_HOME env — mirrors the Linux live E2E.+"""+import sys+from pathlib import Path++import pytest+import yaml++WORKTREE = Path(__file__).resolve().parents[2]+sys.path.insert(0, str(WORKTREE))++pytestmark = pytest.mark.skipif(sys.platform != "win32", reason="live Windows E2E")+++def test_fleet_config_migration_live_windows(tmp_path, monkeypatch):+ active = tmp_path / "hermes-home"+ profiles = active / "profiles"+ for name, ver in [("research", 12), ("work", 25)]:+ home = profiles / name+ home.mkdir(parents=True)+ (home / "config.yaml").write_text(+ yaml.safe_dump({"_config_version": ver, "model": {"provider": "nous"}}),+ encoding="utf-8",+ )+ active.mkdir(exist_ok=True)+ (active / "config.yaml").write_text(+ yaml.safe_dump({"_config_version": 12}), encoding="utf-8"+ )+ monkeypatch.setenv("HERMES_HOME", str(active))++ import hermes_cli.update_cmd as update_cmd+ from hermes_cli.config import DEFAULT_CONFIG++ latest = int(DEFAULT_CONFIG["_config_version"])+ migrated = update_cmd._migrate_sibling_profile_configs()++ by_name = {m[0]: m for m in migrated}+ assert set(by_name) == {"research", "work"}, migrated+ assert by_name["research"][1] == 12 and by_name["research"][2] == latest++ for name in ("research", "work"):+ on_disk = yaml.safe_load((profiles / name / "config.yaml").read_text())+ assert on_disk["_config_version"] == latest+ assert on_disk["model"]["provider"] == "nous"++ # active untouched; idempotent second run+ assert yaml.safe_load((active / "config.yaml").read_text())["_config_version"] == 12+ assert update_cmd._migrate_sibling_profile_configs() == []diff --git a/tests/hermes_cli/test_sibling_config_migration.py b/tests/hermes_cli/test_sibling_config_migration.pynew file mode 100644index 00000000000..3716dc6a0cf--- /dev/null+++ b/tests/hermes_cli/test_sibling_config_migration.py@@ -0,0 +1,124 @@+"""Fleet-wide config migration (#91277 Phase 2 — #20438/#54926/#79048 class).++`hermes update` migrated only the active profile's config.yaml; sibling+profiles silently drifted config versions until their gateway hit a config+the new code couldn't read. `_migrate_sibling_profile_configs()` runs the+same non-interactive safe migration for every sibling home, scoped via the+context-local HERMES_HOME override.++These tests use REAL config files on disk and the REAL migration pipeline —+only the profile-root location is pointed at tmp_path.+"""++import yaml+from pathlib import Path++import hermes_cli.update_cmd as update_cmd+++def _write_profile(root: Path, name: str, version: int) -> Path:+ home = root / name+ home.mkdir(parents=True)+ (home / "config.yaml").write_text(+ yaml.safe_dump({"_config_version": version, "model": {"provider": "nous"}}),+ encoding="utf-8",+ )+ return home+++def _latest_version() -> int:+ from hermes_cli.config import DEFAULT_CONFIG++ return int(DEFAULT_CONFIG["_config_version"])+++def _setup(monkeypatch, tmp_path, active_home: Path):+ import hermes_cli.profiles as profiles_mod++ monkeypatch.setattr(profiles_mod, "_get_profiles_root", lambda: tmp_path / "profiles")+ import hermes_constants++ monkeypatch.setattr(+ hermes_constants, "get_process_hermes_home", lambda: active_home+ )+ monkeypatch.setattr(+ update_cmd, "_reload_config_modules", lambda: None+ ) # module reload is orthogonal here; the real one re-imports from disk+++def test_sibling_behind_is_migrated_on_disk(monkeypatch, tmp_path):+ active = _write_profile(tmp_path / "profiles", "active", _latest_version())+ sibling = _write_profile(tmp_path / "profiles", "research", 12)+ _setup(monkeypatch, tmp_path, active)++ migrated = update_cmd._migrate_sibling_profile_configs()++ names = [m[0] for m in migrated]+ assert "research" in names+ entry = next(m for m in migrated if m[0] == "research")+ assert entry[1] == 12 and entry[2] == _latest_version()+ # REAL file on disk carries the new version+ on_disk = yaml.safe_load((sibling / "config.yaml").read_text())+ assert on_disk["_config_version"] == _latest_version()+ # and user settings survived+ assert on_disk["model"]["provider"] == "nous"+++def test_active_profile_is_skipped(monkeypatch, tmp_path):+ active = _write_profile(tmp_path / "profiles", "active", 12)+ _setup(monkeypatch, tmp_path, active)++ migrated = update_cmd._migrate_sibling_profile_configs()++ assert "active" not in [m[0] for m in migrated]+ # active home untouched (the caller's own migration handles it)+ on_disk = yaml.safe_load((active / "config.yaml").read_text())+ assert on_disk["_config_version"] == 12+++def test_current_sibling_untouched(monkeypatch, tmp_path):+ active = _write_profile(tmp_path / "profiles", "active", _latest_version())+ sibling = _write_profile(tmp_path / "profiles", "work", _latest_version())+ _setup(monkeypatch, tmp_path, active)+ before = (sibling / "config.yaml").read_bytes()++ migrated = update_cmd._migrate_sibling_profile_configs()++ assert migrated == []+ assert (sibling / "config.yaml").read_bytes() == before+++def test_unconfigured_profile_skipped(monkeypatch, tmp_path):+ active = _write_profile(tmp_path / "profiles", "active", _latest_version())+ bare = tmp_path / "profiles" / "empty"+ bare.mkdir()+ _setup(monkeypatch, tmp_path, active)++ assert update_cmd._migrate_sibling_profile_configs() == []+ assert not (bare / "config.yaml").exists()+++def test_one_broken_profile_does_not_block_others(monkeypatch, tmp_path):+ active = _write_profile(tmp_path / "profiles", "active", _latest_version())+ broken_home = tmp_path / "profiles" / "broken"+ broken_home.mkdir()+ (broken_home / "config.yaml").write_text(":\nnot yaml: [", encoding="utf-8")+ _write_profile(tmp_path / "profiles", "healthy", 12)+ _setup(monkeypatch, tmp_path, active)++ migrated = update_cmd._migrate_sibling_profile_configs()++ assert [m[0] for m in migrated] == ["healthy"]+++def test_override_is_reset_after_run(monkeypatch, tmp_path):+ """The ContextVar override must not leak past the sweep."""+ from hermes_constants import get_hermes_home_override++ active = _write_profile(tmp_path / "profiles", "active", _latest_version())+ _write_profile(tmp_path / "profiles", "research", 12)+ _setup(monkeypatch, tmp_path, active)++ before = get_hermes_home_override()+ update_cmd._migrate_sibling_profile_configs()+ assert get_hermes_home_override() == before