The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(guardrails): a harness refusal is not a tool failure
rlaopec962c698f843
diff --git a/agent/tool_guardrails.py b/agent/tool_guardrails.pyindex 1d28df2b781..975dc26caa7 100644--- a/agent/tool_guardrails.py+++ b/agent/tool_guardrails.py@@ -219,6 +219,14 @@ def classify_tool_failure(tool_name: str, result: str | None) -> tuple[bool, strif result is None or file_mutation_result_landed(tool_name, result):return False, ""+ # A body this harness emitted to REFUSE a call is not a call that failed.+ # It carries `"error"` for the model's benefit, which is exactly what the+ # substring test below keys on, so counting it would let a refusal raise+ # the failure streak that produces the next, harder refusal.+ data = safe_json_loads(result)+ if isinstance(data, dict) and data.get("guardrail_refusal") is True:+ return False, ""+if tool_name == "terminal":data = safe_json_loads(result)exit_code = data.get("exit_code") if isinstance(data, dict) else Nonediff --git a/tests/agent/test_tool_guardrails.py b/tests/agent/test_tool_guardrails.pyindex 63ae5debd34..6a233230a54 100644--- a/tests/agent/test_tool_guardrails.py+++ b/tests/agent/test_tool_guardrails.py@@ -376,3 +376,27 @@ def test_supervised_task_platforms_keep_warning_only_default():for platform in ("telegram", "discord", "cron", "kanban"):cfg = ToolCallGuardrailConfig.from_mapping({}, platform=platform)assert cfg.hard_stop_enabled is True, platform+++def test_a_harness_refusal_is_not_counted_as_a_tool_failure():+ """The read-dedup block carries `"error"` for the model's benefit, which is+ exactly what `classify_tool_failure`'s substring test keys on. Counting it+ let a refusal raise the failure streak that produces the next, harder+ refusal -- an escalation to `repeated_exact_failure_block` reporting N+ failures that never happened. Observed on a real session: 13 of 14 results+ classified as failed were this block, against one genuine tool failure."""+ from tools.file_tools import _dedup_stub_or_block++ task_data = {"dedup_hits": {}}+ key = ("/repo/responses.ts", 1, 999)+ for _ in range(3):+ blocked = _dedup_stub_or_block(task_data, key, "/repo/responses.ts")++ assert json.loads(blocked)["guardrail_refusal"] is True+ assert classify_tool_failure("read_file", blocked) == (False, "")+++def test_a_real_tool_error_is_still_a_failure():+ """The exemption is keyed on the marker, not on the word: a body that+ genuinely failed still counts, or the streak that stops a real loop is gone."""+ assert classify_tool_failure("read_file", '{"error": "ENOENT: no such file"}')[0] is Truediff --git a/tools/file_tools.py b/tools/file_tools.pyindex a9f264978c9..a72ebf74853 100644--- a/tools/file_tools.py+++ b/tools/file_tools.py@@ -502,7 +502,14 @@ def _dedup_stub_or_block(task_data: dict, dedup_key: tuple, path: str) -> str:"still current. Proceed with your task using ""the information you already have.",path=path,- already_read=hits + 1)+ already_read=hits + 1,+ # This body is a REFUSAL the harness chose, not a failure the tool+ # hit. Without the marker the guardrail's own block feeds its+ # failure counter (`classify_tool_failure` keys on the literal+ # `"error"`), so refusing a repeated read escalates to+ # `repeated_exact_failure_block` and reports N failures that never+ # happened.+ guardrail_refusal=True)return json.dumps({"status": "unchanged",