The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(gateway): cap failed platform plugin re-arms per queued platform
kshitijk4poor30b04628eafe
diff --git a/gateway/run_adapters.py b/gateway/run_adapters.pyindex 66a53aaaf78..258df315d86 100644--- a/gateway/run_adapters.py+++ b/gateway/run_adapters.py@@ -41,6 +41,7 @@ if TYPE_CHECKING: # string annotations only; never imported at runtime (cycle)# Log-record parity with the origin module.logger = logging.getLogger("gateway.run")_UNSET = object() # "no per-profile human_delay snapshot": fall back to the primary's value+_MAX_PLUGIN_LOAD_REARMS = 3 # per queued platform: transient load failures heal, a broken plugin stops re-importingdef _adapter_unavailable_message(platform: Platform, *, retrying: bool = True) -> str:@@ -822,9 +823,11 @@ class GatewayAdapterLifecycleMixin:)self._drop_from_reconnect_queue(platform, "adapter creation returned None")return- # Unregistered plugin: keep it queued and re-arm a failed load for the next tick.+ # Unregistered plugin: keep it queued and re-arm a failed load (capped) for the next tick.from hermes_cli.plugins import get_plugin_manager- get_plugin_manager().rearm_failed_platform(platform.value)+ if info.get("load_rearms", 0) < _MAX_PLUGIN_LOAD_REARMS and get_plugin_manager().rearm_failed_platform(+ platform.value):+ info["load_rearms"] = info.get("load_rearms", 0) + 1backoff = self._bump_reconnect_backoff(platform, info, attempt, "adapter_unavailable", _adapter_unavailable_message(platform),)diff --git a/tests/gateway/test_platform_reconnect.py b/tests/gateway/test_platform_reconnect.pyindex 4fe98162068..7a94a040e7b 100644--- a/tests/gateway/test_platform_reconnect.py+++ b/tests/gateway/test_platform_reconnect.py@@ -379,13 +379,16 @@ class TestPlatformReconnectWatcher:manager.rearm_failed_platform.side_effect = lambda name: rearmed.append(name) or Truemonkeypatch.setattr(plugins_mod, "get_plugin_manager", lambda: manager)adapter = StubAdapter(platform=platform)- monkeypatch.setattr(runner, "_create_adapter", lambda p, c: adapter if rearmed else None)+ healed = []+ monkeypatch.setattr(runner, "_create_adapter", lambda p, c: adapter if rearmed and healed else None)- for _ in range(2):+ for tick in range(6):+ if tick == 5:+ healed.append(True)runner._failed_platforms.get(platform, {})["next_retry"] = 0await runner._reconnect_failed_platform(platform, time.monotonic())- assert rearmed == ["irc"]+ assert rearmed == ["irc"] * 3 # a permanently broken plugin stops being re-imported after the caprunner._install_reconnected_adapter.assert_awaited_once_with(platform, adapter)