The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(gateway): keep shared-bot fallback for a satellite that has a local session
unsupportedpastels01dffd3b478f
diff --git a/cron/scheduler_preflight.py b/cron/scheduler_preflight.pyindex f848eb0f26c..5fd80d7dd23 100644--- a/cron/scheduler_preflight.py+++ b/cron/scheduler_preflight.py@@ -233,6 +233,13 @@ class SharedRouteAdapters:return default+def has_credential_platform(adapters) -> bool:+ """True when the adapter map holds a bot of the profile's own. Any local session (Desktop chat,+ CLI run, Kanban worker) adds a ``LOCAL`` adapter, which holds no platform credential: a profile+ with only that is still a credentialless satellite that may ride routed primary adapters."""+ return any(getattr(platform, "value", platform) != "local" for platform in adapters or ())++def _preflight_check_delivery(job: dict) -> Optional[str]:"""Check delivery targets resolve to configured platforms. ``local``/``origin``/``all`` arenever checked (no gateway-config load). Unknown platform always blocks; known platform blocksdiff --git a/cron/scheduler_provider.py b/cron/scheduler_provider.pyindex f753b0a7fa2..f4a6352f9ed 100644--- a/cron/scheduler_provider.py+++ b/cron/scheduler_provider.py@@ -541,7 +541,7 @@ class InProcessCronScheduler(CronScheduler):from cron.scheduler import tick as cron_tickfrom cron.scheduler import CronTickYielded, _is_fd_exhaustionfrom cron.scheduler_preflight import (- SharedRouteAdapters, _primary_profile_routes_for_current_home,+ SharedRouteAdapters, _primary_profile_routes_for_current_home, has_credential_platform,)from cron.jobs import clear_ticker_error, record_ticker_error, record_ticker_heartbeatfrom cron.scheduler_ownership import register_ticked_homes@@ -562,7 +562,7 @@ class InProcessCronScheduler(CronScheduler):if profile_name is None or profile_name == default_profile:return adapterstick_adapters = (profile_adapters or {}).get(profile_name) or {}- if not tick_adapters and adapters:+ if not has_credential_platform(tick_adapters) and adapters:return SharedRouteAdapters(adapters, _primary_profile_routes_for_current_home())return tick_adaptersdiff --git a/gateway/authz_mixin.py b/gateway/authz_mixin.pyindex 1a48cf0468e..b49a29f8d35 100644--- a/gateway/authz_mixin.py+++ b/gateway/authz_mixin.py@@ -224,9 +224,11 @@ class GatewayAuthorizationMixin:profile_adapters = self._profile_adapters_map()if profile_name in profile_adapters:adapters = profile_adapters[profile_name]- if adapters or not self._is_shared_bot_satellite(profile_name):+ from cron.scheduler_preflight import has_credential_platform+ if has_credential_platform(adapters) or not self._is_shared_bot_satellite(profile_name):return adapters- return self._primary_adapters()+ # Its own LOCAL adapter stays layered over the borrowed primary bots.+ return {**self._primary_adapters(), **adapters}# Identity captured at construction, not the per-turn HERMES_HOME-derived name.primary_profile = getattr(self, "_primary_profile_name", None)if not primary_profile:diff --git a/gateway/run.py b/gateway/run.pyindex 9a26dd649a7..4fb7e339ca5 100644--- a/gateway/run.py+++ b/gateway/run.py@@ -4469,7 +4469,7 @@ def _housekeeping_checkpoint_prune() -> None:def _drain_restart_safe_cron_deliveries(adapters, loop, runner=None) -> None:"""Drain each profile's worker queue through its matching live adapters. A credential-less satellite- profile (empty adapter map) drains through the primary's adapters routed by its own profile routes."""+ profile (no bot of its own) drains through the primary's adapters routed by its own profile routes."""from cron import scheduler as cron_schedulerfrom cron import scheduler_preflight as sched_preflight@@ -4485,7 +4485,7 @@ def _drain_restart_safe_cron_deliveries(adapters, loop, runner=None) -> None:if profile_adapters is None:continuewith _profile_runtime_scope(profile_home or get_hermes_home()):- if profile_name is not None and not profile_adapters and adapters:+ if profile_name is not None and not sched_preflight.has_credential_platform(profile_adapters) and adapters:routes = sched_preflight._primary_profile_routes_for_current_home()if routes:profile_adapters = sched_preflight.SharedRouteAdapters(adapters, routes)diff --git a/tests/cron/test_cron_multiplex_shared_route_delivery.py b/tests/cron/test_cron_multiplex_shared_route_delivery.pyindex 10399d4f1ff..f28c013f01c 100644--- a/tests/cron/test_cron_multiplex_shared_route_delivery.py+++ b/tests/cron/test_cron_multiplex_shared_route_delivery.py@@ -160,3 +160,81 @@ def test_live_native_adapter_without_platform_block_is_not_treated_as_disabled(){"id": "j"}, Platform.DISCORD, "discord", {"platform": "discord", "chat_id": "C1"},{Platform.DISCORD: adapter}, config)assert resolved is None and "not configured/enabled" in err+++def test_multiplex_tick_routes_desktop_served_satellite_with_only_local_adapter(+ tmp_path, monkeypatch,+):+ """#139825: a satellite profile also chatted with from Hermes Desktop holds+ ``{LOCAL: adapter}`` in ``_profile_adapters``. LOCAL carries no platform credential, so its+ cron tick must still hand it the routed primary view — before, the non-empty map skipped+ ``SharedRouteAdapters`` and delivery fell through to the profile's own credentialless config+ (``platform 'discord' not configured/enabled``)."""+ import threading++ from cron.scheduler_provider import InProcessCronScheduler+ from cron.scheduler_preflight import SharedRouteAdapters++ root = tmp_path / "root"+ sat_home = root / "profiles" / "sat"+ (sat_home / "cron").mkdir(parents=True)+ (root / "config.yaml").write_text(yaml.safe_dump({+ "gateway": {"multiplex_profiles": True, "profile_routes": [+ {"platform": "discord", "guild_id": "G1", "chat_id": "C1", "profile": "sat"}]},+ }), encoding="utf-8")+ monkeypatch.setattr("hermes_constants.get_default_hermes_root", lambda: root)++ primary = _primary_adapter()+ captured = {}+ stop = threading.Event()++ def _tick_and_stop(*_args, **kwargs):+ captured["adapters"] = kwargs["adapters"]+ stop.set()++ provider = InProcessCronScheduler()+ with patch("cron.scheduler.tick", side_effect=_tick_and_stop):+ thread = threading.Thread(+ target=provider.start,+ args=(stop,),+ kwargs={+ "interval": 0,+ "profile_homes": [("sat", sat_home)],+ "adapters": {Platform.DISCORD: primary},+ "profile_adapters": {"sat": {Platform.LOCAL: object()}},+ "default_profile": "default",+ },+ daemon=True,+ )+ thread.start()+ thread.join(timeout=10)+ stop.set()+ thread.join(timeout=10)++ assert not thread.is_alive()+ shared = captured["adapters"]+ assert isinstance(shared, SharedRouteAdapters)+ # The routed view releases the primary adapter for exactly the route-mapped target.+ assert shared.get(Platform.DISCORD, {"chat_id": "C1"}) is primary+ assert shared.get(Platform.DISCORD, {"chat_id": "unmapped"}) is None+++def test_adapters_for_profile_layers_primary_under_local_only_satellite():+ """#141910: the authz resolution is the third call site that decided "owns its adapters" by+ map truthiness. A shared-bot satellite holding only a Desktop ``local`` adapter must still+ resolve the primary's bots (background notices, tool sends) with its own local adapter+ layered on top — not instead of the primary."""+ from gateway.authz_mixin import GatewayAuthorizationMixin++ primary, local = object(), object()+ holder = GatewayAuthorizationMixin()+ holder.adapters = {Platform.DISCORD: primary}+ holder._profile_adapters = {"sat": {Platform.LOCAL: local}}+ holder._is_shared_bot_satellite = lambda profile: True+ resolved = GatewayAuthorizationMixin._adapters_for_profile(holder, "sat")+ assert resolved[Platform.DISCORD] is primary and resolved[Platform.LOCAL] is local++ # A satellite that connected a real platform is its own credential boundary: no borrowing.+ holder._profile_adapters = {"sat": {Platform.LOCAL: local, Platform.TELEGRAM: object()}}+ own = holder._profile_adapters["sat"]+ assert GatewayAuthorizationMixin._adapters_for_profile(holder, "sat") is owndiff --git a/tests/gateway/test_cron_delivery_housekeeping.py b/tests/gateway/test_cron_delivery_housekeeping.pyindex ae45f894be4..29f966cbd5c 100644--- a/tests/gateway/test_cron_delivery_housekeeping.py+++ b/tests/gateway/test_cron_delivery_housekeeping.py@@ -161,6 +161,60 @@ def test_multiplex_housekeeping_uses_primary_routes_for_credentialless_satellite]+def test_multiplex_housekeeping_routes_desktop_served_satellite_with_only_local_adapter(+ tmp_path, monkeypatch+):+ """#139825: a profile also chatted with from Hermes Desktop holds ``{LOCAL: adapter}`` in+ ``_profile_adapters``. LOCAL carries no platform credential, so the drain must still hand+ that profile the routed primary view instead of its own credentialless map."""+ from gateway.config import Platform++ root_adapters = {"discord": object()}+ secondary_home = tmp_path / "secondary"+ runner = SimpleNamespace(+ config=SimpleNamespace(multiplex_profiles=True),+ adapters=root_adapters,+ _profile_adapters={"secondary": {Platform.LOCAL: object()}},+ )+ calls = []+ routed = object()++ monkeypatch.setattr(+ gateway_run,+ "_handoff_watch_scopes",+ lambda _runner: [("secondary", secondary_home)],+ )++ @contextmanager+ def fake_scope(_home):+ yield++ class FakeSharedRouteAdapters:+ def __new__(cls, adapters, routes):+ calls.append(("routed", adapters, routes))+ return routed++ monkeypatch.setattr(gateway_run, "_profile_runtime_scope", fake_scope)+ monkeypatch.setattr(sched_preflight, "SharedRouteAdapters", FakeSharedRouteAdapters)+ monkeypatch.setattr(sched_preflight, "_primary_profile_routes_for_current_home",+ lambda: ["route-to-secondary"],+ )+ monkeypatch.setattr(+ scheduler,+ "drain_delivery_queue",+ lambda adapters, _loop: calls.append(("drain", adapters)),+ )++ gateway_run._drain_restart_safe_cron_deliveries(+ root_adapters, object(), runner+ )++ assert calls == [+ ("routed", root_adapters, ["route-to-secondary"]),+ ("drain", routed),+ ]++def test_primary_drain_delivers_credentialless_satellite_queue_row_through_primary_adapter(tmp_path, monkeypatch,):