fix(context): reserve notice budget so bounded output honors max_bytes

The head+tail slices could each take half of max_bytes, then the
truncation notice and its separators were appended on top, so the value
persisted to history could exceed the configured maximum. Reserve an
upper bound for the notice (and separators) out of the byte budget before
slicing so the whole joined result stays within max_bytes.
This commit is contained in:
Ahmed Allam
2026-07-26 14:38:12 -07:00
committed by Ahmed Allam
parent 6bda366065
commit 0ebd3c6230
2 changed files with 13 additions and 2 deletions
+3 -1
View File
@@ -28,7 +28,9 @@ def test_byte_limit_enforced_on_single_long_line() -> None:
bounded = bound_text(text, max_lines=2_000, max_bytes=1_000)
assert "truncated" in bounded
assert len(bounded.encode("utf-8")) < 3_000
# The whole joined result (head + tail + notice + separators) honours the
# configured maximum, not just the head/tail slices.
assert len(bounded.encode("utf-8")) <= 1_000
def test_multibyte_characters_not_split() -> None: