The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(gateway): only the default profile runs the multiplexer
erosika29c66264e2d6
diff --git a/gateway/run_bootstrap.py b/gateway/run_bootstrap.pyindex 2ef3abd9af2..8ffe771a35a 100644--- a/gateway/run_bootstrap.py+++ b/gateway/run_bootstrap.py@@ -399,6 +399,25 @@ async def _start_gateway_shutdown_tail(+def _launch_home_may_multiplex() -> bool:+ """A named profile serving ``default`` as a secondary splits default's local sessions between+ the two stores (routing rows follow the launch home, receipts follow the authority), so the+ multiplexer is the default profile's job. Exits EX_CONFIG: a config verdict, never a retry."""+ from hermes_constants import profile_name_for_home+ from gateway.run import get_hermes_home, logger+ name = profile_name_for_home(get_hermes_home())+ if name in (None, "default"):+ return True+ from gateway.restart import GATEWAY_FATAL_CONFIG_EXIT_CODE+ from gateway.run import _write_runtime_status_quiet+ logger.error(+ "gateway.multiplex_profiles is set on profile %r, but only the default profile can run the "+ "multiplexer. Unset the flag in this profile's config.yaml, or start the gateway from the "+ "default profile (`hermes gateway run`), which serves this profile too.", name)+ _write_runtime_status_quiet(gateway_state="startup_failed", exit_reason="multiplex_requires_default_profile")+ raise SystemExit(GATEWAY_FATAL_CONFIG_EXIT_CODE)++async def start_gateway(config: Optional[GatewayConfig] = None, replace: bool = False, verbosity: Optional[int] = 0) -> bool:"""Start the gateway and run until interrupted; False if it failed to start (non-zero exit sosystemd can auto-restart). ``replace`` kills any existing instance first (avoids restart-loop deadlocks)."""@@ -445,6 +464,8 @@ async def start_gateway(config: Optional[GatewayConfig] = None, replace: bool =resolved_config = config if config is not None else load_gateway_config_for_runner()profile_homes = (_multiplex_profile_homes(resolved_config)if getattr(resolved_config, 'multiplex_profiles', False) else [])+ if profile_homes and not _launch_home_may_multiplex():+ return Falsetry:process_ownership.reserve([get_hermes_home(), *(home for _, home in profile_homes)])except OwnershipConflict as exc:diff --git a/hermes_cli/profiles.py b/hermes_cli/profiles.pyindex d3ad434d594..6ad57afb866 100644--- a/hermes_cli/profiles.py+++ b/hermes_cli/profiles.py@@ -808,6 +808,25 @@ def _clone_all_into(source_dir: Path, profile_dir: Path, canon: str) -> None:)+def _strip_multiplex_flag(config_path: Path) -> None:+ """Multiplexing belongs to the default profile; a clone that keeps the flag would start its+ own multiplexer (or be refused at boot) the first time it runs a gateway."""+ if not config_path.is_file():+ return+ with contextlib.suppress(Exception): # creation must not fail over an unreadable copy+ import yaml+ from hermes_cli.config import read_user_config_raw+ cfg = read_user_config_raw(config_path)+ gateway = cfg.get("gateway") if isinstance(cfg.get("gateway"), dict) else {}+ if "multiplex_profiles" not in cfg and "multiplex_profiles" not in gateway:+ return+ cfg.pop("multiplex_profiles", None)+ gateway.pop("multiplex_profiles", None)+ if not gateway and "gateway" in cfg:+ cfg.pop("gateway")+ config_path.write_text(yaml.safe_dump(cfg, sort_keys=False), encoding="utf-8")++def _bootstrap_profile_dir(profile_dir: Path, source_dir: Optional[Path]) -> None:"""Fresh layout: bootstrap dirs, then either seed a model block (no source) or cloneconfig files, installed skills (the dashboard's "clone from default" must keep bundled@@ -820,6 +839,7 @@ def _bootstrap_profile_dir(profile_dir: Path, source_dir: Optional[Path]) -> Nonreturnfor relpath in _CLONE_CONFIG_FILES:_clone_file(source_dir, profile_dir, relpath)+ _strip_multiplex_flag(profile_dir / "config.yaml")source_skills = source_dir / "skills"if source_skills.is_dir():shutil.copytree(source_skills, profile_dir / "skills", symlinks=True, dirs_exist_ok=True)diff --git a/tests/gateway/test_multiplex_requires_default_profile.py b/tests/gateway/test_multiplex_requires_default_profile.pynew file mode 100644index 00000000000..cf8b02ee818--- /dev/null+++ b/tests/gateway/test_multiplex_requires_default_profile.py@@ -0,0 +1,56 @@+"""Only the default profile runs the multiplexer; a named launch would split default's sessions."""+import pytest++from gateway.restart import GATEWAY_FATAL_CONFIG_EXIT_CODE+++def _root(tmp_path):+ root = tmp_path / '.hermes'+ root.mkdir()+ (root / 'config.yaml').write_text('model: {default: m}\n')+ (root / 'profiles' / 'foo').mkdir(parents=True)+ (root / 'profiles' / 'foo' / 'config.yaml').write_text('gateway:\n multiplex_profiles: true\n')+ return root+++def test_named_profile_launch_with_multiplex_is_a_config_verdict(tmp_path, monkeypatch):+ from gateway import run_bootstrap++ root = _root(tmp_path)+ monkeypatch.setenv('HERMES_HOME', str(root / 'profiles' / 'foo'))+ import hermes_constants+ hermes_constants._default_hermes_root_memo = None+ written = []+ monkeypatch.setattr('gateway.run._write_runtime_status_quiet', lambda **kw: written.append(kw))+ with pytest.raises(SystemExit) as exc:+ run_bootstrap._launch_home_may_multiplex()+ assert exc.value.code == GATEWAY_FATAL_CONFIG_EXIT_CODE+ assert written == [{'gateway_state': 'startup_failed', 'exit_reason': 'multiplex_requires_default_profile'}]+++def test_default_profile_launch_may_multiplex(tmp_path, monkeypatch):+ from gateway import run_bootstrap++ root = _root(tmp_path)+ monkeypatch.setenv('HERMES_HOME', str(root))+ import hermes_constants+ hermes_constants._default_hermes_root_memo = None+ assert run_bootstrap._launch_home_may_multiplex() is True+++def test_cloned_profile_does_not_inherit_the_multiplex_flag(tmp_path, monkeypatch):+ import yaml+ from hermes_cli.profiles import _strip_multiplex_flag++ nested = tmp_path / 'nested.yaml'+ nested.write_text('model: {default: m}\ngateway:\n multiplex_profiles: true\n service_install_choice: skip\n')+ _strip_multiplex_flag(nested)+ assert yaml.safe_load(nested.read_text()) == {'model': {'default': 'm'}, 'gateway': {'service_install_choice': 'skip'}}+ top = tmp_path / 'top.yaml'+ top.write_text('multiplex_profiles: true\nmodel: {default: m}\n')+ _strip_multiplex_flag(top)+ assert yaml.safe_load(top.read_text()) == {'model': {'default': 'm'}}+ untouched = tmp_path / 'plain.yaml'+ untouched.write_text('# keep my comment\nmodel: {default: m}\n')+ _strip_multiplex_flag(untouched)+ assert untouched.read_text() == '# keep my comment\nmodel: {default: m}\n'