The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(plugins): avoid recursive deadline workers
Yuan Licfb005ed14de
diff --git a/hermes_cli/plugins_loader.py b/hermes_cli/plugins_loader.pyindex b9e2759bb23..597780ecace 100644--- a/hermes_cli/plugins_loader.py+++ b/hermes_cli/plugins_loader.py@@ -105,6 +105,12 @@ def run_with_load_deadline(plugin_key: str, ctx: "PluginContext", fn: Callable[[and :class:`PluginLoadTimeout` is raised on the calling thread so the usual failure path records thereason and disposes whatever was registered before the hang."""+ # A plugin's register() can re-enter discovery. It is already running on the+ # deadline worker, so creating and joining another worker here can deadlock the+ # parent worker. Run the nested load inline instead; the outer worker still+ # provides the deadline for the whole re-entrant chain.+ if in_plugin_load_worker():+ return fn()timeout = _resolve_plugin_load_timeout()if timeout <= 0:return fn()diff --git a/tests/hermes_cli/test_plugins_loader.py b/tests/hermes_cli/test_plugins_loader.pyindex 90593fa6e3e..41a30561677 100644--- a/tests/hermes_cli/test_plugins_loader.py+++ b/tests/hermes_cli/test_plugins_loader.py@@ -1,4 +1,5 @@from hermes_cli import plugins_loader+import threadingdef test_plugin_load_marker_propagates_into_deadline_worker(monkeypatch):@@ -16,3 +17,25 @@ def test_plugin_load_marker_propagates_into_deadline_worker(monkeypatch):plugins_loader.run_with_load_deadline("test", Context(), load)assert observed == [True]+++def test_nested_plugin_load_runs_inline_on_deadline_worker(monkeypatch):+ monkeypatch.setattr(plugins_loader, "_resolve_plugin_load_timeout", lambda: 1.0)++ class Context:+ def _abandon_load(self):+ raise AssertionError("unexpected timeout")++ observed_threads = []++ def nested_load():+ observed_threads.append(threading.current_thread())++ def outer_load():+ observed_threads.append(threading.current_thread())+ plugins_loader.run_with_load_deadline("nested", Context(), nested_load)++ plugins_loader.run_with_load_deadline("outer", Context(), outer_load)++ assert len(observed_threads) == 2+ assert observed_threads[0] is observed_threads[1]