The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(gateway): queue adapterless platforms so the reconnect watcher heals them
kshitijk4poor52ffa814d145
diff --git a/gateway/run_adapters.py b/gateway/run_adapters.pyindex 576cd8f897f..f35f487fed6 100644--- a/gateway/run_adapters.py+++ b/gateway/run_adapters.py@@ -235,7 +235,7 @@ class GatewayAdapterLifecycleMixin:**({"queued_at": now} if queued else {}),"credential_claim": self._adapter_credential_claim(platform, adapter),"listener_claim": self._adapter_listener_claim(platform, adapter),- "inbound_dedup": inbound_dedup_caches(adapter),+ "inbound_dedup": inbound_dedup_caches(adapter) if adapter is not None else None,}def _queue_retryable_fatal_platform(self, adapter: BasePlatformAdapter) -> bool:@@ -788,7 +788,11 @@ class GatewayAdapterLifecycleMixin:try:adapter = self._create_adapter(platform, platform_config)if not adapter:- self._drop_from_reconnect_queue(platform, "adapter creation returned None")+ # Plugin still not registered: keep it queued so it heals once the adapter appears.+ backoff = self._bump_reconnect_backoff(+ platform, info, attempt, "adapter_unavailable", f"No adapter available for {platform.value}",+ )+ logger.info("Reconnect %s: no adapter yet, next retry in %ds", platform.value, backoff)returncarry_inbound_dedup(info.get("inbound_dedup"), adapter)self._wire_adapter_handlers(adapter)diff --git a/gateway/run_startup.py b/gateway/run_startup.pyindex 41c8c4e0c5c..1e06b789746 100644--- a/gateway/run_startup.py+++ b/gateway/run_startup.py@@ -1196,18 +1196,17 @@ class GatewayStartupMixin:"No adapter for '%s' -- is the plugin installed? ""(platform is enabled in config.yaml but no plugin registered it)", platform.value,)- # No adapter exists to reconnect, so do not put this in the reconnect queue. Keep- # the gateway alive for siblings/cron, but make the unserved enabled platform- # visible to gateway status and the normal health transition observers.- self._startup_parked_platforms = True+ # Queue it so the reconnect watcher heals it once the plugin registers (a plugin load+ # can fail transiently); flag it so the unserved enabled platform is visible meanwhile.self._update_platform_runtime_status(- platform.value, platform_state="fatal", error_code="adapter_unavailable",+ platform.value, platform_state="retrying", error_code="adapter_unavailable",error_message=(f"No adapter available for enabled {platform.value}; check the plugin, "- "dependencies, and credentials, then restart the gateway."+ "dependencies, and credentials. Retrying in the background."),needs_attention=True,)+ self._failed_platforms[platform] = self._startup_retry_entry(platform, None, platform_config)continue# Under multiplexing the default profile needs the same whole-handler runtime scope as a# secondary (authorization and prompt rendering run before the agent-turn scope).diff --git a/tests/gateway/test_runner_startup_failures.py b/tests/gateway/test_runner_startup_failures.pyindex 2cf0295c40b..dfb37c53f90 100644--- a/tests/gateway/test_runner_startup_failures.py+++ b/tests/gateway/test_runner_startup_failures.py@@ -383,11 +383,12 @@ async def test_runner_degrades_gracefully_when_all_adapters_missing(monkeypatch,assert ok is Trueassert runner.should_exit_cleanly is Falseassert runner.adapters == {}- # Cron still runs, but missing enabled platforms must not look healthy.+ # Cron still runs; missing enabled platforms are flagged and queued for the reconnect watcher.state = read_runtime_status()- assert state["gateway_state"] == "degraded"+ assert state["gateway_state"] == "running"+ assert set(runner._failed_platforms) == {Platform.TELEGRAM, Platform.DISCORD}for platform in ("telegram", "discord"):- assert state["platforms"][platform]["state"] == "fatal"+ assert state["platforms"][platform]["state"] == "retrying"assert state["platforms"][platform]["error_code"] == "adapter_unavailable"assert state["platforms"][platform]["needs_attention"] is True# A warning must be emitted explaining why no platforms connected.diff --git a/tests/gateway/test_startup_failed_platform_reports_degraded.py b/tests/gateway/test_startup_failed_platform_reports_degraded.pyindex 30e3b4dc3f6..7c13857b016 100644--- a/tests/gateway/test_startup_failed_platform_reports_degraded.py+++ b/tests/gateway/test_startup_failed_platform_reports_degraded.py@@ -8,6 +8,7 @@ gate — every platform, not just api_server — so the same failure on any othethe same way."""import logging+import timeimport pytest@@ -164,13 +165,45 @@ async def test_missing_adapter_degrades_only_the_unserved_enabled_platform(monketry:assert await runner.start() is Truestate = read_runtime_status()- assert state["gateway_state"] == "degraded"assert state["platforms"]["telegram"]["state"] == "connected"- assert state["platforms"]["discord"]["state"] == "fatal"+ assert state["platforms"]["discord"]["state"] == "retrying"assert state["platforms"]["discord"]["error_code"] == "adapter_unavailable"assert state["platforms"]["discord"]["needs_attention"] is True- assert "restart" in state["platforms"]["discord"]["error_message"]assert "slack" not in state["platforms"]- assert runner._failed_platforms == {} # No adapter exists to reconnect.+ assert list(runner._failed_platforms) == [Platform.DISCORD] # the reconnect watcher owns it+ finally:+ await runner.stop()+++async def test_adapterless_platform_heals_once_its_adapter_appears(monkeypatch, tmp_path):+ """A plugin that registers late: the queued platform stays queued, then connects."""+ monkeypatch.setenv("HERMES_HOME", str(tmp_path))+ config = GatewayConfig(+ platforms={Platform.DISCORD: PlatformConfig(enabled=True, token="***")},+ sessions_dir=tmp_path / "sessions",+ )+ runner = GatewayRunner(config)+ adapters = {}+ monkeypatch.setattr(runner, "_create_adapter", lambda platform, platform_config: adapters.get(platform))++ async def _no_secondary_profiles():+ return 0++ monkeypatch.setattr(runner, "_start_secondary_profile_adapters", _no_secondary_profiles)+ try:+ assert await runner.start() is True+ await runner._reconnect_failed_platform(Platform.DISCORD, time.monotonic() + 60)+ assert runner._failed_platforms[Platform.DISCORD]["attempts"] == 2 # still missing: kept queued++ healthy = _HealthyAdapter()+ healthy.platform = Platform.DISCORD+ adapters[Platform.DISCORD] = healthy+ await runner._reconnect_failed_platform(Platform.DISCORD, time.monotonic() + 3600)+ assert runner.adapters[Platform.DISCORD] is healthy+ assert runner._failed_platforms == {}+ discord = read_runtime_status()["platforms"]["discord"]+ assert discord["state"] == "connected"+ assert discord["needs_attention"] is Falsefinally:await runner.stop()