The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix: a removed secondary's scope never resolves to the launch authority
Teknium3745e6a5784f
diff --git a/gateway/run_runtime.py b/gateway/run_runtime.pyindex 2f27edd006d..c2773d5f90f 100644--- a/gateway/run_runtime.py+++ b/gateway/run_runtime.py@@ -112,7 +112,7 @@ async def initialize_gateway_runtime(runner):'served_profiles': [],}runner.session_runtime_descriptor = descriptor- registry = SessionAuthorities(homes[0][1])+ registry = SessionAuthorities(homes[0][1], multiplexed=getattr(runner.config, 'multiplex_profiles', False))runner.session_authorities = registryfor index, (name, home) in enumerate(homes):try:diff --git a/gateway/session_authorities.py b/gateway/session_authorities.pyindex 1f067fc423b..f35ad63b407 100644--- a/gateway/session_authorities.py+++ b/gateway/session_authorities.py@@ -20,10 +20,13 @@ from hermes_state_runtime import RuntimeStoreErrorclass SessionAuthorities:"""Registry of authorities keyed by ``hermes_home_key(home)``."""- def __init__(self, launch_home):+ def __init__(self, launch_home, *, multiplexed=False):self.launch_key = hermes_home_key(launch_home)self._by_key: dict[str, object] = {}self._names: dict[str, str | None] = {}+ # A multiplexing runtime (configured, or one that ever served a second home) keeps the+ # scoped-lookup contract after its secondaries are removed: an unserved home is None.+ self.multiplexed = bool(multiplexed)def add(self, home, authority, name=None) -> None:key = hermes_home_key(home)@@ -31,6 +34,8 @@ class SessionAuthorities:raise RuntimeError(f'duplicate session authority for {home}')self._by_key[key] = authorityself._names[key] = name+ if key != self.launch_key:+ self.multiplexed = Truedef replace(self, home, authority) -> None:"""Fill the slot reserved by ``add(home, None, name=...)`` once the authority exists."""@@ -82,9 +87,11 @@ class SessionAuthorities:Unscoped code (startup, shutdown, background watchers) belongs to the launch profile.Scoped code that names a home this process does not serve gets ``None``: a routed- profile must never fall back to the launch profile's ledger.+ profile must never fall back to the launch profile's ledger — including once a removed+ secondary leaves only the launch slot (a late callback of that profile). Only a runtime+ that never multiplexed is a map of one that answers every scope with the launch authority."""- if len(self._by_key) == 1 or get_hermes_home_override() is None:+ if not self.multiplexed or get_hermes_home_override() is None:return self._by_key[self.launch_key]return self._by_key.get(hermes_home_key(get_hermes_home()))diff --git a/tests/gateway/test_session_authorities_multiplex.py b/tests/gateway/test_session_authorities_multiplex.pyindex ec768252f27..78652171620 100644--- a/tests/gateway/test_session_authorities_multiplex.py+++ b/tests/gateway/test_session_authorities_multiplex.py@@ -113,3 +113,31 @@ def test_single_profile_runtime_is_a_map_of_one(tmp_path, monkeypatch):other.mkdir()with _profile_runtime_scope(other, {}):assert active_authority(runner) is authority+++async def test_removed_last_secondary_never_resolves_to_launch(tmp_path, monkeypatch):+ """Once a multiplexed runtime unserves its last secondary only the launch slot remains; a late+ callback scoped to the removed home must get None, not the launch profile's ledger."""+ from gateway.run import _profile_runtime_scope+ from gateway.run_runtime import initialize_gateway_runtime, unserve_profile_runtime+ from gateway.runtime_ownership import process_ownership+ from gateway.session_authorities import active_authority+ root, homes = _reserve_homes(tmp_path, monkeypatch, names=('alpha',))+ process_ownership.reserve([home for _, home in homes])+ alpha = homes[1][1]+ try:+ runner = _runner(root, homes)+ await initialize_gateway_runtime(runner)+ removed = runner.session_authorities.for_home(alpha)+ assert await unserve_profile_runtime(runner, alpha) is True+ removed.db.close()+ assert len(runner.session_authorities) == 1+ with _profile_runtime_scope(alpha, {}):+ assert active_authority(runner) is None+ assert active_authority(runner) is runner.session_authority # unscoped = launch profile+ finally:+ for authority in list(runner.session_authorities):+ authority.db.close()+ for _, home in homes:+ process_ownership.release(home)