The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(plugins): name the callback and error in the raise-fail-closed block
teknium132518f024f5b
diff --git a/hermes_cli/plugins_dispatch.py b/hermes_cli/plugins_dispatch.pyindex 7aa7cb34c05..e49b3cef263 100644--- a/hermes_cli/plugins_dispatch.py+++ b/hermes_cli/plugins_dispatch.py@@ -52,6 +52,15 @@ _HOOK_CALLER_THREAD_HOOKS: Set[str] = {"subagent_stop"}_HOOK_TIMEOUT_SUPPRESSION_SECONDS = 60.0_PRE_TOOL_CALL_TIMEOUT_BLOCK_MESSAGE = "pre_tool_call plugin callback timed out or is still running"++def _policy_error_block_directive(hook_name: str, cb: Callable, exc: BaseException) -> Dict[str, str]:+ """Block directive for a fail-closed hook whose callback raised: names the callback and the+ error (truncated — a hook that embeds tool args in its exception must not grow the tool+ result) so the operator can tell a crashing guard from a slow one."""+ callback_name = getattr(cb, "__name__", repr(cb))+ return {"action": "block",+ "message": f"{hook_name} plugin callback {callback_name} raised {type(exc).__name__}: {str(exc)[:200]}"}+# System-prompt sections are tightly bounded: they become high-trust prompt bytes charged every turn.SYSTEM_PROMPT_SECTION_POSITIONS = frozenset({"after_memory"})DEFAULT_SYSTEM_PROMPT_SECTION_MAX_CHARS = 4_000@@ -220,8 +229,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})+ if fail_closed: # a guard that raised made no decision: same veto as a timeout+ results.append(_policy_error_block_directive(hook_name, cb, exc))return resultsdef _report_hook_failure(diff --git a/tests/hermes_cli/test_plugins.py b/tests/hermes_cli/test_plugins.pyindex 05b0ef5321d..3455b75ae06 100644--- a/tests/hermes_cli/test_plugins.py+++ b/tests/hermes_cli/test_plugins.py@@ -1268,41 +1268,24 @@ 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-+ @pytest.mark.parametrize("timeout", [0.0, 1.0], ids=["caller-thread", "bounded-worker"])+ def test_pre_tool_call_callback_exception_fails_closed(self, monkeypatch, timeout):+ """A policy callback that raises made no decision: it must block like a timeout does+ (#109624), on both the caller-thread and the bounded-worker path, and the block message+ names the callback and the error so a crashing guard is distinguishable from a slow one."""monkeypatch.setattr(- "hermes_cli.plugins._resolve_hook_callback_timeout", lambda: 1.0+ "hermes_cli.plugins._resolve_hook_callback_timeout", lambda: timeout)def boom(**_kwargs):raise RuntimeError("policy plugin blew up")mgr = PluginManager()- mgr._hooks["pre_tool_call"] = [boom]+ mgr._hooks["pre_tool_call"] = [boom, lambda **_kw: {"action": "approve"}]- assert mgr.invoke_hook("pre_tool_call", tool_name="terminal", args={}) == [- {"action": "block", "message": _PRE_TOOL_CALL_TIMEOUT_BLOCK_MESSAGE}- ]+ results = mgr.invoke_hook("pre_tool_call", tool_name="terminal", args={})+ assert [r.get("action") for r in results] == ["block", "approve"]+ assert "boom" in results[0]["message"] and "RuntimeError: policy plugin blew up" in results[0]["message"]def test_hook_callback_timeout_reads_config(self, tmp_path, monkeypatch):hermes_home = tmp_path / "hermes_test"