Skip to content

Commit 9d963e8

Browse files
authored
fix: bound manifest description truncation (#2974)
1 parent 902c599 commit 9d963e8

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

src/agents/sandbox/manifest_render.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
def _truncate_manifest_description(description: str, max_chars: int | None) -> str:
1515
if max_chars is None or len(description) <= max_chars:
1616
return description
17+
if max_chars <= 0:
18+
return ""
1719

1820
omitted_chars = len(description) - max_chars
1921
while True:
@@ -30,6 +32,15 @@ def _truncate_manifest_description(description: str, max_chars: int | None) -> s
3032
omitted_chars = actual_omitted_chars
3133

3234
truncated = description[:keep_chars].rstrip() + marker
35+
if len(marker) >= max_chars:
36+
truncated = marker[:max_chars]
37+
logger.warning(
38+
f"Manifest description exceeded {max_chars} characters "
39+
f"and was truncated to {len(truncated)} characters."
40+
)
41+
return truncated
42+
if len(truncated) > max_chars:
43+
truncated = truncated[:max_chars]
3344
logger.warning(
3445
f"Manifest description exceeded {max_chars} characters "
3546
f"and was truncated to {len(truncated)} characters."

tests/sandbox/test_manifest.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
)
1212
from agents.sandbox.errors import InvalidManifestPathError
1313
from agents.sandbox.manifest import Manifest
14+
from agents.sandbox.manifest_render import _truncate_manifest_description
1415

1516

1617
def test_manifest_rejects_nested_child_paths_that_escape_workspace() -> None:
@@ -197,3 +198,17 @@ def test_manifest_describe_preserves_tree_rendering_after_renderer_extract() ->
197198
assert "/workspace/data" in description
198199
assert "repo/" in description
199200
assert "/workspace/repo/README.md" in description
201+
202+
203+
def test_manifest_description_truncation_respects_short_limits() -> None:
204+
description = "0123456789" * 20
205+
206+
for max_chars in range(0, 40):
207+
truncated = _truncate_manifest_description(description, max_chars)
208+
assert len(truncated) <= max_chars
209+
210+
211+
def test_manifest_description_truncation_preserves_unbounded_description() -> None:
212+
description = "short"
213+
214+
assert _truncate_manifest_description(description, None) == description

0 commit comments

Comments
 (0)