The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(plugins): isolate SystemExit in event, middleware and prompt-section callbacks too
teknium1656c1c9bda7a
diff --git a/hermes_cli/plugins_dispatch.py b/hermes_cli/plugins_dispatch.pyindex 65ba6f268b4..3f54d05d2b6 100644--- a/hermes_cli/plugins_dispatch.py+++ b/hermes_cli/plugins_dispatch.py@@ -397,7 +397,7 @@ class PluginDispatchMixin:try:# Fresh deep copy per subscriber: no callback can mutate what the next sees.resolve_plugin_command_result(callback(**copy.deepcopy(item.payload)))- except Exception as exc:+ except (Exception, SystemExit) as exc:# A subscriber that fails identically on every emit is reported once (#111922).self._report_hook_failure(item.event, callback, item.payload, exc, surface="Event")finally:@@ -494,7 +494,7 @@ class PluginDispatchMixin:try:value = section.content(frozen_info) if callable(section.content) else section.content- except Exception as exc:+ except (Exception, SystemExit) as exc:_skip("raised and was skipped: %s", exc)return Noneif not isinstance(value, str):@@ -523,7 +523,7 @@ class PluginDispatchMixin:ret = cb(**kwargs)if ret is not None:results.append(ret)- except Exception as exc:+ except (Exception, SystemExit) as exc:# Runs once per tool call like a hook, so a mis-declared callback floods identically.self._report_hook_failure(kind, cb, kwargs, exc, surface="Middleware")return resultsdiff --git a/tests/hermes_cli/test_plugins.py b/tests/hermes_cli/test_plugins.pyindex d6c0afa46e9..0459d26500c 100644--- a/tests/hermes_cli/test_plugins.py+++ b/tests/hermes_cli/test_plugins.py@@ -1206,6 +1206,18 @@ class TestForceReloadSymmetry:mgr.invoke_hook("subagent_stop", parent_session_id="p1")assert later_calls == []+ def test_system_exit_from_middleware_is_isolated(self, caplog):+ """Middleware shares the hook isolation contract: sys.exit() in one callback skips only it."""+ def exits(**_kwargs):+ raise SystemExit("middleware requested process exit")++ mgr = PluginManager()+ mgr._middleware["tool_call"] = [exits, lambda **_kw: "survived"]++ with caplog.at_level(logging.WARNING, logger="hermes_cli.plugins"):+ assert mgr.invoke_middleware("tool_call") == ["survived"]+ assert "middleware requested process exit" in caplog.text+def test_hung_callback_suppresses_repeat_fires(self, monkeypatch):"""A still-running timed-out callback must not spawn another worker."""import time