Repository navigation
fix(infer): reject prompts without generation space - #9851
Merged
Merged
Conversation
Raise a clear input-length error before zero or negative generation limits reach backend-specific configuration validation. Fixes #6441 Test: python -m unittest tests.infer.test_infer_engine_limits
Contributor
|
Caution The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased. |
hjh0119
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.
PR type
PR information
Fixes #6441.
Background
When an encoded prompt consumes all or more than the model context,
set_default_max_tokens()currently calculates a zero or negativegeneration limit and stores it in the request configuration.
The invalid value then reaches a backend-specific configuration class,
which raises a secondary error such as:
This obscures the actual problem: the prompt itself leaves no room for
generation.
Changes
negative.
offset in the error.
remaining context.
Verification
PYTHONPATH=. .venv/bin/python -m unittest tests.infer.test_infer_engine_limitsPYTHONPATH=. .venv/bin/python tests/run.py --pattern test_infer_engine_limits.py.venv/bin/pre-commit run --all-filesgit diff --checkImpact
Valid inference requests are unchanged. Requests that previously
propagated zero or negative generation limits now fail earlier with an
actionable error. The change applies consistently to inference backends
that use
set_default_max_tokens().Experiment results
Before the fix, prompts of length 5 and 4 with
max_model_len=4produced generation limits of
-1and0without a direct error. Afterthe fix, both raise the input-length error, while a valid prompt still
caps the requested generation length from 4 to 2.