diff --git a/acp_adapter/tools.py b/acp_adapter/tools.py index 22b181650c1..8de0b6b1ac1 100644 --- a/acp_adapter/tools.py +++ b/acp_adapter/tools.py @@ -202,7 +202,7 @@ def _json_loads_maybe(value: Optional[str]) -> Any: return None -def _tool_result_failed(result: Optional[str]) -> bool: +def _tool_result_failed(result: Optional[str], tool_name: str | None = None) -> bool: """Return True when a structured Hermes tool result clearly failed. Keep this deliberately conservative. Plain text can contain words like @@ -221,6 +221,13 @@ def _tool_result_failed(result: Optional[str]) -> bool: if isinstance(exit_code, int) and exit_code != 0: return True + # Hermes core/polished tools commonly report tool-level failures as a + # structured {"error": "..."} payload without an explicit success flag. + # Keep generic plugin/unknown tool payloads conservative to avoid marking + # optional diagnostic messages as failed. + if tool_name in _POLISHED_TOOLS and data.get("error") and not data.get("content"): + return True + return False @@ -1318,7 +1325,7 @@ def build_tool_complete( return acp.update_tool_call( tool_call_id, kind=kind, - status="failed" if _tool_result_failed(result) else "completed", + status="failed" if _tool_result_failed(result, tool_name) else "completed", content=content, raw_output=None if tool_name in _POLISHED_TOOLS or _is_structured_json_result(result) else result, ) diff --git a/tests/acp/test_tools.py b/tests/acp/test_tools.py index efce0d24bfd..a077160b1f0 100644 --- a/tests/acp/test_tools.py +++ b/tests/acp/test_tools.py @@ -365,6 +365,10 @@ class TestBuildToolComplete: result = build_tool_complete("tc-ok", "terminal", "tests failed: 1 assertion error") assert result.status == "completed" + def test_build_tool_complete_marks_structured_polished_tool_error_as_failed(self): + result = build_tool_complete("tc-fail", "read_file", '{"error": "File not found"}') + assert result.status == "failed" + def test_build_tool_complete_keeps_json_error_without_failure_flag_completed(self): result = build_tool_complete("tc-ok", "some_tool", '{"error": "timeout while reading optional source"}') assert result.status == "completed"