Skip to content

The agent that grows with you

fix(plugins): fail closed on policy hook exceptions

KoNit-K89de6083171d
diff --git a/hermes_cli/plugins_dispatch.py b/hermes_cli/plugins_dispatch.py
index 55b469fdb50..7aa7cb34c05 100644
--- a/hermes_cli/plugins_dispatch.py
+++ b/hermes_cli/plugins_dispatch.py
@@ -220,6 +220,8 @@ class PluginDispatchMixin:
results.append(ret)
except (Exception, SystemExit) as exc:
self._report_hook_failure(hook_name, cb, kwargs, exc)
+ if fail_closed:
+ results.append({"action": "block", "message": _PRE_TOOL_CALL_TIMEOUT_BLOCK_MESSAGE})
return results
def _report_hook_failure(
diff --git a/tests/hermes_cli/test_plugins.py b/tests/hermes_cli/test_plugins.py
index 6df94835a43..05b0ef5321d 100644
--- a/tests/hermes_cli/test_plugins.py
+++ b/tests/hermes_cli/test_plugins.py
@@ -1268,6 +1268,42 @@ class TestForceReloadSymmetry:
assert mgr.invoke_hook("post_tool_call") == ["survived"]
assert "bounded plugin requested process exit" in caplog.text
+ def test_pre_tool_call_direct_callback_exception_fails_closed(self, monkeypatch):
+ """A synchronous policy callback error must block rather than allow the tool."""
+ from hermes_cli.plugins import _PRE_TOOL_CALL_TIMEOUT_BLOCK_MESSAGE
+
+ monkeypatch.setattr(
+ "hermes_cli.plugins._resolve_hook_callback_timeout", lambda: 0.0
+ )
+
+ def boom(**_kwargs):
+ raise RuntimeError("policy plugin blew up")
+
+ mgr = PluginManager()
+ mgr._hooks["pre_tool_call"] = [boom]
+
+ assert mgr.invoke_hook("pre_tool_call", tool_name="terminal", args={}) == [
+ {"action": "block", "message": _PRE_TOOL_CALL_TIMEOUT_BLOCK_MESSAGE}
+ ]
+
+ def test_pre_tool_call_timeout_worker_exception_fails_closed(self, monkeypatch):
+ """A bounded policy callback error must use the same fail-closed directive."""
+ from hermes_cli.plugins import _PRE_TOOL_CALL_TIMEOUT_BLOCK_MESSAGE
+
+ monkeypatch.setattr(
+ "hermes_cli.plugins._resolve_hook_callback_timeout", lambda: 1.0
+ )
+
+ def boom(**_kwargs):
+ raise RuntimeError("policy plugin blew up")
+
+ mgr = PluginManager()
+ mgr._hooks["pre_tool_call"] = [boom]
+
+ assert mgr.invoke_hook("pre_tool_call", tool_name="terminal", args={}) == [
+ {"action": "block", "message": _PRE_TOOL_CALL_TIMEOUT_BLOCK_MESSAGE}
+ ]
+
def test_hook_callback_timeout_reads_config(self, tmp_path, monkeypatch):
hermes_home = tmp_path / "hermes_test"
hermes_home.mkdir(parents=True, exist_ok=True)