The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
feat(gateway): let an install opt out of the automatic multiplex migration
Athena8ed2fec94c84
diff --git a/hermes_cli/config_defaults.py b/hermes_cli/config_defaults.pyindex e969f97135f..cf80150fc7c 100644--- a/hermes_cli/config_defaults.py+++ b/hermes_cli/config_defaults.py@@ -1962,6 +1962,13 @@ DEFAULT_CONFIG = {# served together — the duplicate adapter is parked; `hermes profile create --clone`# therefore leaves messaging channels behind unless --clone-channels is passed."multiplex_profiles": False,+ # May `hermes update` fold this install onto a multiplexed default gateway by itself?+ # True (the default) keeps today's behaviour: a multi-profile install whose secondaries run+ # their own gateways is migrated automatically after an update when nothing blocks it.+ # Set to False to stay on per-profile gateways — a durable opt-out that survives updates, so+ # the decision is not re-litigated on every release. Only the AUTOMATIC path reads this:+ # `hermes gateway migrate --multiplex` is an explicit request and always proceeds.+ "auto_migrate": True,# Route inbound chats of the default profile's bots to another profile# (gateway/profile_routing.py): [{profile, platform, chat_id|user_id|guild_id|...}].# Most-specific match wins; only read by the multiplexing default gateway.diff --git a/hermes_cli/gateway_migrate.py b/hermes_cli/gateway_migrate.pyindex 14cd938d3b6..a17c2bcaa22 100644--- a/hermes_cli/gateway_migrate.py+++ b/hermes_cli/gateway_migrate.py@@ -259,6 +259,25 @@ def _read_multiplex_flag(default_home: Path) -> bool:return bool(cfg.get("multiplex_profiles") or gateway_section.get("multiplex_profiles"))+def _read_auto_migrate_flag(default_home: Path) -> bool:+ """``gateway.auto_migrate`` in the DEFAULT profile's config.yaml: may ``hermes update`` fold+ this install onto a multiplexed gateway on its own? Absent (the default) means yes; an explicit+ ``false`` is a durable opt-out that survives updates, so an operator who wants to stay on+ per-profile gateways does not have to re-decide after every release. Only the AUTO path reads+ this — ``hermes gateway migrate --multiplex`` is an explicit request and always proceeds."""+ cfg_path = default_home / "config.yaml"+ if not cfg_path.exists():+ return True+ from hermes_cli.config import read_user_config_raw+ cfg = read_user_config_raw(cfg_path) or {}+ gateway_section = cfg.get("gateway") if isinstance(cfg.get("gateway"), dict) else {}+ for source in (gateway_section, cfg):+ value = source.get("auto_migrate")+ if value is not None:+ return bool(value)+ return True++def _write_multiplex_flag(default_home: Path, value: bool) -> None:"""Set ``gateway.multiplex_profiles`` in the DEFAULT profile's config.yaml through the config API(same read-guard + nested-set + atomic write ``hermes config set`` uses; no raw YAML edits)."""@@ -858,9 +877,12 @@ def cmd_migrate(args) -> None:def maybe_auto_migrate_after_update() -> None:"""``hermes update`` hook: with >= 2 profiles, per-profile gateways present and multiplex off,- migrate automatically when unblocked (deterministic, never prompts) or print the blocker block."""+ migrate automatically when unblocked (deterministic, never prompts) or print the blocker block.+ ``gateway.auto_migrate: false`` on the default profile opts out durably."""if _host_supports_migration() is not None:return+ if not _read_auto_migrate_flag(_default_home()):+ returnplan = build_migration_plan()if plan.already_multiplexed or len(plan.profiles) < 2 or not plan.standalone_secondaries:returndiff --git a/tests/hermes_cli/test_gateway_migrate_multiplex.py b/tests/hermes_cli/test_gateway_migrate_multiplex.pyindex d36a9b3f7bb..05f6032edd0 100644--- a/tests/hermes_cli/test_gateway_migrate_multiplex.py+++ b/tests/hermes_cli/test_gateway_migrate_multiplex.py@@ -377,6 +377,36 @@ def test_auto_migration_guard_allows_detached_default_and_secondary_in_same_scopassert gm._auto_migration_blockers(plan) == []+def test_auto_migrate_false_opts_out_of_the_update_hook_but_not_the_explicit_command(fleet, capsys):+ """``gateway.auto_migrate: false`` is a durable opt-out: an otherwise-eligible fleet is left+ alone by ``hermes update``, while the operator typing ``migrate --multiplex`` still migrates."""+ assert gm.build_migration_plan().eligible_for_migration() # would migrate but for the flag+ (fleet.root / "config.yaml").write_text(+ "model:\n default: x\ngateway:\n auto_migrate: false\n", encoding="utf-8")++ gm.maybe_auto_migrate_after_update()+ assert capsys.readouterr().out == ""+ assert fleet.ops == [] and _config_flag(fleet.root) is None+ assert fleet.services == {"coder": ("systemd", False), "ops": ("systemd", False)}+ assert fleet.pids == {"coder": 4101, "ops": 4102}+ assert not (fleet.root / gm.MANIFEST_NAME).exists()++ # Absent (the default) and an explicit true both keep today's automatic behaviour.+ assert gm._read_auto_migrate_flag(fleet.root) is False+ (fleet.root / "config.yaml").write_text(+ "model:\n default: x\ngateway:\n auto_migrate: true\n", encoding="utf-8")+ assert gm._read_auto_migrate_flag(fleet.root) is True+ (fleet.root / "config.yaml").write_text("model:\n default: x\n", encoding="utf-8")+ assert gm._read_auto_migrate_flag(fleet.root) is True++ # The opt-out governs the AUTOMATIC path only: an explicit --multiplex is an explicit request.+ (fleet.root / "config.yaml").write_text(+ "model:\n default: x\ngateway:\n auto_migrate: false\n", encoding="utf-8")+ with pytest.raises(SystemExit) as exc:+ gm.cmd_migrate(SimpleNamespace(multiplex=True, standalone=False, dry_run=False, yes=True))+ assert exc.value.code == 0+ assert _config_flag(fleet.root) is True and (fleet.root / gm.MANIFEST_NAME).exists()+def test_explicit_migrate_with_no_standalone_secondaries_still_flips_flag_and_restarts_default(fleet, capsys, monkeypatch):"""The user typed --multiplex: 'nothing to migrate' + flag left off was a no-op the user did not askdiff --git a/website/docs/user-guide/multi-profile-gateways.md b/website/docs/user-guide/multi-profile-gateways.mdindex 980c8149069..c42a7ce8500 100644--- a/website/docs/user-guide/multi-profile-gateways.md+++ b/website/docs/user-guide/multi-profile-gateways.md@@ -812,6 +812,23 @@ install that is already multiplexing is left alone. `hermes update` also doesnothing when no secondary profile runs its own gateway — it never flips modeson an install where nothing was running.+### Opting out of the automatic migration++Set `gateway.auto_migrate: false` on the **default** profile to keep the+automatic fold from ever running on this install:++```bash+hermes config set gateway.auto_migrate false+```++`hermes update` then leaves per-profile gateways exactly as they are, with no+output and no changes, however eligible the install looks. The setting lives in+config, so it survives updates — the decision is made once rather than+re-litigated on every release. It governs the **automatic** path only:+`hermes gateway migrate --multiplex` is an explicit request and still migrates+(and is the supported way to opt back in). Absent or `true` keeps the default+behaviour described above.+The explicit command is different: `hermes gateway migrate --multiplex` withtwo or more profiles and **no** standalone secondary gateway still applies theone remaining step — it sets `gateway.multiplex_profiles: true`, (re)starts the