Skip to content

The agent that grows with you

fix(update): keep the config-migration purge and reload inside the fail-open guard

teknium18e0b1a2e47ac
diff --git a/hermes_cli/update_cmd_config.py b/hermes_cli/update_cmd_config.py
index bf9139a3906..4b002571fd8 100644
--- a/hermes_cli/update_cmd_config.py
+++ b/hermes_cli/update_cmd_config.py
@@ -181,12 +181,14 @@ def _check_and_apply_config_migration(
# object is still cached — reloading a hand-picked list re-fixes this per symptom
# (#111271). The purge is the class fix already used by the fleet-restart phase.
from hermes_cli.update_cmd import _m
- _m()._purge_stale_hermes_modules()
- # Reload BEFORE any config reads so all checks use the updated code.
- _reload_config_modules()
- from hermes_cli.config import get_missing_env_vars, get_missing_config_fields
# A config-check failure must not break an otherwise-successful update.
try:
+ _m()._purge_stale_hermes_modules()
+ # Reload BEFORE any config reads so all checks use the updated code.
+ _reload_config_modules()
+ # Post-purge this re-executes the NEW config.py against whatever root modules
+ # (hermes_constants, utils, ...) are still cached, so it can fail too.
+ from hermes_cli.config import get_missing_env_vars, get_missing_config_fields
# Log, point at the manual command, and return. See #91360.
missing_env = get_missing_env_vars(required_only=True)
missing_config = get_missing_config_fields()
diff --git a/tests/hermes_cli/test_update_config_reload_tools_config.py b/tests/hermes_cli/test_update_config_reload_tools_config.py
index 5e4d37ba104..59842d75487 100644
--- a/tests/hermes_cli/test_update_config_reload_tools_config.py
+++ b/tests/hermes_cli/test_update_config_reload_tools_config.py
@@ -67,3 +67,25 @@ def test_update_migration_survives_stale_module_missing_call_time_symbol(tmp_pat
text = (home / "config.yaml").read_text(encoding="utf-8")
assert "_config_version: 45" in text, text
+
+
+def test_update_migration_import_failure_after_purge_prints_fallback(tmp_path, monkeypatch, capsys):
+ """The purge evicts ``hermes_cli.*`` but not root modules (``hermes_constants``, ...), so the
+ post-purge ``from hermes_cli.config import ...`` re-executes NEW config.py against OLD root
+ modules and can raise ImportError. That must print the 'run hermes config migrate' fallback and
+ return — not escape and abort the rest of post-update maintenance (fleet restart)."""
+ home = tmp_path / "flat-home"
+ home.mkdir()
+ (home / "config.yaml").write_text("_config_version: 44\n", encoding="utf-8")
+ monkeypatch.setenv("HERMES_HOME", str(home))
+ import hermes_cli.config # noqa: F401 (pre-pull world has config cached)
+ import hermes_constants
+ # A pre-pull root module lacking a symbol the post-pull hermes_cli/config.py imports at module level.
+ monkeypatch.delattr(hermes_constants, "get_process_hermes_home")
+
+ from hermes_cli.update_cmd import _check_and_apply_config_migration
+ _check_and_apply_config_migration(assume_yes=True, gateway_mode=False, pre_update_snapshot_id=None)
+
+ out = capsys.readouterr().out
+ assert "Could not check config version" in out, out
+ assert "hermes config migrate" in out, out