Skip to content

Commit 18982f1

Browse files
author
Tooru
committed
Fix Harness
1 parent d37eb65 commit 18982f1

1 file changed

Lines changed: 17 additions & 5 deletions

File tree

harness/run_harness.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -721,16 +721,28 @@ def extract_patch(raw_response: str, allow_incomplete_diffs: bool = False) -> st
721721
if fence not in raw_response:
722722
raise HarnessError("Model response does not contain a ```diff fenced block.")
723723
start = raw_response.index(fence) + len(fence)
724-
try:
725-
end = raw_response.index("```", start)
726-
except ValueError as exc:
724+
# Find closing ``` that is at the start of a line (not embedded in code)
725+
# This handles cases where generated code contains ``` strings
726+
end = None
727+
search_pos = start
728+
while search_pos < len(raw_response):
729+
try:
730+
candidate = raw_response.index("```", search_pos)
731+
except ValueError:
732+
break
733+
# Check if this ``` is at the start of a line (preceded by newline or at start)
734+
if candidate == 0 or raw_response[candidate - 1] == '\n':
735+
end = candidate
736+
break
737+
search_pos = candidate + 3
738+
if end is None:
727739
if not allow_incomplete_diffs:
728-
raise HarnessError("Model response does not contain closing ``` fence.") from exc
740+
raise HarnessError("Model response does not contain closing ``` fence.") from None
729741
fallback_patch = _extract_incomplete_patch(raw_response[start:])
730742
if not fallback_patch or not _is_probably_valid_patch(fallback_patch):
731743
raise HarnessError(
732744
"Model response diff block is incomplete or untrustworthy (missing closing ``` fence)."
733-
) from exc
745+
)
734746
return fallback_patch
735747
patch = raw_response[start:end]
736748
return patch.strip() + "\n"

0 commit comments

Comments
 (0)