fix(sandbox): enforce token output budgets - #3934
Merged
Merged
Conversation
cosin2077
marked this pull request as ready for review
July 31, 2026 04:18
luisangelrod
reviewed
Aug 4, 2026
luisangelrod
left a comment
There was a problem hiding this comment.
Reviewed the complete token-mode path and its formatted callers. The patch correctly reserves the line-count prefix and truncation-marker bytes before splitting retained content, preserves UTF-8 boundaries, handles a zero-token budget, and recomputes the removed-token count without exceeding the original marker reservation. Byte-mode behavior remains unchanged, and the focused tests plus the green cross-version/Windows CI cover the changed contract. No blocking findings from me.
seratch
approved these changes
Aug 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This pull request fixes sandbox token truncation so
max_output_tokensapplies to the complete output payload, including the line-count header and truncation marker.Previously, the implementation spent the full budget on retained content and appended formatting metadata afterward. Small limits could therefore return many times the requested token budget. The new token-specific assembly reserves space for metadata before splitting the retained prefix and suffix, and safely clips the marker for budgets too small to hold the full message. Byte-mode truncation and shell response metadata such as chunk ID and wall time remain unchanged.
Test plan
uv run pytest -q tests/sandbox/test_memory.py::test_memory_capability_injects_truncated_memory_summary tests/sandbox/test_token_truncation.py tests/sandbox/test_pty_types.py tests/sandbox/test_pty_output.py tests/sandbox/capabilities/test_shell_capability.py(49 passed)bash .agents/skills/code-change-verification/scripts/run.sh(format, lint, typecheck, and full test suite passed)origin/main; Standards and Spec reviews reported no findings.Issue number
No linked issue. A pre-submission search found no open issue or pull request covering this fix.
Checks
.agents/skills/code-change-verification/scripts/run.sh/reviewbefore submitting this PR