Skip to content

The agent that grows with you

fix(gateway): read a masked default unit as an opt-out of the update's multiplex fold

Tekniumc2422986cde3
diff --git a/hermes_cli/gateway_migrate.py b/hermes_cli/gateway_migrate.py
index f70c80183e1..cb0ec0334f7 100644
--- a/hermes_cli/gateway_migrate.py
+++ b/hermes_cli/gateway_migrate.py
@@ -1278,6 +1278,12 @@ def maybe_auto_migrate_after_update() -> None:
resuming = plan.manifest is not None
if not plan.standalone_secondaries and not resuming:
return
+ from hermes_cli.gateway_migrate_guards import masked_default_unit
+ masked = None if resuming else masked_default_unit(plan.default_home)
+ if masked is not None:
+ print(f"\n ℹ Per-profile gateways kept: the default gateway unit is masked ({masked}).\n"
+ f" Unmask it and run {MIGRATE_COMMAND} to fold them into one gateway.")
+ return
print()
auto_blockers = auto_migration_blockers(plan)
if not resuming and (plan.blocked or auto_blockers):
diff --git a/hermes_cli/gateway_migrate_guards.py b/hermes_cli/gateway_migrate_guards.py
index d952466b20f..d39f8b667bd 100644
--- a/hermes_cli/gateway_migrate_guards.py
+++ b/hermes_cli/gateway_migrate_guards.py
@@ -173,6 +173,21 @@ def auto_migration_blockers(plan: MigrationPlan) -> list[str]:
# --------------------------------------------------------------------------- opt-out
+def masked_default_unit(default_home: Path) -> Optional[Path]:
+ """The default profile's systemd unit when the operator MASKED it (``systemctl mask`` links it to
+ ``/dev/null``), else None. A masked survivor cannot be enabled at boot, and masking is a deliberate
+ "never start this", so the update hook reads it as an opt-out instead of refusing (#139324)."""
+ from hermes_cli import gateway as gw
+ from hermes_cli.gateway_migrate import _home_env
+ with _home_env(default_home):
+ units = [gw.get_systemd_unit_path(system=system) for system in (False, True)]
+ for unit in units:
+ with contextlib.suppress(OSError):
+ if unit.is_symlink() and os.path.realpath(unit) == os.devnull:
+ return unit
+ return None
+
+
def auto_migration_opted_out(default_home: Path) -> bool:
"""``gateway.auto_multiplex_migration: false`` in the DEFAULT profile's EFFECTIVE config: the same
``load_config`` the rest of the CLI reads (``DEFAULT_CONFIG`` + config.yaml + the managed overlay), so
diff --git a/tests/hermes_cli/test_gateway_migrate_multiplex.py b/tests/hermes_cli/test_gateway_migrate_multiplex.py
index d6a94075e23..e5937a86126 100644
--- a/tests/hermes_cli/test_gateway_migrate_multiplex.py
+++ b/tests/hermes_cli/test_gateway_migrate_multiplex.py
@@ -435,6 +435,20 @@ def test_update_hook_never_touches_single_profile_or_already_multiplexed(fleet,
assert capsys.readouterr().out == "" and _config_flag(fleet.root) is None
+def test_update_hook_reads_a_masked_default_unit_as_an_opt_out(fleet, capsys, monkeypatch, tmp_path):
+ """`systemctl mask hermes-gateway` is the operator's "never start this": no refusal, no change (#139324)."""
+ from hermes_cli import gateway as gw
+ unit = tmp_path / "systemd/user/hermes-gateway.service"
+ unit.parent.mkdir(parents=True)
+ unit.symlink_to(os.devnull) # exactly what `systemctl --user mask` leaves on disk
+ monkeypatch.setattr(gw, "get_systemd_unit_path", lambda system=False: unit if not system else tmp_path / "none")
+ fleet.services["default"] = ("systemd", False)
+ gm.maybe_auto_migrate_after_update()
+ out = capsys.readouterr().out
+ assert "masked" in out and "refused" not in out and gm.MIGRATE_COMMAND in out
+ assert fleet.ops == [] and _config_flag(fleet.root) is None
+
+
@pytest.mark.parametrize(
("secondary_service", "secondary_uid", "secondary_home", "expected"),
[