Skip to content
Python

Tool results: a plain-text result never overshoots the byte cap

Rohit C Prasadb90e2c6c5b90
diff --git a/coworker/toolresult.py b/coworker/toolresult.py
index 7a2217a8..28dde426 100644
--- a/coworker/toolresult.py
+++ b/coworker/toolresult.py
@@ -127,4 +127,10 @@ def bound_tool_result(
return out
path = spill(f"{step:04d}-{safe_tool}.txt", text)
- return head_tail(text, max_bytes - _MARKER_RESERVE, spill_path=path, total_bytes=_nbytes(text))
+ bounded = head_tail(text, max_bytes - _MARKER_RESERVE, spill_path=path, total_bytes=_nbytes(text))
+ # The marker names the spill file, and a long path can outgrow the reserve; tighten once
+ # (OPE-199: the cap was overshot by the length of the path).
+ over = _nbytes(bounded) - max_bytes
+ if over > 0:
+ bounded = head_tail(text, max_bytes - _MARKER_RESERVE - over, spill_path=path, total_bytes=_nbytes(text))
+ return bounded