fix(acp): treat polished tool error payloads as failed

This commit is contained in:
HenkDz 2026-05-16 11:50:50 +01:00 committed by Teknium
parent b38d2d133b
commit 9cf1140caa
2 changed files with 13 additions and 2 deletions

View file

@ -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,
)

View file

@ -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"