Skip to content

The agent that grows with you

fix(gateway): queue only unregistered-plugin platforms for adapter retry

kshitijk4poor0dcae4ff5c53
diff --git a/gateway/run_adapters.py b/gateway/run_adapters.py
index f35f487fed6..4aca32939c2 100644
--- a/gateway/run_adapters.py
+++ b/gateway/run_adapters.py
@@ -43,6 +43,15 @@ logger = logging.getLogger("gateway.run")
_UNSET = object() # "no per-profile human_delay snapshot": fall back to the primary's value
+def _adapter_unavailable_message(platform: Platform, *, retrying: bool = True) -> str:
+ """Actionable ``adapter_unavailable`` status text, shared by startup and the reconnect watcher so
+ ``hermes status`` keeps the plugin/deps/credentials hint after the first retry."""
+ message = (
+ f"No adapter available for enabled {platform.value}; check the plugin, dependencies, and credentials."
+ )
+ return f"{message} Retrying in the background." if retrying else message
+
+
class _UnresolvedProfileHome:
"""A NAMED routed profile whose home does not resolve — never the same thing as ``None``
("this body is the launch profile's own work"). Overloading ``None`` for both let an inbound
@@ -788,9 +797,9 @@ class GatewayAdapterLifecycleMixin:
try:
adapter = self._create_adapter(platform, platform_config)
if not adapter:
- # Plugin still not registered: keep it queued so it heals once the adapter appears.
+ # No adapter yet (plugin unregistered or deps missing): keep it queued so it heals once one appears.
backoff = self._bump_reconnect_backoff(
- platform, info, attempt, "adapter_unavailable", f"No adapter available for {platform.value}",
+ platform, info, attempt, "adapter_unavailable", _adapter_unavailable_message(platform),
)
logger.info("Reconnect %s: no adapter yet, next retry in %ds", platform.value, backoff)
return
diff --git a/gateway/run_startup.py b/gateway/run_startup.py
index 1e06b789746..21beaf487bb 100644
--- a/gateway/run_startup.py
+++ b/gateway/run_startup.py
@@ -1161,7 +1161,9 @@ class GatewayStartupMixin:
async def _start_prefilter_platforms(self) -> Tuple[bool, int, list, list]:
"""Create + wire an adapter per enabled platform (no connects). Returns
(aborted, enabled_platform_count, multiplex_skipped_platforms, pending_connects)."""
- from gateway.run import _platform_has_bot_credential
+ from gateway.platform_registry import platform_registry
+ from gateway.run import _BUILTIN_ADAPTERS, _platform_has_bot_credential
+ from gateway.run_adapters import _adapter_unavailable_message
enabled_platform_count = 0
_multiplex_on = self._multiplex_on()
_multiplex_skipped_platforms: list[Platform] = []
@@ -1196,17 +1198,24 @@ class GatewayStartupMixin:
"No adapter for '%s' -- is the plugin installed? "
"(platform is enabled in config.yaml but no plugin registered it)", platform.value,
)
- # 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.
+ # Only an unregistered plugin can heal on its own (a plugin load can fail transiently), so
+ # only that case is queued for the reconnect watcher. A builtin whose probe fails (missing
+ # deps/creds), a registered plugin returning None, or an empty bot credential needs a config
+ # change: queueing it would re-warn forever at the backoff cap (#5196 fleet nodes). Either
+ # way flag it so the unserved enabled platform is visible.
+ heals = (
+ platform not in _BUILTIN_ADAPTERS
+ and not platform_registry.is_registered(platform.value)
+ and _platform_has_bot_credential(platform, platform_config)
+ )
self._update_platform_runtime_status(
- 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. Retrying in the background."
- ),
+ platform.value, platform_state="retrying" if heals else "fatal",
+ error_code="adapter_unavailable",
+ error_message=_adapter_unavailable_message(platform, retrying=heals),
needs_attention=True,
)
- self._failed_platforms[platform] = self._startup_retry_entry(platform, None, platform_config)
+ if heals:
+ 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).
@@ -1429,7 +1438,7 @@ class GatewayStartupMixin:
# All retryable: stay alive (cron runs, watcher recovers) rather than systemd restart-loop.
logger.warning(
"Gateway started with no connected platforms — %d platform(s) queued for retry: %s",
- len(self._failed_platforms), "; ".join(startup_retryable_errors),
+ len(startup_retryable_errors), "; ".join(startup_retryable_errors),
)
_write_runtime_status_quiet(gateway_state="degraded", exit_reason=None)
# No adapter for any enabled platform: fleet nodes share one config.yaml but hold a subset of
@@ -1441,7 +1450,8 @@ class GatewayStartupMixin:
# (#5196).
"No adapter could be created for any of the %d configured platform(s). "
"Check that required dependencies are installed and credentials are set. "
- "Gateway will continue for cron job execution.", enabled_platform_count,
+ "Gateway will continue for cron job execution; platforms whose plugin may still register "
+ "are queued for background retry.", enabled_platform_count,
)
return False
diff --git a/tests/gateway/test_runner_startup_failures.py b/tests/gateway/test_runner_startup_failures.py
index dfb37c53f90..9c67eda849b 100644
--- a/tests/gateway/test_runner_startup_failures.py
+++ b/tests/gateway/test_runner_startup_failures.py
@@ -374,6 +374,8 @@ async def test_runner_degrades_gracefully_when_all_adapters_missing(monkeypatch,
# Simulate _create_adapter returning None for ALL platforms (missing library /
# missing credentials — no connection attempt ever made).
monkeypatch.setattr(runner, "_create_adapter", lambda platform, cfg: None)
+ # ...because no plugin registered them, so the reconnect watcher may still heal them.
+ monkeypatch.setattr("gateway.platform_registry.platform_registry.is_registered", lambda name: False)
import logging
with caplog.at_level(logging.WARNING):
diff --git a/tests/gateway/test_startup_failed_platform_reports_degraded.py b/tests/gateway/test_startup_failed_platform_reports_degraded.py
index 7c13857b016..3b0835b1c1d 100644
--- a/tests/gateway/test_startup_failed_platform_reports_degraded.py
+++ b/tests/gateway/test_startup_failed_platform_reports_degraded.py
@@ -62,28 +62,31 @@ class _HealthyAdapter(BasePlatformAdapter):
return {"id": chat_id}
-def _runner_with_one_parked_platform(monkeypatch, tmp_path) -> GatewayRunner:
+def _runner(monkeypatch, tmp_path, platforms, create_adapter) -> GatewayRunner:
monkeypatch.setenv("HERMES_HOME", str(tmp_path))
- config = GatewayConfig(
- platforms={
+ # No plugin registers any platform here, so a None adapter is the "plugin never registered" case.
+ monkeypatch.setattr("gateway.platform_registry.platform_registry.is_registered", lambda name: False)
+ runner = GatewayRunner(GatewayConfig(platforms=platforms, sessions_dir=tmp_path / "sessions"))
+ monkeypatch.setattr(runner, "_create_adapter", create_adapter)
+
+ async def _no_secondary_profiles():
+ return 0
+
+ monkeypatch.setattr(runner, "_start_secondary_profile_adapters", _no_secondary_profiles)
+ return runner
+
+
+def _runner_with_one_parked_platform(monkeypatch, tmp_path) -> GatewayRunner:
+ return _runner(
+ monkeypatch, tmp_path,
+ {
Platform.API_SERVER: PlatformConfig(enabled=True, extra={"port": 8642}),
Platform.TELEGRAM: PlatformConfig(enabled=True, token="***"),
},
- sessions_dir=tmp_path / "sessions",
- )
- runner = GatewayRunner(config)
- monkeypatch.setattr(
- runner,
- "_create_adapter",
lambda platform, platform_config: (
_PortTakenAdapter() if platform is Platform.API_SERVER else _HealthyAdapter()
),
)
- async def _no_secondary_profiles():
- return 0
-
- monkeypatch.setattr(runner, "_start_secondary_profile_adapters", _no_secondary_profiles)
- return runner
@pytest.mark.asyncio
@@ -143,25 +146,15 @@ async def test_every_platform_connected_still_reports_a_normal_run(monkeypatch,
@pytest.mark.asyncio
async def test_missing_adapter_degrades_only_the_unserved_enabled_platform(monkeypatch, tmp_path):
"""An enabled missing plugin must appear in status even when a sibling connects."""
- monkeypatch.setenv("HERMES_HOME", str(tmp_path))
- config = GatewayConfig(
- platforms={
+ runner = _runner(
+ monkeypatch, tmp_path,
+ {
Platform.TELEGRAM: PlatformConfig(enabled=True, token="***"),
Platform.DISCORD: PlatformConfig(enabled=True, token="***"),
Platform.SLACK: PlatformConfig(enabled=False, token="***"),
},
- sessions_dir=tmp_path / "sessions",
- )
- runner = GatewayRunner(config)
- monkeypatch.setattr(
- runner, "_create_adapter",
lambda platform, platform_config: _HealthyAdapter() if platform is Platform.TELEGRAM else None,
)
-
- async def _no_secondary_profiles():
- return 0
-
- monkeypatch.setattr(runner, "_start_secondary_profile_adapters", _no_secondary_profiles)
try:
assert await runner.start() is True
state = read_runtime_status()
@@ -176,34 +169,48 @@ async def test_missing_adapter_degrades_only_the_unserved_enabled_platform(monke
@pytest.mark.asyncio
-async def test_adapterless_platform_heals_once_its_adapter_appears(monkeypatch, tmp_path):
+ "platform, platform_config, heals",
+ [
+ # An unregistered plugin can still register later: queued, retried, healed.
+ (Platform.DISCORD, PlatformConfig(enabled=True, token="***"), True),
+ # A builtin whose probe fails on missing creds needs a config change: flagged once, never queued
+ # (else it re-warns forever at the backoff cap on fleet nodes, #5196).
+ (Platform.BLUEBUBBLES, PlatformConfig(enabled=True), False),
+ ],
+ ids=["unregistered-plugin", "builtin-missing-creds"],
+)
+async def test_adapterless_platform_heals_once_its_adapter_appears(
+ monkeypatch, tmp_path, platform, platform_config, heals
+):
"""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)
+ runner = _runner(
+ monkeypatch, tmp_path, {platform: platform_config},
+ lambda platform, platform_config: adapters.get(platform),
+ )
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
+ status = read_runtime_status()["platforms"][platform.value]
+ assert status["error_code"] == "adapter_unavailable"
+ assert status["needs_attention"] is True
+ if not heals:
+ assert runner._failed_platforms == {}
+ assert status["state"] == "fatal"
+ assert "Retrying" not in status["error_message"]
+ return
+ await runner._reconnect_failed_platform(platform, time.monotonic() + 60)
+ assert runner._failed_platforms[platform]["attempts"] == 2 # still missing: kept queued
+ assert "check the plugin" in read_runtime_status()["platforms"][platform.value]["error_message"]
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
+ healthy.platform = platform
+ adapters[platform] = healthy
+ await runner._reconnect_failed_platform(platform, time.monotonic() + 3600)
+ assert runner.adapters[platform] is healthy
assert runner._failed_platforms == {}
- discord = read_runtime_status()["platforms"]["discord"]
- assert discord["state"] == "connected"
- assert discord["needs_attention"] is False
+ status = read_runtime_status()["platforms"][platform.value]
+ assert status["state"] == "connected"
+ assert status["needs_attention"] is False
finally:
await runner.stop()