The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(gateway): keep multiplexed direct platforms awake
joaomarcosbbdaa89a4727
diff --git a/gateway/run_shutdown.py b/gateway/run_shutdown.pyindex b8c4091fe6b..043634532fe 100644--- a/gateway/run_shutdown.py+++ b/gateway/run_shutdown.py@@ -330,21 +330,32 @@ class GatewayShutdownMixin:)def _scale_to_zero_active_messaging_platforms(self) -> list:- """ENABLED MESSAGING platforms for the relay-only arm gate.+ """Return every enabled or live messaging platform across served profiles.- config.platforms is pre-seeded with disabled placeholders, and the api_server is force-enabled- on every hosted container (counting it silently disarmed the feature everywhere).+ ``self.config`` belongs to the launch profile, while ``_profile_adapters`` holds+ live adapters for multiplexed secondary profiles. A direct secondary connection+ must block suspension just like a direct primary connection."""- if not self.config:- return []non_messaging = {Platform.LOCAL, Platform.API_SERVER, Platform.WEBHOOK}+ active = []++ def add_platform(platform: Platform) -> None:+ if platform not in non_messaging and platform not in active:+ active.append(platform)+try:- return [- p for p, pc in self.config.platforms.items()- if getattr(pc, "enabled", False) and p not in non_messaging- ]- except Exception: # noqa: BLE001- return []+ if self.config:+ for platform, platform_config in self.config.platforms.items():+ if getattr(platform_config, "enabled", False):+ add_platform(platform)+ for platform in getattr(self, "adapters", {}) or {}:+ add_platform(platform)+ for profile_adapters in (getattr(self, "_profile_adapters", {}) or {}).values():+ for platform in profile_adapters:+ add_platform(platform)+ except Exception: # noqa: BLE001 - diagnostics must not block gateway startup+ return active+ return active@staticmethoddef _relay_wake_url_or_none():diff --git a/tests/gateway/test_scale_to_zero.py b/tests/gateway/test_scale_to_zero.pyindex 938bf463ffe..05d620fbc7c 100644--- a/tests/gateway/test_scale_to_zero.py+++ b/tests/gateway/test_scale_to_zero.py@@ -65,6 +65,22 @@ def test_no_platform_is_true():assert messaging_is_relay_only_or_absent([]) is True+def test_scale_to_zero_gate_accounts_for_secondary_profile_direct_adapter(monkeypatch):+ # A direct adapter in a served profile owns an inbound socket too; the process+ # must stay awake even when the launch profile itself is relay-only.+ from gateway.config import GatewayConfig, Platform, PlatformConfig+ from gateway.run_shutdown import GatewayShutdownMixin++ monkeypatch.setenv("HERMES_SCALE_TO_ZERO", "1")+ monkeypatch.setenv("GATEWAY_RELAY_WAKE_URL", "https://wake.example.test/instance")+ runner = object.__new__(GatewayShutdownMixin)+ runner.config = GatewayConfig(platforms={Platform.RELAY: PlatformConfig(enabled=True)})+ runner.adapters = {Platform.RELAY: object()}+ runner._profile_adapters = {"imessage": {Platform("photon"): object()}}++ assert runner._scale_to_zero_should_arm() is False++# ── should_arm (D1/D11/§3.4(1)) ──────────────────────────────────────────────