Skip to content

The agent that grows with you

fix(display): an "error": null straddling the 500-char scan cut stays a success

Tekniume01fdd1c43e2
diff --git a/agent/tool_result_classification.py b/agent/tool_result_classification.py
index 2fb807226ca..5a5738d626a 100644
--- a/agent/tool_result_classification.py
+++ b/agent/tool_result_classification.py
@@ -45,13 +45,16 @@ def is_guardrail_refusal(result: Any) -> bool:
# A quoted "error"/"failed" in a result's head marks it failed UNLESS it is a key whose value is
# empty: success payloads routinely carry ``"error": null`` per item (web_extract) or a
# ``"failed": 0`` count, and a bare substring test flagged every one of them.
-_FAILURE_MARKER_RE = re.compile(r'"(?:error|failed)"(?!\s*:\s*(?:null|false|0|""|\[\]|\{\})\s*(?:[,}\]]|$))')
+_FAILURE_MARKER_RE = re.compile(
+ r'"(?:error|failed)"(?!\s*:\s*(?:null|false|0|""|\[\]|\{\})\s*(?:[,}\]]|$))', re.IGNORECASE)
def has_failure_marker(result: str) -> bool:
"""Last-resort text test for a failed tool result: a non-empty ``"error"``/``"failed"``
- in the first 500 chars, or a body starting with ``Error``."""
- return bool(_FAILURE_MARKER_RE.search(result[:500].lower())) or result.startswith("Error")
+ STARTING in the first 500 chars, or a body starting with ``Error``. The value is read past
+ the cut, so an ``"error": null`` straddling char 500 is not mistaken for a truncated one."""
+ head = result[:600]
+ return any(m.start() < 500 for m in _FAILURE_MARKER_RE.finditer(head)) or result.startswith("Error")
def file_mutation_result_landed(tool_name: str, result: Any) -> bool:
diff --git a/tests/agent/test_display_tool_failure.py b/tests/agent/test_display_tool_failure.py
index 38cbc726a92..5c4e71346aa 100644
--- a/tests/agent/test_display_tool_failure.py
+++ b/tests/agent/test_display_tool_failure.py
@@ -135,6 +135,8 @@ class TestDetectToolFailureStructured:
json.dumps({"results": [{"url": "https://example.com/", "content": "hi", "error": None}]}, indent=2),
json.dumps({"done": 3, "failed": 0}),
json.dumps({"items": [], "errors": [], "error": ""}),
+ # "error": null straddling the 500-char scan cut must not read as a truncated value
+ json.dumps({"results": [{"url": "https://example.com/", "content": "x" * 428, "error": None}]}),
]
for result in ok:
assert _detect_tool_failure("web_extract", result) == (False, ""), result