The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(gateway): re-arm a failed platform plugin load from the reconnect watcher
kshitijk4poor02367369f65b
diff --git a/gateway/run_adapters.py b/gateway/run_adapters.pyindex f280172e204..4a9fa1ec3a1 100644--- a/gateway/run_adapters.py+++ b/gateway/run_adapters.py@@ -822,7 +822,8 @@ class GatewayAdapterLifecycleMixin:)self._drop_from_reconnect_queue(platform, "adapter creation returned None")return- # Unregistered plugin: keep it queued so it heals once the plugin registers.+ # Unregistered plugin: keep it queued and re-arm a failed load for the next tick.+ self._rearm_failed_platform_load(platform)backoff = self._bump_reconnect_backoff(platform, info, attempt, "adapter_unavailable", _adapter_unavailable_message(platform),)diff --git a/gateway/run_plugin_rewire.py b/gateway/run_plugin_rewire.pyindex 03275d5cd9a..69c7b963271 100644--- a/gateway/run_plugin_rewire.py+++ b/gateway/run_plugin_rewire.py@@ -77,6 +77,12 @@ class GatewayPluginRewireMixin:f" for profile '{profile_name}'" if profile_name else "")return count+ def _rearm_failed_platform_load(self, platform) -> bool:+ """Reconnect-watcher hook (once per backoff tick): re-arm the current profile's failed platform+ plugin load so the next ``_create_adapter`` retries it instead of waiting for reload-plugins."""+ from hermes_cli.plugins import get_plugin_manager+ return get_plugin_manager().rearm_failed_platform(platform.value)+def reload_plugins_verb(runner: Any, loop: asyncio.AbstractEventLoop) -> Callable[..., dict]:"""Control-socket ``reload-plugins``: force re-discovery under the requested home's scope so a plugindiff --git a/hermes_cli/plugins_loader.py b/hermes_cli/plugins_loader.pyindex a0d4422f4b5..e0b76d11312 100644--- a/hermes_cli/plugins_loader.py+++ b/hermes_cli/plugins_loader.py@@ -265,6 +265,21 @@ class PluginLoaderMixin:returnself._register_deferred_platform_tools(manifest, loaded)+ def rearm_failed_platform(self, platform_name: str) -> bool:+ """Re-lease the deferred loader of a platform plugin whose load failed, so the next registry lookup+ retries the import. A failed load disposes its lease (the registry forgets the platform), so without+ this a load that raised or overran its deadline at startup stays down until a forced re-discovery+ (#126356). True when a loader was re-armed."""+ with self._discovery_lock:+ failed = next((p.manifest for p in self._plugins.values()+ if p.error and not p.enabled and p.manifest.kind == "platform"+ and self._platform_name_from_manifest(p.manifest) == platform_name), None)+ if failed is None:+ return False+ logger.info("Re-arming failed platform plugin load: %s", platform_name)+ self._register_deferred_platform(failed)+ return True+@_serialized_replacementdef _lease_deferred_platform(self, manifest: PluginManifest, lookup_key: str) -> bool:"""Publish the deferred loader as a ledger-owned lease; False when the registry refused it."""diff --git a/tests/gateway/test_platform_reconnect.py b/tests/gateway/test_platform_reconnect.pyindex 608c02ea3b9..4fe98162068 100644--- a/tests/gateway/test_platform_reconnect.py+++ b/tests/gateway/test_platform_reconnect.py@@ -359,6 +359,36 @@ class TestPlatformReconnectWatcher:assert info["next_retry"] > time.monotonic()+ @pytest.mark.asyncio+ async def test_failed_plugin_load_is_rearmed_by_the_watcher(self, monkeypatch):+ """An unregistered plugin platform (its deferred load failed at startup) heals on the next watcher+ tick: the adapter_unavailable branch re-arms the failed load instead of waiting for a manual+ reload-plugins or restart (#126356)."""+ import hermes_cli.plugins as plugins_mod++ runner = _make_runner()+ runner._update_platform_runtime_status = MagicMock()+ runner._install_reconnected_adapter = AsyncMock()+ platform = Platform("irc") # bundled plugin platform (not a builtin adapter)+ monkeypatch.setattr(runner, "_adapter_may_heal", lambda p, c: True)+ runner._failed_platforms[platform] = {+ "config": PlatformConfig(enabled=True), "attempts": 0, "next_retry": 0,+ }+ rearmed = []+ manager = MagicMock()+ manager.rearm_failed_platform.side_effect = lambda name: rearmed.append(name) or True+ monkeypatch.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)++ for _ in range(2):+ runner._failed_platforms.get(platform, {})["next_retry"] = 0+ await runner._reconnect_failed_platform(platform, time.monotonic())++ assert rearmed == ["irc"]+ runner._install_reconnected_adapter.assert_awaited_once_with(platform, adapter)++# --- Runtime disconnection queueing ---class TestRuntimeDisconnectQueuing:diff --git a/tests/hermes_cli/test_deferred_platform_client_tools.py b/tests/hermes_cli/test_deferred_platform_client_tools.pyindex 119682290eb..0151c01c0e4 100644--- a/tests/hermes_cli/test_deferred_platform_client_tools.py+++ b/tests/hermes_cli/test_deferred_platform_client_tools.py@@ -431,6 +431,33 @@ class TestDeferredPlatformToolPreregistration:# The bookkeeping entry must not outlive the failed load attempt.assert "probeplat-platform" not in mgr._predeclared_tools+ def test_failed_load_is_rearmed_and_heals_on_next_lookup(self, tmp_path, probe, clean_registry):+ """A platform whose first deferred load raises (e.g. a load-deadline overrun under startup I/O) is+ re-armed by the reconnect watcher's hook, so the next lookup imports it again and the platform+ registers, without a forced re-discovery (#126356)."""+ from gateway.platform_registry import platform_registry+ from hermes_cli.plugins import PluginManager++ manifest = _write_platform_plugin(tmp_path, "probeplat", with_tools_module=False)+ (Path(manifest.path) / "__init__.py").write_text(+ "import _deferred_probe\n"+ "def register(ctx):\n"+ " _deferred_probe.adapter_imports += 1\n"+ " if _deferred_probe.adapter_imports == 1:\n"+ " raise TimeoutError('load deadline overrun')\n"+ " ctx.register_platform('probeplat', 'Probe', lambda cfg: object(), lambda: True)\n",+ encoding="utf-8",+ )+ mgr = PluginManager()+ mgr._register_deferred_platform(manifest)+ assert platform_registry.get("probeplat") is None+ assert platform_registry.get("probeplat") is None # a failed load is never retried by a lookup++ assert mgr.rearm_failed_platform("probeplat") is True+ assert platform_registry.get("probeplat") is not None+ assert probe.adapter_imports == 2+ assert mgr.rearm_failed_platform("probeplat") is False # loaded: nothing left to re-arm+def test_declared_tools_with_no_tools_module_warns(self, tmp_path, probe, clean_registry, caplog):