The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(migrate): rollback re-run skips a detached secondary that is already running
kshitijk4poorfadcff92270d
diff --git a/hermes_cli/gateway_migrate.py b/hermes_cli/gateway_migrate.pyindex b851a6d6236..a40c5ba538a 100644--- a/hermes_cli/gateway_migrate.py+++ b/hermes_cli/gateway_migrate.py@@ -664,6 +664,8 @@ def rollback_migration(default_home: Optional[Path] = None) -> bool:_service_op(kind, system, "install", home)_service_op(kind, system, "start", home)print(f" ✓ {name}: reinstalled and started its {kind} service")+ elif rec.get("pid") and _live_gateway_pid(home) is not None:+ print(f" ✓ {name}: standalone gateway already running") # re-run after a partial rollbackelif rec.get("pid"):if _spawn_detached_gateway(home):print(f" ✓ {name}: started its standalone gateway (detached)")diff --git a/tests/hermes_cli/test_gateway_migrate_multiplex.py b/tests/hermes_cli/test_gateway_migrate_multiplex.pyindex ea3141280cc..090fbafcf2e 100644--- a/tests/hermes_cli/test_gateway_migrate_multiplex.py+++ b/tests/hermes_cli/test_gateway_migrate_multiplex.py@@ -42,9 +42,6 @@ def fleet(tmp_path, monkeypatch):refused_at_start={},)- def _name(home: Path) -> str:- return hermes_constants.profile_name_for_home(home) or "default"-def _service_op(kind, system, verb, home):name = _name(home)state.ops.append((name, verb))@@ -77,6 +74,10 @@ def fleet(tmp_path, monkeypatch):return state+def _name(home: Path) -> str:+ return hermes_constants.profile_name_for_home(home) or "default"++def _config_flag(root: Path):import yamlraw = yaml.safe_load((root / "config.yaml").read_text(encoding="utf-8")) or {}@@ -150,7 +151,7 @@ def test_rollback_with_failed_secondary_still_restarts_default_and_keeps_manifesreal_op = gm._service_opdef _flaky(kind, system, verb, home):- if verb == "start" and _name_of(home) == "coder":+ if verb == "start" and _name(home) == "coder":raise RuntimeError("systemctl start failed")real_op(kind, system, verb, home)@@ -163,8 +164,16 @@ def test_rollback_with_failed_secondary_still_restarts_default_and_keeps_manifesassert (fleet.root / gm.MANIFEST_NAME).exists()-def _name_of(home: Path) -> str:- return hermes_constants.profile_name_for_home(home) or "default"+def test_rollback_rerun_does_not_respawn_a_running_detached_secondary(fleet, monkeypatch):+ # Manifest of a fleet with no service manager anywhere (detached gateways only).+ gm._write_manifest(fleet.root, {"version": 1, "flag_was": False, "default": {"service": None}, "secondaries": [+ {"profile": n, "home": str(fleet.root / "profiles" / n), "pid": 4100, "service": None} for n in ("coder", "ops")]})+ fleet.services.clear()+ fleet.pids = {"coder": 4101} # coder came back up in an earlier, interrupted rollback; ops did not+ spawned = []+ monkeypatch.setattr(gm, "_spawn_detached_gateway", lambda home: spawned.append(_name(home)) or True)+ assert gm.rollback_migration(fleet.root) is True+ assert spawned == ["ops"]def test_standalone_dry_run_prints_rollback_plan_without_mutation(fleet, capsys):