Repository navigation
Conversation
argszero
force-pushed
the
fix/code-mode-clamp-output
branch
from
September 17, 2026 08:55
27023e3 to
2eb64c7
Compare
argszero
force-pushed
the
fix/code-mode-clamp-output
branch
3 times, most recently
from
September 30, 2026 10:39
1936088 to
5893a05
Compare
In code mode, the size of a tool result the model receives is bounded only by what the script's @exec pragma requests: truncate_code_mode_result uses resolve_max_tokens(max_output_tokens) with no clamp, so a script that raises its max_output_tokens can push a shell result (up to the unified-exec buffer limit) straight into context. Mirror the function-mode clamp in ExecCommandToolOutput::model_output_policy: thread the model's truncation policy into truncate_code_mode_result and clamp the requested budget to it, so a model can never receive a tool result larger than its own output policy allows. Adds a regression test asserting a high max_output_tokens pragma is clamped to the model's truncation policy.
argszero
force-pushed
the
fix/code-mode-clamp-output
branch
from
October 8, 2026 09:29
5893a05 to
ddf9b35
Compare
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
In code mode, the size of a tool result the model receives is bounded only by what the script's
@execpragma requests.truncate_code_mode_resultusesresolve_max_tokens(max_output_tokens)with no clamp, so a script that raises itsmax_output_tokenscan push a shell result (up to the unified-exec buffer limit) straight into context. Observed: a ~497 KB result reaching the model as ~138K tokens.The function-mode path (
ExecCommandToolOutput::model_output_policy) already clamps to the model'struncation_policy. This mirrors that clamp in the code-mode path: thread the model's truncation policy intotruncate_code_mode_resultand clamp the requested budget, so a model never receives a tool result larger than its own output policy allows.Related Issue
Closes openai#42367
Tests
codex-corecode_mode unit tests)high_max_output_tokens_is_clamped_to_model_policyasserts a raisedmax_output_tokenspragma is clamped to the model's truncation policy