Skip to content

fix(sandbox): enforce token output budgets - #3934

Merged
seratch merged 1 commit into
openai:mainfrom
cosin2077:fix/sandbox-token-budget
Aug 4, 2026
Merged

fix(sandbox): enforce token output budgets#3934
seratch merged 1 commit into
openai:mainfrom
cosin2077:fix/sandbox-token-budget

Conversation

@cosin2077

Copy link
Copy Markdown
Contributor

Summary

This pull request fixes sandbox token truncation so max_output_tokens applies 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)
  • Reviewed the final diff against 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

  • I've added new tests, if relevant
  • I've run .agents/skills/code-change-verification/scripts/run.sh
  • I've confirmed all verification steps pass
  • If using Codex, I've run /review before submitting this PR

@cosin2077
cosin2077 marked this pull request as ready for review July 31, 2026 04:18

@luisangelrod luisangelrod left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 seratch added this to the 0.19.x milestone Aug 4, 2026
@seratch
seratch merged commit ad976ad into openai:main Aug 4, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants